mirror of
https://github.com/iSoron/uhabits.git
synced 2025-12-06 17:18:52 -06:00
Create new UNKNOWN checkmark state
This commit is contained in:
@@ -391,7 +391,7 @@ public class HistoryChart extends ScrollableChart
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
checkmark = checkmarks[checkmarkOffset];
|
checkmark = checkmarks[checkmarkOffset];
|
||||||
if(checkmark == 0)
|
if(checkmark <= 0)
|
||||||
{
|
{
|
||||||
pSquareBg.setColor(colors[0]);
|
pSquareBg.setColor(colors[0]);
|
||||||
pSquareFg.setColor(textColors[1]);
|
pSquareFg.setColor(textColors[1]);
|
||||||
|
|||||||
@@ -114,6 +114,7 @@ class CheckmarkButtonView(
|
|||||||
val id = when (value) {
|
val id = when (value) {
|
||||||
SKIP -> R.string.fa_skipped
|
SKIP -> R.string.fa_skipped
|
||||||
NO -> R.string.fa_times
|
NO -> R.string.fa_times
|
||||||
|
UNKNOWN -> R.string.fa_question
|
||||||
else -> R.string.fa_check
|
else -> R.string.fa_check
|
||||||
}
|
}
|
||||||
val label = resources.getString(id)
|
val label = resources.getString(id)
|
||||||
|
|||||||
@@ -62,7 +62,7 @@ class CheckmarkPanelView(
|
|||||||
val timestamp = today.minus(index + dataOffset)
|
val timestamp = today.minus(index + dataOffset)
|
||||||
button.value = when {
|
button.value = when {
|
||||||
index + dataOffset < values.size -> values[index + dataOffset]
|
index + dataOffset < values.size -> values[index + dataOffset]
|
||||||
else -> NO
|
else -> UNKNOWN
|
||||||
}
|
}
|
||||||
button.color = color
|
button.color = color
|
||||||
button.onToggle = { value -> onToggle(timestamp, value) }
|
button.onToggle = { value -> onToggle(timestamp, value) }
|
||||||
|
|||||||
@@ -86,8 +86,8 @@ public class CheckmarkWidgetView extends HabitWidgetView {
|
|||||||
|
|
||||||
case Checkmark.YES_AUTO:
|
case Checkmark.YES_AUTO:
|
||||||
case Checkmark.NO:
|
case Checkmark.NO:
|
||||||
|
case Checkmark.UNKNOWN:
|
||||||
default:
|
default:
|
||||||
getResources().getString(R.string.fa_times);
|
|
||||||
bgColor = res.getColor(R.attr.cardBgColor);
|
bgColor = res.getColor(R.attr.cardBgColor);
|
||||||
fgColor = res.getColor(R.attr.mediumContrastTextColor);
|
fgColor = res.getColor(R.attr.mediumContrastTextColor);
|
||||||
setShadowAlpha(0x00);
|
setShadowAlpha(0x00);
|
||||||
@@ -120,6 +120,8 @@ public class CheckmarkWidgetView extends HabitWidgetView {
|
|||||||
return getResources().getString(R.string.fa_check);
|
return getResources().getString(R.string.fa_check);
|
||||||
case Checkmark.SKIP:
|
case Checkmark.SKIP:
|
||||||
return getResources().getString(R.string.fa_skipped);
|
return getResources().getString(R.string.fa_skipped);
|
||||||
|
case Checkmark.UNKNOWN:
|
||||||
|
return getResources().getString(R.string.fa_question);
|
||||||
case Checkmark.NO:
|
case Checkmark.NO:
|
||||||
default:
|
default:
|
||||||
return getResources().getString(R.string.fa_times);
|
return getResources().getString(R.string.fa_times);
|
||||||
|
|||||||
@@ -26,6 +26,7 @@
|
|||||||
<string translatable="false" name="fa_skipped"></string>
|
<string translatable="false" name="fa_skipped"></string>
|
||||||
<string translatable="false" name="fa_bell_o"></string>
|
<string translatable="false" name="fa_bell_o"></string>
|
||||||
<string translatable="false" name="fa_calendar"></string>
|
<string translatable="false" name="fa_calendar"></string>
|
||||||
|
<string translatable="false" name="fa_question"></string>
|
||||||
|
|
||||||
<!--<string translatable="false" name="fa_glass"></string>-->
|
<!--<string translatable="false" name="fa_glass"></string>-->
|
||||||
<!--<string translatable="false" name="fa_music"></string>-->
|
<!--<string translatable="false" name="fa_music"></string>-->
|
||||||
@@ -281,7 +282,6 @@
|
|||||||
<!--<string translatable="false" name="fa_crop"></string>-->
|
<!--<string translatable="false" name="fa_crop"></string>-->
|
||||||
<!--<string translatable="false" name="fa_code_fork"></string>-->
|
<!--<string translatable="false" name="fa_code_fork"></string>-->
|
||||||
<!--<string translatable="false" name="fa_chain_broken"></string>-->
|
<!--<string translatable="false" name="fa_chain_broken"></string>-->
|
||||||
<!--<string translatable="false" name="fa_question"></string>-->
|
|
||||||
<!--<string translatable="false" name="fa_info"></string>-->
|
<!--<string translatable="false" name="fa_info"></string>-->
|
||||||
<!--<string translatable="false" name="fa_exclamation"></string>-->
|
<!--<string translatable="false" name="fa_exclamation"></string>-->
|
||||||
<!--<string translatable="false" name="fa_superscript"></string>-->
|
<!--<string translatable="false" name="fa_superscript"></string>-->
|
||||||
|
|||||||
@@ -43,27 +43,32 @@ import static org.isoron.uhabits.core.utils.StringUtils.defaultToStringStyle;
|
|||||||
public final class Checkmark
|
public final class Checkmark
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* Indicates that there was an explicit skip at the timestamp.
|
* Checkmark value indicating that the habit is not applicable for this timestamp.
|
||||||
*/
|
*/
|
||||||
public static final int SKIP = 3;
|
public static final int SKIP = 3;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Indicates that there was a repetition at the timestamp.
|
* Checkmark value indicating that the user has performed the habit at this timestamp.
|
||||||
*/
|
*/
|
||||||
public static final int YES_MANUAL = 2;
|
public static final int YES_MANUAL = 2;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Indicates that there was no repetition at the timestamp, but one was not
|
* Checkmark value indicating that the user did not perform the habit, but they were not
|
||||||
* expected in any case, due to the frequency of the habit.
|
* expected to, because of the frequency of the habit.
|
||||||
*/
|
*/
|
||||||
public static final int YES_AUTO = 1;
|
public static final int YES_AUTO = 1;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Indicates that there was no repetition at the timestamp, even though a
|
* Checkmark value indicating that the user did not perform the habit, even though they were
|
||||||
* repetition was expected.
|
* expected to perform it.
|
||||||
*/
|
*/
|
||||||
public static final int NO = 0;
|
public static final int NO = 0;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Checkmark value indicating that no data is available for the given timestamp.
|
||||||
|
*/
|
||||||
|
public static final int UNKNOWN = -1;
|
||||||
|
|
||||||
private final Timestamp timestamp;
|
private final Timestamp timestamp;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -62,7 +62,7 @@ public abstract class CheckmarkList
|
|||||||
int nDays = begin.daysUntil(today) + 1;
|
int nDays = begin.daysUntil(today) + 1;
|
||||||
List<Checkmark> checkmarks = new ArrayList<>(nDays);
|
List<Checkmark> checkmarks = new ArrayList<>(nDays);
|
||||||
for (int i = 0; i < nDays; i++)
|
for (int i = 0; i < nDays; i++)
|
||||||
checkmarks.add(new Checkmark(today.minus(i), NO));
|
checkmarks.add(new Checkmark(today.minus(i), UNKNOWN));
|
||||||
|
|
||||||
for (Interval interval : intervals)
|
for (Interval interval : intervals)
|
||||||
{
|
{
|
||||||
@@ -79,7 +79,10 @@ public abstract class CheckmarkList
|
|||||||
{
|
{
|
||||||
Timestamp date = rep.getTimestamp();
|
Timestamp date = rep.getTimestamp();
|
||||||
int offset = date.daysUntil(today);
|
int offset = date.daysUntil(today);
|
||||||
checkmarks.set(offset, new Checkmark(date, rep.getValue()));
|
int value = rep.getValue();
|
||||||
|
int prevValue = checkmarks.get(offset).getValue();
|
||||||
|
if (prevValue < value)
|
||||||
|
checkmarks.set(offset, new Checkmark(date, value));
|
||||||
}
|
}
|
||||||
|
|
||||||
return checkmarks;
|
return checkmarks;
|
||||||
@@ -224,7 +227,7 @@ public abstract class CheckmarkList
|
|||||||
{
|
{
|
||||||
Checkmark today = getToday();
|
Checkmark today = getToday();
|
||||||
if (today != null) return today.getValue();
|
if (today != null) return today.getValue();
|
||||||
else return NO;
|
else return UNKNOWN;
|
||||||
}
|
}
|
||||||
|
|
||||||
public synchronized int getThisWeekValue(int firstWeekday)
|
public synchronized int getThisWeekValue(int firstWeekday)
|
||||||
|
|||||||
@@ -332,7 +332,7 @@ public class Habit
|
|||||||
else
|
else
|
||||||
return todayCheckmark / 1000.0 <= data.targetValue;
|
return todayCheckmark / 1000.0 <= data.targetValue;
|
||||||
}
|
}
|
||||||
else return (todayCheckmark != NO);
|
else return (todayCheckmark != NO && todayCheckmark != UNKNOWN);
|
||||||
}
|
}
|
||||||
|
|
||||||
public synchronized boolean isNumerical()
|
public synchronized boolean isNumerical()
|
||||||
|
|||||||
@@ -60,6 +60,7 @@ public final class Repetition
|
|||||||
{
|
{
|
||||||
switch(value) {
|
switch(value) {
|
||||||
case NO:
|
case NO:
|
||||||
|
case UNKNOWN:
|
||||||
case YES_AUTO:
|
case YES_AUTO:
|
||||||
return YES_MANUAL;
|
return YES_MANUAL;
|
||||||
case YES_MANUAL:
|
case YES_MANUAL:
|
||||||
@@ -74,6 +75,7 @@ public final class Repetition
|
|||||||
{
|
{
|
||||||
switch(value) {
|
switch(value) {
|
||||||
case NO:
|
case NO:
|
||||||
|
case UNKNOWN:
|
||||||
case YES_AUTO:
|
case YES_AUTO:
|
||||||
return YES_MANUAL;
|
return YES_MANUAL;
|
||||||
default:
|
default:
|
||||||
|
|||||||
@@ -85,7 +85,7 @@ public abstract class RepetitionList
|
|||||||
public int getValue(Timestamp timestamp)
|
public int getValue(Timestamp timestamp)
|
||||||
{
|
{
|
||||||
Repetition rep = getByTimestamp(timestamp);
|
Repetition rep = getByTimestamp(timestamp);
|
||||||
if (rep == null) return Checkmark.NO;
|
if (rep == null) return Checkmark.UNKNOWN;
|
||||||
return rep.getValue();
|
return rep.getValue();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -138,8 +138,8 @@ public abstract class StreakList
|
|||||||
current = current.plus(1);
|
current = current.plus(1);
|
||||||
int j = checks.length - i - 1;
|
int j = checks.length - i - 1;
|
||||||
|
|
||||||
if ((checks[j + 1] == 0 && checks[j] > 0)) list.add(current);
|
if ((checks[j + 1] <= 0 && checks[j] > 0)) list.add(current);
|
||||||
if ((checks[j + 1] > 0 && checks[j] == 0)) list.add(current.minus(1));
|
if ((checks[j + 1] > 0 && checks[j] <= 0)) list.add(current.minus(1));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (list.size() % 2 == 1) list.add(current);
|
if (list.size() % 2 == 1) list.add(current);
|
||||||
|
|||||||
@@ -68,7 +68,7 @@ public class MemoryCheckmarkList extends CheckmarkList
|
|||||||
{
|
{
|
||||||
Timestamp t = to.minus(i);
|
Timestamp t = to.minus(i);
|
||||||
if(t.isNewerThan(newestComputed) || t.isOlderThan(oldestComputed))
|
if(t.isNewerThan(newestComputed) || t.isOlderThan(oldestComputed))
|
||||||
filtered.add(new Checkmark(t, Checkmark.NO));
|
filtered.add(new Checkmark(t, Checkmark.UNKNOWN));
|
||||||
else
|
else
|
||||||
filtered.add(list.get(t.daysUntil(newestComputed)));
|
filtered.add(list.get(t.daysUntil(newestComputed)));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -142,7 +142,9 @@ public class HabitFixtures
|
|||||||
Timestamp timestamp = DateUtils.getToday();
|
Timestamp timestamp = DateUtils.getToday();
|
||||||
for (boolean c : NON_DAILY_HABIT_CHECKS)
|
for (boolean c : NON_DAILY_HABIT_CHECKS)
|
||||||
{
|
{
|
||||||
if (c) habit.getRepetitions().setValue(timestamp, YES_MANUAL);
|
int value = NO;
|
||||||
|
if (c) value = YES_MANUAL;
|
||||||
|
habit.getRepetitions().setValue(timestamp, value);
|
||||||
timestamp = timestamp.minus(1);
|
timestamp = timestamp.minus(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -186,7 +186,7 @@ public class NotificationTray
|
|||||||
{
|
{
|
||||||
systemTray.log("Showing notification for habit=" + habit.id);
|
systemTray.log("Showing notification for habit=" + habit.id);
|
||||||
|
|
||||||
if (todayValue != Checkmark.NO) {
|
if (todayValue != Checkmark.UNKNOWN) {
|
||||||
systemTray.log(String.format(
|
systemTray.log(String.format(
|
||||||
Locale.US,
|
Locale.US,
|
||||||
"Habit %d already checked. Skipping.",
|
"Habit %d already checked. Skipping.",
|
||||||
|
|||||||
@@ -80,14 +80,14 @@ public class CheckmarkListTest extends BaseUnitTest
|
|||||||
intervals.add(new CheckmarkList.Interval(day(2), day(2), day(1)));
|
intervals.add(new CheckmarkList.Interval(day(2), day(2), day(1)));
|
||||||
|
|
||||||
List<Checkmark> expected = new ArrayList<>();
|
List<Checkmark> expected = new ArrayList<>();
|
||||||
expected.add(new Checkmark(day(0), NO));
|
expected.add(new Checkmark(day(0), UNKNOWN));
|
||||||
expected.add(new Checkmark(day(1), YES_MANUAL));
|
expected.add(new Checkmark(day(1), YES_MANUAL));
|
||||||
expected.add(new Checkmark(day(2), YES_MANUAL));
|
expected.add(new Checkmark(day(2), YES_MANUAL));
|
||||||
expected.add(new Checkmark(day(3), NO));
|
expected.add(new Checkmark(day(3), UNKNOWN));
|
||||||
expected.add(new Checkmark(day(4), YES_AUTO));
|
expected.add(new Checkmark(day(4), YES_AUTO));
|
||||||
expected.add(new Checkmark(day(5), YES_MANUAL));
|
expected.add(new Checkmark(day(5), YES_MANUAL));
|
||||||
expected.add(new Checkmark(day(6), YES_AUTO));
|
expected.add(new Checkmark(day(6), YES_AUTO));
|
||||||
expected.add(new Checkmark(day(7), NO));
|
expected.add(new Checkmark(day(7), UNKNOWN));
|
||||||
expected.add(new Checkmark(day(8), YES_AUTO));
|
expected.add(new Checkmark(day(8), YES_AUTO));
|
||||||
expected.add(new Checkmark(day(9), YES_AUTO));
|
expected.add(new Checkmark(day(9), YES_AUTO));
|
||||||
expected.add(new Checkmark(day(10), YES_MANUAL));
|
expected.add(new Checkmark(day(10), YES_MANUAL));
|
||||||
@@ -220,9 +220,9 @@ public class CheckmarkListTest extends BaseUnitTest
|
|||||||
travelInTime(3);
|
travelInTime(3);
|
||||||
|
|
||||||
int[] expectedValues = {
|
int[] expectedValues = {
|
||||||
NO,
|
UNKNOWN,
|
||||||
NO,
|
UNKNOWN,
|
||||||
NO,
|
UNKNOWN,
|
||||||
YES_MANUAL,
|
YES_MANUAL,
|
||||||
NO,
|
NO,
|
||||||
YES_AUTO,
|
YES_AUTO,
|
||||||
@@ -296,7 +296,7 @@ public class CheckmarkListTest extends BaseUnitTest
|
|||||||
assertThat(checkmarks.getTodayValue(), equalTo(YES_MANUAL));
|
assertThat(checkmarks.getTodayValue(), equalTo(YES_MANUAL));
|
||||||
|
|
||||||
travelInTime(1);
|
travelInTime(1);
|
||||||
assertThat(checkmarks.getTodayValue(), equalTo(NO));
|
assertThat(checkmarks.getTodayValue(), equalTo(UNKNOWN));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -320,12 +320,12 @@ public class CheckmarkListTest extends BaseUnitTest
|
|||||||
YES_AUTO,
|
YES_AUTO,
|
||||||
YES_MANUAL,
|
YES_MANUAL,
|
||||||
YES_MANUAL,
|
YES_MANUAL,
|
||||||
NO,
|
UNKNOWN,
|
||||||
NO,
|
UNKNOWN,
|
||||||
NO,
|
UNKNOWN,
|
||||||
NO,
|
UNKNOWN,
|
||||||
NO,
|
UNKNOWN,
|
||||||
NO
|
UNKNOWN
|
||||||
};
|
};
|
||||||
|
|
||||||
int[] actualValues = nonDailyHabit.getCheckmarks().getValues(from, to);
|
int[] actualValues = nonDailyHabit.getCheckmarks().getValues(from, to);
|
||||||
@@ -475,7 +475,7 @@ public class CheckmarkListTest extends BaseUnitTest
|
|||||||
assertThat(checkmarks.getThisMonthValue(), equalTo(1006));
|
assertThat(checkmarks.getThisMonthValue(), equalTo(1006));
|
||||||
|
|
||||||
DateUtils.setFixedLocalTime(unixTime(2000, MAY, 1));
|
DateUtils.setFixedLocalTime(unixTime(2000, MAY, 1));
|
||||||
assertThat(checkmarks.getTodayValue(), equalTo(0));
|
assertThat(checkmarks.getTodayValue(), equalTo(UNKNOWN));
|
||||||
assertThat(checkmarks.getThisWeekValue(SATURDAY), equalTo(0));
|
assertThat(checkmarks.getThisWeekValue(SATURDAY), equalTo(0));
|
||||||
assertThat(checkmarks.getThisMonthValue(), equalTo(0));
|
assertThat(checkmarks.getThisMonthValue(), equalTo(0));
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user