mirror of
https://github.com/iSoron/uhabits.git
synced 2025-12-06 09:08:52 -06:00
HistoryChart: make toggling faster
This commit is contained in:
@@ -32,6 +32,8 @@ import org.isoron.uhabits.utils.*;
|
|||||||
import java.text.*;
|
import java.text.*;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
|
||||||
|
import static org.isoron.uhabits.models.Checkmark.*;
|
||||||
|
|
||||||
public class HistoryChart extends ScrollableChart
|
public class HistoryChart extends ScrollableChart
|
||||||
{
|
{
|
||||||
private int[] checkmarks;
|
private int[] checkmarks;
|
||||||
@@ -118,12 +120,15 @@ public class HistoryChart extends ScrollableChart
|
|||||||
final Long timestamp = positionToTimestamp(x, y);
|
final Long timestamp = positionToTimestamp(x, y);
|
||||||
if (timestamp == null) return false;
|
if (timestamp == null) return false;
|
||||||
|
|
||||||
controller.onToggleCheckmark(timestamp);
|
int offset = timestampToOffset(timestamp);
|
||||||
|
boolean isChecked = checkmarks[offset] == CHECKED_EXPLICITLY;
|
||||||
|
checkmarks[offset] = (isChecked ? UNCHECKED : CHECKED_EXPLICITLY);
|
||||||
|
|
||||||
|
controller.onToggleCheckmark(timestamp);
|
||||||
|
postInvalidate();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public void populateWithRandomData()
|
public void populateWithRandomData()
|
||||||
{
|
{
|
||||||
Random random = new Random();
|
Random random = new Random();
|
||||||
@@ -407,6 +412,14 @@ public class HistoryChart extends ScrollableChart
|
|||||||
return date.getTimeInMillis();
|
return date.getTimeInMillis();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private int timestampToOffset(Long timestamp)
|
||||||
|
{
|
||||||
|
Long day = DateUtils.millisecondsInOneDay;
|
||||||
|
Long today = DateUtils.getStartOfToday();
|
||||||
|
|
||||||
|
return (int) ((today - timestamp) / day);
|
||||||
|
}
|
||||||
|
|
||||||
private void updateDate()
|
private void updateDate()
|
||||||
{
|
{
|
||||||
baseDate = DateUtils.getStartOfTodayCalendar();
|
baseDate = DateUtils.getStartOfTodayCalendar();
|
||||||
|
|||||||
Reference in New Issue
Block a user