Rename checkmark values to NO, YES_AUTO, YES_MANUAL and SKIP

This makes the source code consistent with the user interface.
This commit is contained in:
2020-09-05 18:04:04 -05:00
parent d59ab89426
commit b72cad5316
26 changed files with 154 additions and 164 deletions

View File

@@ -40,32 +40,31 @@ public final class Checkmark
/**
* Indicates that there was an explicit skip at the timestamp.
*/
public static final int SKIPPED = 3;
public static final int SKIP = 3;
/**
* Indicates that there was a repetition at the timestamp.
*/
public static final int CHECKED_EXPLICITLY = 2;
public static final int YES_MANUAL = 2;
/**
* Indicates that there was no repetition at the timestamp, but one was not
* expected in any case, due to the frequency of the habit.
*/
public static final int CHECKED_IMPLICITLY = 1;
public static final int YES_AUTO = 1;
/**
* Indicates that there was no repetition at the timestamp, even though a
* repetition was expected.
*/
public static final int UNCHECKED = 0;
public static final int NO = 0;
private final Timestamp timestamp;
/**
* The value of the checkmark.
* <p>
* For boolean habits, this equals either UNCHECKED, CHECKED_EXPLICITLY, CHECKED_IMPLICITLY
* or SKIPPED.
* For boolean habits, this equals either NO, YES_AUTO, YES_MANUAL or SKIP.
* <p>
* For numerical habits, this number is stored in thousandths. That
* is, if the user enters value 1.50 on the app, it is stored as 1500.

View File

@@ -62,7 +62,7 @@ public abstract class CheckmarkList
int nDays = begin.daysUntil(today) + 1;
List<Checkmark> checkmarks = new ArrayList<>(nDays);
for (int i = 0; i < nDays; i++)
checkmarks.add(new Checkmark(today.minus(i), UNCHECKED));
checkmarks.add(new Checkmark(today.minus(i), NO));
for (Interval interval : intervals)
{
@@ -71,7 +71,7 @@ public abstract class CheckmarkList
Timestamp date = interval.begin.plus(i);
int offset = date.daysUntil(today);
if (offset < 0) continue;
checkmarks.set(offset, new Checkmark(date, CHECKED_IMPLICITLY));
checkmarks.set(offset, new Checkmark(date, YES_AUTO));
}
}
@@ -102,7 +102,7 @@ public abstract class CheckmarkList
{
ArrayList<Repetition> filteredReps = new ArrayList<>();
for (Repetition r : reps)
if (r.getValue() == CHECKED_EXPLICITLY)
if (r.getValue() == YES_MANUAL)
filteredReps.add(r);
int num = freq.getNumerator();
@@ -224,7 +224,7 @@ public abstract class CheckmarkList
{
Checkmark today = getToday();
if (today != null) return today.getValue();
else return UNCHECKED;
else return NO;
}
public synchronized int getThisWeekValue(int firstWeekday)
@@ -480,7 +480,7 @@ public abstract class CheckmarkList
if(habit.isNumerical())
values[count - 1] += rep.getValue();
else if(rep.getValue() == Checkmark.CHECKED_EXPLICITLY)
else if(rep.getValue() == Checkmark.YES_MANUAL)
values[count - 1] += 1000;
}

View File

@@ -331,7 +331,7 @@ public class Habit
else
return todayCheckmark / 1000.0 <= data.targetValue;
}
else return (todayCheckmark != UNCHECKED);
else return (todayCheckmark != NO);
}
public synchronized boolean isNumerical()

View File

@@ -20,12 +20,6 @@
package org.isoron.uhabits.core.models;
import org.apache.commons.lang3.builder.*;
import org.isoron.uhabits.core.utils.DateFormats;
import org.isoron.uhabits.core.utils.DateUtils;
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;
import static org.isoron.uhabits.core.models.Checkmark.*;
import static org.isoron.uhabits.core.utils.StringUtils.defaultToStringStyle;
@@ -42,7 +36,7 @@ public final class Repetition
/**
* The value of the repetition.
*
* For boolean habits, this equals CHECKED_EXPLICITLY if performed or SKIPPED if skipped.
* For boolean habits, this equals YES_MANUAL if performed or SKIP if skipped.
* For numerical habits, this number is stored in thousandths. That is, if the user enters
* value 1.50 on the app, it is here stored as 1500.
*/
@@ -65,14 +59,14 @@ public final class Repetition
public static int nextToggleValue(int value)
{
switch(value) {
case UNCHECKED:
case CHECKED_IMPLICITLY:
return CHECKED_EXPLICITLY;
case CHECKED_EXPLICITLY:
return SKIPPED;
case NO:
case YES_AUTO:
return YES_MANUAL;
case YES_MANUAL:
return SKIP;
default:
case SKIPPED:
return UNCHECKED;
case SKIP:
return NO;
}
}

View File

@@ -140,7 +140,7 @@ public abstract class RepetitionList
for (Repetition r : reps)
{
if (!habit.isNumerical() && r.getValue() != Checkmark.CHECKED_EXPLICITLY)
if (!habit.isNumerical() && r.getValue() != Checkmark.YES_MANUAL)
continue;
Calendar date = r.getTimestamp().toCalendar();
@@ -197,7 +197,7 @@ public abstract class RepetitionList
if (rep != null) remove(rep);
else
{
rep = new Repetition(timestamp, Checkmark.CHECKED_EXPLICITLY);
rep = new Repetition(timestamp, Checkmark.YES_MANUAL);
add(rep);
}

View File

@@ -68,7 +68,7 @@ public class MemoryCheckmarkList extends CheckmarkList
{
Timestamp t = to.minus(i);
if(t.isNewerThan(newestComputed) || t.isOlderThan(oldestComputed))
filtered.add(new Checkmark(t, Checkmark.UNCHECKED));
filtered.add(new Checkmark(t, Checkmark.NO));
else
filtered.add(list.get(t.daysUntil(newestComputed)));
}

View File

@@ -123,7 +123,7 @@ public class MemoryRepetitionList extends RepetitionList
{
int count = 0;
for (Repetition rep : list)
if (rep.getValue() == Checkmark.CHECKED_EXPLICITLY)
if (rep.getValue() == Checkmark.YES_MANUAL)
count++;
return count;
}

View File

@@ -186,7 +186,7 @@ public class NotificationTray
{
systemTray.log("Showing notification for habit=" + habit.id);
if (todayValue != Checkmark.UNCHECKED) {
if (todayValue != Checkmark.NO) {
systemTray.log(String.format(
Locale.US,
"Habit %d already checked. Skipping.",

View File

@@ -110,7 +110,7 @@ public class ShowHabitMenuBehavior
if (i % 7 == 0) strength = max(0, min(100, strength + 10 * random.nextGaussian()));
if (random.nextInt(100) > strength) continue;
int value = Checkmark.CHECKED_EXPLICITLY;
int value = Checkmark.YES_MANUAL;
if (habit.isNumerical())
value = (int) (1000 + 250 * random.nextGaussian() * strength / 100) * 1000;

View File

@@ -51,7 +51,7 @@ public class WidgetBehavior
notificationTray.cancel(habit);
Repetition rep = habit.getRepetitions().getByTimestamp(timestamp);
if (rep != null) return;
performToggle(habit, timestamp, Checkmark.CHECKED_EXPLICITLY);
performToggle(habit, timestamp, Checkmark.YES_MANUAL);
}
public void onRemoveRepetition(@NonNull Habit habit, Timestamp timestamp)
@@ -59,13 +59,13 @@ public class WidgetBehavior
notificationTray.cancel(habit);
Repetition rep = habit.getRepetitions().getByTimestamp(timestamp);
if (rep == null) return;
performToggle(habit, timestamp, Checkmark.UNCHECKED);
performToggle(habit, timestamp, Checkmark.NO);
}
public void onToggleRepetition(@NonNull Habit habit, Timestamp timestamp)
{
Repetition previous = habit.getRepetitions().getByTimestamp(timestamp);
if(previous == null) performToggle(habit, timestamp, Checkmark.CHECKED_EXPLICITLY);
if(previous == null) performToggle(habit, timestamp, Checkmark.YES_MANUAL);
else performToggle(habit, timestamp, Repetition.nextToggleValue(previous.getValue()));
}