mirror of
https://github.com/iSoron/uhabits.git
synced 2025-12-06 01:08:50 -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.util.*;
|
||||
|
||||
import static org.isoron.uhabits.models.Checkmark.*;
|
||||
|
||||
public class HistoryChart extends ScrollableChart
|
||||
{
|
||||
private int[] checkmarks;
|
||||
@@ -118,12 +120,15 @@ public class HistoryChart extends ScrollableChart
|
||||
final Long timestamp = positionToTimestamp(x, y);
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
public void populateWithRandomData()
|
||||
{
|
||||
Random random = new Random();
|
||||
@@ -407,6 +412,14 @@ public class HistoryChart extends ScrollableChart
|
||||
return date.getTimeInMillis();
|
||||
}
|
||||
|
||||
private int timestampToOffset(Long timestamp)
|
||||
{
|
||||
Long day = DateUtils.millisecondsInOneDay;
|
||||
Long today = DateUtils.getStartOfToday();
|
||||
|
||||
return (int) ((today - timestamp) / day);
|
||||
}
|
||||
|
||||
private void updateDate()
|
||||
{
|
||||
baseDate = DateUtils.getStartOfTodayCalendar();
|
||||
|
||||
Reference in New Issue
Block a user