Rename checkmark values to NO, YES_AUTO, YES_MANUAL and SKIP

This makes the source code consistent with the user interface.
pull/638/head
Alinson S. Xavier 5 years ago
parent d59ab89426
commit b72cad5316

@ -80,11 +80,11 @@ public class HistoryChartTest extends BaseViewTest
chart.setIsEditable(true); chart.setIsEditable(true);
chart.tap(dpToPixels(340), dpToPixels(40)); chart.tap(dpToPixels(340), dpToPixels(40));
verify(controller).onToggleCheckmark(today, Checkmark.SKIPPED); verify(controller).onToggleCheckmark(today, Checkmark.SKIP);
chart.tap(dpToPixels(340), dpToPixels(40)); chart.tap(dpToPixels(340), dpToPixels(40));
verify(controller).onToggleCheckmark(today, Checkmark.UNCHECKED); verify(controller).onToggleCheckmark(today, Checkmark.NO);
chart.tap(dpToPixels(340), dpToPixels(40)); chart.tap(dpToPixels(340), dpToPixels(40));
verify(controller).onToggleCheckmark(today, Checkmark.CHECKED_EXPLICITLY); verify(controller).onToggleCheckmark(today, Checkmark.YES_MANUAL);
verifyNoMoreInteractions(controller); verifyNoMoreInteractions(controller);
} }
@ -94,7 +94,7 @@ public class HistoryChartTest extends BaseViewTest
chart.setIsEditable(true); chart.setIsEditable(true);
chart.setCheckmarks(new int[]{}); chart.setCheckmarks(new int[]{});
chart.tap(dpToPixels(340), dpToPixels(40)); chart.tap(dpToPixels(340), dpToPixels(40));
verify(controller).onToggleCheckmark(today, Checkmark.CHECKED_EXPLICITLY); verify(controller).onToggleCheckmark(today, Checkmark.YES_MANUAL);
verifyNoMoreInteractions(controller); verifyNoMoreInteractions(controller);
} }

@ -21,7 +21,6 @@ package org.isoron.uhabits.activities.habits.list.views
import androidx.test.ext.junit.runners.AndroidJUnit4 import androidx.test.ext.junit.runners.AndroidJUnit4
import androidx.test.filters.* import androidx.test.filters.*
import androidx.test.runner.*
import org.isoron.uhabits.* import org.isoron.uhabits.*
import org.isoron.uhabits.core.models.* import org.isoron.uhabits.core.models.*
import org.isoron.uhabits.utils.* import org.isoron.uhabits.utils.*
@ -41,7 +40,7 @@ class CheckmarkButtonViewTest : BaseViewTest() {
override fun setUp() { override fun setUp() {
super.setUp() super.setUp()
view = component.getCheckmarkButtonViewFactory().create().apply { view = component.getCheckmarkButtonViewFactory().create().apply {
value = Checkmark.UNCHECKED value = Checkmark.NO
color = PaletteUtils.getAndroidTestColor(5) color = PaletteUtils.getAndroidTestColor(5)
onToggle = { toggled = true } onToggle = { toggled = true }
} }
@ -50,19 +49,19 @@ class CheckmarkButtonViewTest : BaseViewTest() {
@Test @Test
fun testRender_explicitCheck() { fun testRender_explicitCheck() {
view.value = Checkmark.CHECKED_EXPLICITLY view.value = Checkmark.YES_MANUAL
assertRendersCheckedExplicitly() assertRendersCheckedExplicitly()
} }
@Test @Test
fun testRender_implicitCheck() { fun testRender_implicitCheck() {
view.value = Checkmark.CHECKED_IMPLICITLY view.value = Checkmark.YES_AUTO
assertRendersCheckedImplicitly() assertRendersCheckedImplicitly()
} }
@Test @Test
fun testRender_unchecked() { fun testRender_unchecked() {
view.value = Checkmark.UNCHECKED view.value = Checkmark.NO
assertRendersUnchecked() assertRendersUnchecked()
} }

@ -21,7 +21,6 @@ package org.isoron.uhabits.activities.habits.list.views
import androidx.test.ext.junit.runners.AndroidJUnit4 import androidx.test.ext.junit.runners.AndroidJUnit4
import androidx.test.filters.* import androidx.test.filters.*
import androidx.test.runner.*
import org.hamcrest.CoreMatchers.* import org.hamcrest.CoreMatchers.*
import org.hamcrest.MatcherAssert.* import org.hamcrest.MatcherAssert.*
import org.isoron.uhabits.* import org.isoron.uhabits.*
@ -43,13 +42,13 @@ class CheckmarkPanelViewTest : BaseViewTest() {
super.setUp() super.setUp()
prefs.isCheckmarkSequenceReversed = false prefs.isCheckmarkSequenceReversed = false
val checkmarks = intArrayOf(CHECKED_EXPLICITLY, val checkmarks = intArrayOf(YES_MANUAL,
CHECKED_EXPLICITLY, YES_MANUAL,
CHECKED_IMPLICITLY, YES_AUTO,
UNCHECKED, NO,
UNCHECKED, NO,
UNCHECKED, NO,
CHECKED_EXPLICITLY) YES_MANUAL)
view = component.getCheckmarkPanelViewFactory().create().apply { view = component.getCheckmarkPanelViewFactory().create().apply {
values = checkmarks values = checkmarks

@ -20,7 +20,7 @@
package org.isoron.uhabits.widgets; package org.isoron.uhabits.widgets;
import androidx.test.filters.*; import androidx.test.filters.*;
import androidx.test.runner.*;
import android.widget.*; import android.widget.*;
import androidx.test.ext.junit.runners.AndroidJUnit4; import androidx.test.ext.junit.runners.AndroidJUnit4;
@ -58,7 +58,7 @@ public class CheckmarkWidgetTest extends BaseViewTest
CheckmarkWidget widget = new CheckmarkWidget(targetContext, 0, habit); CheckmarkWidget widget = new CheckmarkWidget(targetContext, 0, habit);
view = convertToView(widget, 150, 200); view = convertToView(widget, 150, 200);
assertThat(checkmarks.getTodayValue(), equalTo(CHECKED_EXPLICITLY)); assertThat(checkmarks.getTodayValue(), equalTo(YES_MANUAL));
} }
@Test @Test
@ -71,11 +71,11 @@ public class CheckmarkWidgetTest extends BaseViewTest
// possible to capture intents sent to BroadcastReceivers. // possible to capture intents sent to BroadcastReceivers.
button.performClick(); button.performClick();
sleep(1000); sleep(1000);
assertThat(checkmarks.getTodayValue(), equalTo(SKIPPED)); assertThat(checkmarks.getTodayValue(), equalTo(SKIP));
button.performClick(); button.performClick();
sleep(1000); sleep(1000);
assertThat(checkmarks.getTodayValue(), equalTo(UNCHECKED)); assertThat(checkmarks.getTodayValue(), equalTo(NO));
} }
@Test @Test

@ -70,7 +70,7 @@ public class CheckmarkWidgetViewTest extends BaseViewTest
// @Test // @Test
// public void testRender_implicitlyChecked() throws IOException // public void testRender_implicitlyChecked() throws IOException
// { // {
// view.setCheckmarkValue(Checkmark.CHECKED_IMPLICITLY); // view.setCheckmarkValue(Checkmark.YES_AUTO);
// view.refresh(); // view.refresh();
// assertRenders(view, PATH + "implicitly_checked.png"); // assertRenders(view, PATH + "implicitly_checked.png");
// } // }
@ -85,7 +85,7 @@ public class CheckmarkWidgetViewTest extends BaseViewTest
// @Test // @Test
// public void testRender_unchecked() throws IOException // public void testRender_unchecked() throws IOException
// { // {
// view.setCheckmarkValue(Checkmark.UNCHECKED); // view.setCheckmarkValue(Checkmark.NO);
// view.refresh(); // view.refresh();
// assertRenders(view, PATH + "unchecked.png"); // assertRenders(view, PATH + "unchecked.png");
// } // }

@ -149,7 +149,7 @@ public class HistoryChart extends ScrollableChart
if (timestamp == null) return false; if (timestamp == null) return false;
Timestamp today = DateUtils.getToday(); Timestamp today = DateUtils.getToday();
int newValue = CHECKED_EXPLICITLY; int newValue = YES_MANUAL;
int offset = timestamp.daysUntil(today); int offset = timestamp.daysUntil(today);
if (offset < checkmarks.length) if (offset < checkmarks.length)
{ {
@ -385,7 +385,7 @@ public class HistoryChart extends ScrollableChart
pSquareBg.setColor(colors[0]); pSquareBg.setColor(colors[0]);
pSquareFg.setColor(textColors[1]); pSquareFg.setColor(textColors[1]);
} }
else if ((isNumerical && checkmark < target) || checkmark != CHECKED_EXPLICITLY) else if ((isNumerical && checkmark < target) || checkmark != YES_MANUAL)
{ {
pSquareBg.setColor(colors[1]); pSquareBg.setColor(colors[1]);
pSquareFg.setColor(textColors[2]); pSquareFg.setColor(textColors[2]);
@ -400,7 +400,7 @@ public class HistoryChart extends ScrollableChart
float round = dpToPixels(getContext(), 2); float round = dpToPixels(getContext(), 2);
canvas.drawRoundRect(location, round, round, pSquareBg); canvas.drawRoundRect(location, round, round, pSquareBg);
if (!isNumerical && checkmark == SKIPPED) if (!isNumerical && checkmark == SKIP)
{ {
pSquareBg.setColor(backgroundColor); pSquareBg.setColor(backgroundColor);
pSquareBg.setStrokeWidth(columnWidth * 0.025f); pSquareBg.setStrokeWidth(columnWidth * 0.025f);

@ -103,14 +103,14 @@ class CheckmarkButtonView(
fun draw(canvas: Canvas) { fun draw(canvas: Canvas) {
paint.color = when (value) { paint.color = when (value) {
CHECKED_EXPLICITLY -> color YES_MANUAL -> color
SKIPPED -> color SKIP -> color
else -> lowContrastColor else -> lowContrastColor
} }
val id = when (value) { val id = when (value) {
SKIPPED -> R.string.fa_skipped SKIP -> R.string.fa_skipped
CHECKED_IMPLICITLY -> R.string.fa_skipped YES_AUTO -> R.string.fa_skipped
UNCHECKED -> R.string.fa_times NO -> R.string.fa_times
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 -> UNCHECKED else -> NO
} }
button.color = color button.color = color
button.onToggle = { value -> onToggle(timestamp, value) } button.onToggle = { value -> onToggle(timestamp, value) }

@ -67,9 +67,9 @@ open class CheckmarkWidget(
private fun getNumericalCheckmarkState(): Int { private fun getNumericalCheckmarkState(): Int {
return if (habit.isCompletedToday) { return if (habit.isCompletedToday) {
Checkmark.CHECKED_EXPLICITLY Checkmark.YES_MANUAL
} else { } else {
Checkmark.UNCHECKED Checkmark.NO
} }
} }

@ -75,8 +75,8 @@ public class CheckmarkWidgetView extends HabitWidgetView {
int fgColor; int fgColor;
switch (checkmarkState) { switch (checkmarkState) {
case Checkmark.CHECKED_EXPLICITLY: case Checkmark.YES_MANUAL:
case Checkmark.SKIPPED: case Checkmark.SKIP:
bgColor = activeColor; bgColor = activeColor;
fgColor = res.getColor(R.attr.highContrastReverseTextColor); fgColor = res.getColor(R.attr.highContrastReverseTextColor);
setShadowAlpha(0x4f); setShadowAlpha(0x4f);
@ -84,8 +84,8 @@ public class CheckmarkWidgetView extends HabitWidgetView {
frame.setBackgroundDrawable(background); frame.setBackgroundDrawable(background);
break; break;
case Checkmark.CHECKED_IMPLICITLY: case Checkmark.YES_AUTO:
case Checkmark.UNCHECKED: case Checkmark.NO:
default: default:
getResources().getString(R.string.fa_times); getResources().getString(R.string.fa_times);
bgColor = res.getColor(R.attr.cardBgColor); bgColor = res.getColor(R.attr.cardBgColor);
@ -115,12 +115,12 @@ public class CheckmarkWidgetView extends HabitWidgetView {
{ {
if (isNumerical) return NumberButtonViewKt.toShortString(checkmarkValue / 1000.0); if (isNumerical) return NumberButtonViewKt.toShortString(checkmarkValue / 1000.0);
switch (checkmarkState) { switch (checkmarkState) {
case Checkmark.CHECKED_EXPLICITLY: case Checkmark.YES_MANUAL:
return getResources().getString(R.string.fa_check); return getResources().getString(R.string.fa_check);
case Checkmark.CHECKED_IMPLICITLY: case Checkmark.YES_AUTO:
case Checkmark.SKIPPED: case Checkmark.SKIP:
return getResources().getString(R.string.fa_skipped); return getResources().getString(R.string.fa_skipped);
case Checkmark.UNCHECKED: case Checkmark.NO:
default: default:
return getResources().getString(R.string.fa_times); return getResources().getString(R.string.fa_times);
} }
@ -204,7 +204,7 @@ public class CheckmarkWidgetView extends HabitWidgetView {
percentage = 0.75f; percentage = 0.75f;
name = "Wake up early"; name = "Wake up early";
activeColor = PaletteUtils.getAndroidTestColor(6); activeColor = PaletteUtils.getAndroidTestColor(6);
checkmarkValue = Checkmark.CHECKED_EXPLICITLY; checkmarkValue = Checkmark.YES_MANUAL;
refresh(); refresh();
} }
} }

@ -62,7 +62,7 @@ public class WidgetControllerTest extends BaseAndroidJVMTest
{ {
habit.getRepetitions().toggle(today); habit.getRepetitions().toggle(today);
int todayValue = habit.getCheckmarks().getTodayValue(); int todayValue = habit.getCheckmarks().getTodayValue();
assertThat(todayValue, equalTo(CHECKED_EXPLICITLY)); assertThat(todayValue, equalTo(YES_MANUAL));
controller.onAddRepetition(habit, today); controller.onAddRepetition(habit, today);
verifyZeroInteractions(commandRunner); verifyZeroInteractions(commandRunner);
} }
@ -71,7 +71,7 @@ public class WidgetControllerTest extends BaseAndroidJVMTest
public void testOnAddRepetition_whenUnchecked() throws Exception public void testOnAddRepetition_whenUnchecked() throws Exception
{ {
int todayValue = habit.getCheckmarks().getTodayValue(); int todayValue = habit.getCheckmarks().getTodayValue();
assertThat(todayValue, equalTo(UNCHECKED)); assertThat(todayValue, equalTo(NO));
controller.onAddRepetition(habit, today); controller.onAddRepetition(habit, today);
verify(commandRunner).execute(any(), isNull()); verify(commandRunner).execute(any(), isNull());
verify(notificationTray).cancel(habit); verify(notificationTray).cancel(habit);
@ -82,7 +82,7 @@ public class WidgetControllerTest extends BaseAndroidJVMTest
{ {
habit.getRepetitions().toggle(today); habit.getRepetitions().toggle(today);
int todayValue = habit.getCheckmarks().getTodayValue(); int todayValue = habit.getCheckmarks().getTodayValue();
assertThat(todayValue, equalTo(CHECKED_EXPLICITLY)); assertThat(todayValue, equalTo(YES_MANUAL));
controller.onRemoveRepetition(habit, today); controller.onRemoveRepetition(habit, today);
verify(commandRunner).execute(any(), isNull()); verify(commandRunner).execute(any(), isNull());
} }
@ -91,7 +91,7 @@ public class WidgetControllerTest extends BaseAndroidJVMTest
public void testOnRemoveRepetition_whenUnchecked() throws Exception public void testOnRemoveRepetition_whenUnchecked() throws Exception
{ {
int todayValue = habit.getCheckmarks().getTodayValue(); int todayValue = habit.getCheckmarks().getTodayValue();
assertThat(todayValue, equalTo(UNCHECKED)); assertThat(todayValue, equalTo(NO));
controller.onRemoveRepetition(habit, today); controller.onRemoveRepetition(habit, today);
verifyZeroInteractions(commandRunner); verifyZeroInteractions(commandRunner);
} }

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

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

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

@ -20,12 +20,6 @@
package org.isoron.uhabits.core.models; package org.isoron.uhabits.core.models;
import org.apache.commons.lang3.builder.*; 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.models.Checkmark.*;
import static org.isoron.uhabits.core.utils.StringUtils.defaultToStringStyle; import static org.isoron.uhabits.core.utils.StringUtils.defaultToStringStyle;
@ -42,7 +36,7 @@ public final class Repetition
/** /**
* The value of the 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 * 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. * 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) public static int nextToggleValue(int value)
{ {
switch(value) { switch(value) {
case UNCHECKED: case NO:
case CHECKED_IMPLICITLY: case YES_AUTO:
return CHECKED_EXPLICITLY; return YES_MANUAL;
case CHECKED_EXPLICITLY: case YES_MANUAL:
return SKIPPED; return SKIP;
default: default:
case SKIPPED: case SKIP:
return UNCHECKED; return NO;
} }
} }

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

@ -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.UNCHECKED)); filtered.add(new Checkmark(t, Checkmark.NO));
else else
filtered.add(list.get(t.daysUntil(newestComputed))); filtered.add(list.get(t.daysUntil(newestComputed)));
} }

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

@ -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.UNCHECKED) { if (todayValue != Checkmark.NO) {
systemTray.log(String.format( systemTray.log(String.format(
Locale.US, Locale.US,
"Habit %d already checked. Skipping.", "Habit %d already checked. Skipping.",

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

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

@ -57,7 +57,7 @@ public class CreateRepetitionCommandTest extends BaseUnitTest
Repetition rep = reps.getByTimestamp(today); Repetition rep = reps.getByTimestamp(today);
assertNotNull(rep); assertNotNull(rep);
assertEquals(CHECKED_EXPLICITLY, rep.getValue()); assertEquals(YES_MANUAL, rep.getValue());
command.execute(); command.execute();
rep = reps.getByTimestamp(today); rep = reps.getByTimestamp(today);
@ -67,7 +67,7 @@ public class CreateRepetitionCommandTest extends BaseUnitTest
command.undo(); command.undo();
rep = reps.getByTimestamp(today); rep = reps.getByTimestamp(today);
assertNotNull(rep); assertNotNull(rep);
assertEquals(CHECKED_EXPLICITLY, rep.getValue()); assertEquals(YES_MANUAL, rep.getValue());
} }
@Test @Test

@ -29,7 +29,6 @@ import java.util.*;
import nl.jqno.equalsverifier.*; import nl.jqno.equalsverifier.*;
import static java.util.Calendar.*; import static java.util.Calendar.*;
import static junit.framework.TestCase.*;
import static org.hamcrest.MatcherAssert.*; import static org.hamcrest.MatcherAssert.*;
import static org.hamcrest.core.IsEqual.*; import static org.hamcrest.core.IsEqual.*;
import static org.isoron.uhabits.core.models.Checkmark.*; import static org.isoron.uhabits.core.models.Checkmark.*;
@ -69,10 +68,10 @@ public class CheckmarkListTest extends BaseUnitTest
public void test_buildCheckmarksFromIntervals_1() throws Exception public void test_buildCheckmarksFromIntervals_1() throws Exception
{ {
Repetition reps[] = new Repetition[]{ Repetition reps[] = new Repetition[]{
new Repetition(day(10), CHECKED_EXPLICITLY), new Repetition(day(10), YES_MANUAL),
new Repetition(day(5), CHECKED_EXPLICITLY), new Repetition(day(5), YES_MANUAL),
new Repetition(day(2), CHECKED_EXPLICITLY), new Repetition(day(2), YES_MANUAL),
new Repetition(day(1), CHECKED_EXPLICITLY), new Repetition(day(1), YES_MANUAL),
}; };
ArrayList<CheckmarkList.Interval> intervals = new ArrayList<>(); ArrayList<CheckmarkList.Interval> intervals = new ArrayList<>();
@ -81,17 +80,17 @@ 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), UNCHECKED)); expected.add(new Checkmark(day(0), NO));
expected.add(new Checkmark(day(1), CHECKED_EXPLICITLY)); expected.add(new Checkmark(day(1), YES_MANUAL));
expected.add(new Checkmark(day(2), CHECKED_EXPLICITLY)); expected.add(new Checkmark(day(2), YES_MANUAL));
expected.add(new Checkmark(day(3), UNCHECKED)); expected.add(new Checkmark(day(3), NO));
expected.add(new Checkmark(day(4), CHECKED_IMPLICITLY)); expected.add(new Checkmark(day(4), YES_AUTO));
expected.add(new Checkmark(day(5), CHECKED_EXPLICITLY)); expected.add(new Checkmark(day(5), YES_MANUAL));
expected.add(new Checkmark(day(6), CHECKED_IMPLICITLY)); expected.add(new Checkmark(day(6), YES_AUTO));
expected.add(new Checkmark(day(7), UNCHECKED)); expected.add(new Checkmark(day(7), NO));
expected.add(new Checkmark(day(8), CHECKED_IMPLICITLY)); expected.add(new Checkmark(day(8), YES_AUTO));
expected.add(new Checkmark(day(9), CHECKED_IMPLICITLY)); expected.add(new Checkmark(day(9), YES_AUTO));
expected.add(new Checkmark(day(10), CHECKED_EXPLICITLY)); expected.add(new Checkmark(day(10), YES_MANUAL));
List<Checkmark> actual = List<Checkmark> actual =
CheckmarkList.buildCheckmarksFromIntervals(reps, intervals); CheckmarkList.buildCheckmarksFromIntervals(reps, intervals);
@ -102,14 +101,14 @@ public class CheckmarkListTest extends BaseUnitTest
public void test_buildCheckmarksFromIntervals_2() throws Exception public void test_buildCheckmarksFromIntervals_2() throws Exception
{ {
Repetition reps[] = new Repetition[]{ Repetition reps[] = new Repetition[]{
new Repetition(day(0), CHECKED_EXPLICITLY), new Repetition(day(0), YES_MANUAL),
}; };
ArrayList<CheckmarkList.Interval> intervals = new ArrayList<>(); ArrayList<CheckmarkList.Interval> intervals = new ArrayList<>();
intervals.add(new CheckmarkList.Interval(day(0), day(0), day(-10))); intervals.add(new CheckmarkList.Interval(day(0), day(0), day(-10)));
List<Checkmark> expected = new ArrayList<>(); List<Checkmark> expected = new ArrayList<>();
expected.add(new Checkmark(day(0), CHECKED_EXPLICITLY)); expected.add(new Checkmark(day(0), YES_MANUAL));
List<Checkmark> actual = List<Checkmark> actual =
CheckmarkList.buildCheckmarksFromIntervals(reps, intervals); CheckmarkList.buildCheckmarksFromIntervals(reps, intervals);
@ -120,9 +119,9 @@ public class CheckmarkListTest extends BaseUnitTest
public void test_buildIntervals_1() throws Exception public void test_buildIntervals_1() throws Exception
{ {
Repetition reps[] = new Repetition[]{ Repetition reps[] = new Repetition[]{
new Repetition(day(23), CHECKED_EXPLICITLY), new Repetition(day(23), YES_MANUAL),
new Repetition(day(18), CHECKED_EXPLICITLY), new Repetition(day(18), YES_MANUAL),
new Repetition(day(8), CHECKED_EXPLICITLY), new Repetition(day(8), YES_MANUAL),
}; };
ArrayList<CheckmarkList.Interval> expected = new ArrayList<>(); ArrayList<CheckmarkList.Interval> expected = new ArrayList<>();
@ -139,9 +138,9 @@ public class CheckmarkListTest extends BaseUnitTest
public void test_buildIntervals_2() throws Exception public void test_buildIntervals_2() throws Exception
{ {
Repetition reps[] = new Repetition[]{ Repetition reps[] = new Repetition[]{
new Repetition(day(23), CHECKED_EXPLICITLY), new Repetition(day(23), YES_MANUAL),
new Repetition(day(18), CHECKED_EXPLICITLY), new Repetition(day(18), YES_MANUAL),
new Repetition(day(8), CHECKED_EXPLICITLY), new Repetition(day(8), YES_MANUAL),
}; };
ArrayList<CheckmarkList.Interval> expected = new ArrayList<>(); ArrayList<CheckmarkList.Interval> expected = new ArrayList<>();
@ -158,11 +157,11 @@ public class CheckmarkListTest extends BaseUnitTest
public void test_buildIntervals_3() throws Exception public void test_buildIntervals_3() throws Exception
{ {
Repetition reps[] = new Repetition[]{ Repetition reps[] = new Repetition[]{
new Repetition(day(23), CHECKED_EXPLICITLY), new Repetition(day(23), YES_MANUAL),
new Repetition(day(22), CHECKED_EXPLICITLY), new Repetition(day(22), YES_MANUAL),
new Repetition(day(18), CHECKED_EXPLICITLY), new Repetition(day(18), YES_MANUAL),
new Repetition(day(15), CHECKED_EXPLICITLY), new Repetition(day(15), YES_MANUAL),
new Repetition(day(8), CHECKED_EXPLICITLY), new Repetition(day(8), YES_MANUAL),
}; };
ArrayList<CheckmarkList.Interval> expected = new ArrayList<>(); ArrayList<CheckmarkList.Interval> expected = new ArrayList<>();
@ -181,9 +180,9 @@ public class CheckmarkListTest extends BaseUnitTest
public void test_buildIntervals_4() throws Exception public void test_buildIntervals_4() throws Exception
{ {
Repetition[] reps = new Repetition[]{ Repetition[] reps = new Repetition[]{
new Repetition(day(30), CHECKED_EXPLICITLY), new Repetition(day(30), YES_MANUAL),
new Repetition(day(20), SKIPPED), new Repetition(day(20), SKIP),
new Repetition(day(10), CHECKED_EXPLICITLY), new Repetition(day(10), YES_MANUAL),
}; };
ArrayList<CheckmarkList.Interval> expected = new ArrayList<>(); ArrayList<CheckmarkList.Interval> expected = new ArrayList<>();
@ -201,13 +200,13 @@ public class CheckmarkListTest extends BaseUnitTest
travelInTime(-3); travelInTime(-3);
int[] expectedValues = { int[] expectedValues = {
CHECKED_EXPLICITLY, YES_MANUAL,
CHECKED_EXPLICITLY, YES_MANUAL,
CHECKED_EXPLICITLY, YES_MANUAL,
CHECKED_IMPLICITLY, YES_AUTO,
CHECKED_IMPLICITLY, YES_AUTO,
CHECKED_EXPLICITLY, YES_MANUAL,
CHECKED_EXPLICITLY YES_MANUAL
}; };
int[] actualValues = nonDailyHabit.getCheckmarks().getAllValues(); int[] actualValues = nonDailyHabit.getCheckmarks().getAllValues();
@ -221,19 +220,19 @@ public class CheckmarkListTest extends BaseUnitTest
travelInTime(3); travelInTime(3);
int[] expectedValues = { int[] expectedValues = {
UNCHECKED, NO,
UNCHECKED, NO,
UNCHECKED, NO,
CHECKED_EXPLICITLY, YES_MANUAL,
UNCHECKED, NO,
CHECKED_IMPLICITLY, YES_AUTO,
CHECKED_EXPLICITLY, YES_MANUAL,
CHECKED_EXPLICITLY, YES_MANUAL,
CHECKED_EXPLICITLY, YES_MANUAL,
CHECKED_IMPLICITLY, YES_AUTO,
CHECKED_IMPLICITLY, YES_AUTO,
CHECKED_EXPLICITLY, YES_MANUAL,
CHECKED_EXPLICITLY YES_MANUAL
}; };
int[] actualValues = nonDailyHabit.getCheckmarks().getAllValues(); int[] actualValues = nonDailyHabit.getCheckmarks().getAllValues();
@ -254,16 +253,16 @@ public class CheckmarkListTest extends BaseUnitTest
public void test_getAllValues_withNonDailyHabit() public void test_getAllValues_withNonDailyHabit()
{ {
int[] expectedValues = { int[] expectedValues = {
CHECKED_EXPLICITLY, YES_MANUAL,
UNCHECKED, NO,
CHECKED_IMPLICITLY, YES_AUTO,
CHECKED_EXPLICITLY, YES_MANUAL,
CHECKED_EXPLICITLY, YES_MANUAL,
CHECKED_EXPLICITLY, YES_MANUAL,
CHECKED_IMPLICITLY, YES_AUTO,
CHECKED_IMPLICITLY, YES_AUTO,
CHECKED_EXPLICITLY, YES_MANUAL,
CHECKED_EXPLICITLY YES_MANUAL
}; };
int[] actualValues = nonDailyHabit.getCheckmarks().getAllValues(); int[] actualValues = nonDailyHabit.getCheckmarks().getAllValues();
@ -291,13 +290,13 @@ public class CheckmarkListTest extends BaseUnitTest
CheckmarkList checkmarks = nonDailyHabit.getCheckmarks(); CheckmarkList checkmarks = nonDailyHabit.getCheckmarks();
travelInTime(-1); travelInTime(-1);
assertThat(checkmarks.getTodayValue(), equalTo(UNCHECKED)); assertThat(checkmarks.getTodayValue(), equalTo(NO));
travelInTime(0); travelInTime(0);
assertThat(checkmarks.getTodayValue(), equalTo(CHECKED_EXPLICITLY)); assertThat(checkmarks.getTodayValue(), equalTo(YES_MANUAL));
travelInTime(1); travelInTime(1);
assertThat(checkmarks.getTodayValue(), equalTo(UNCHECKED)); assertThat(checkmarks.getTodayValue(), equalTo(NO));
} }
@Test @Test
@ -316,17 +315,17 @@ public class CheckmarkListTest extends BaseUnitTest
Timestamp to = today.minus(5); Timestamp to = today.minus(5);
int[] expectedValues = { int[] expectedValues = {
CHECKED_EXPLICITLY, YES_MANUAL,
CHECKED_IMPLICITLY, YES_AUTO,
CHECKED_IMPLICITLY, YES_AUTO,
CHECKED_EXPLICITLY, YES_MANUAL,
CHECKED_EXPLICITLY, YES_MANUAL,
UNCHECKED, NO,
UNCHECKED, NO,
UNCHECKED, NO,
UNCHECKED, NO,
UNCHECKED, NO,
UNCHECKED NO
}; };
int[] actualValues = nonDailyHabit.getCheckmarks().getValues(from, to); int[] actualValues = nonDailyHabit.getCheckmarks().getValues(from, to);

@ -70,12 +70,12 @@ public class SQLiteRepetitionListTest extends BaseUnitTest
RepetitionRecord record = getByTimestamp(today.plus(1)); RepetitionRecord record = getByTimestamp(today.plus(1));
assertNull(record); assertNull(record);
Repetition rep = new Repetition(today.plus(1), CHECKED_EXPLICITLY); Repetition rep = new Repetition(today.plus(1), YES_MANUAL);
habit.getRepetitions().add(rep); habit.getRepetitions().add(rep);
record = getByTimestamp(today.plus(1)); record = getByTimestamp(today.plus(1));
assertNotNull(record); assertNotNull(record);
assertThat(record.value, equalTo(CHECKED_EXPLICITLY)); assertThat(record.value, equalTo(YES_MANUAL));
} }
@Test @Test

@ -84,7 +84,7 @@ public class HabitCardListCacheTest extends BaseUnitTest
{ {
Habit h2 = habitList.getByPosition(2); Habit h2 = habitList.getByPosition(2);
Timestamp today = DateUtils.getToday(); Timestamp today = DateUtils.getToday();
commandRunner.execute(new CreateRepetitionCommand(habitList, h2, today, Checkmark.UNCHECKED), h2.getId()); commandRunner.execute(new CreateRepetitionCommand(habitList, h2, today, Checkmark.NO), h2.getId());
verify(listener).onItemChanged(2); verify(listener).onItemChanged(2);
verify(listener).onRefreshFinished(); verify(listener).onRefreshFinished();
verifyNoMoreInteractions(listener); verifyNoMoreInteractions(listener);

@ -173,7 +173,7 @@ public class ListHabitsBehaviorTest extends BaseUnitTest
public void testOnToggle() public void testOnToggle()
{ {
assertTrue(habit1.isCompletedToday()); assertTrue(habit1.isCompletedToday());
behavior.onToggle(habit1, DateUtils.getToday(), Checkmark.UNCHECKED); behavior.onToggle(habit1, DateUtils.getToday(), Checkmark.NO);
assertFalse(habit1.isCompletedToday()); assertFalse(habit1.isCompletedToday());
} }

Loading…
Cancel
Save