diff --git a/android/uhabits-android/src/main/java/org/isoron/uhabits/activities/common/views/HistoryChart.java b/android/uhabits-android/src/main/java/org/isoron/uhabits/activities/common/views/HistoryChart.java index d27bdc280..50bee35b9 100644 --- a/android/uhabits-android/src/main/java/org/isoron/uhabits/activities/common/views/HistoryChart.java +++ b/android/uhabits-android/src/main/java/org/isoron/uhabits/activities/common/views/HistoryChart.java @@ -158,9 +158,9 @@ public class HistoryChart extends ScrollableChart if (offset < checkmarks.length) { if(skipsEnabled) - newValue = Repetition.nextToggleValueWithSkip(checkmarks[offset]); + newValue = Checkmark.Companion.nextToggleValueWithSkip(checkmarks[offset]); else - newValue = Repetition.nextToggleValueWithoutSkip(checkmarks[offset]); + newValue = Checkmark.Companion.nextToggleValueWithoutSkip(checkmarks[offset]); } onToggleCheckmarkListener.onToggleCheckmark(timestamp, newValue); diff --git a/android/uhabits-android/src/main/java/org/isoron/uhabits/activities/habits/list/views/CheckmarkButtonView.kt b/android/uhabits-android/src/main/java/org/isoron/uhabits/activities/habits/list/views/CheckmarkButtonView.kt index 2faaf416e..7ce5e46bf 100644 --- a/android/uhabits-android/src/main/java/org/isoron/uhabits/activities/habits/list/views/CheckmarkButtonView.kt +++ b/android/uhabits-android/src/main/java/org/isoron/uhabits/activities/habits/list/views/CheckmarkButtonView.kt @@ -66,9 +66,9 @@ class CheckmarkButtonView( fun performToggle() { value = if(preferences.isSkipEnabled) { - Repetition.nextToggleValueWithSkip(value) + Checkmark.nextToggleValueWithSkip(value) } else { - Repetition.nextToggleValueWithoutSkip(value) + Checkmark.nextToggleValueWithoutSkip(value) } onToggle(value) performHapticFeedback(HapticFeedbackConstants.LONG_PRESS) diff --git a/android/uhabits-core/src/main/java/org/isoron/uhabits/core/models/Checkmark.kt b/android/uhabits-core/src/main/java/org/isoron/uhabits/core/models/Checkmark.kt index 2f52f00e5..9d08a7b25 100644 --- a/android/uhabits-core/src/main/java/org/isoron/uhabits/core/models/Checkmark.kt +++ b/android/uhabits-core/src/main/java/org/isoron/uhabits/core/models/Checkmark.kt @@ -59,5 +59,22 @@ data class Checkmark( * Checkmark value indicating that no data is available for the given timestamp. */ const val UNKNOWN = -1 + + fun nextToggleValueWithSkip(value: Int): Int { + return when (value) { + NO, UNKNOWN, YES_AUTO -> YES_MANUAL + YES_MANUAL -> SKIP + SKIP -> NO + else -> NO + } + } + + fun nextToggleValueWithoutSkip(value: Int): Int { + return when (value) { + NO, UNKNOWN, YES_AUTO -> YES_MANUAL + else -> NO + } + } + } } \ No newline at end of file diff --git a/android/uhabits-core/src/main/java/org/isoron/uhabits/core/models/Repetition.java b/android/uhabits-core/src/main/java/org/isoron/uhabits/core/models/Repetition.java deleted file mode 100644 index 9c3ec30f9..000000000 --- a/android/uhabits-core/src/main/java/org/isoron/uhabits/core/models/Repetition.java +++ /dev/null @@ -1,128 +0,0 @@ -/* - * Copyright (C) 2016 Álinson Santos Xavier - * - * This file is part of Loop Habit Tracker. - * - * Loop Habit Tracker is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by the - * Free Software Foundation, either version 3 of the License, or (at your - * option) any later version. - * - * Loop Habit Tracker is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY - * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for - * more details. - * - * You should have received a copy of the GNU General Public License along - * with this program. If not, see . - */ - -package org.isoron.uhabits.core.models; - -import org.apache.commons.lang3.builder.*; - -import static org.isoron.uhabits.core.models.Checkmark.*; -import static org.isoron.uhabits.core.utils.StringUtils.defaultToStringStyle; - -/** - * Represents a record that the user has performed or skipped a certain habit at a certain - * date. - */ -public final class Repetition -{ - - private final Timestamp timestamp; - - /** - * The value of the repetition. - * - * 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. - */ - private final int value; - - /** - * Creates a new repetition with given parameters. - *

- * The timestamp corresponds to the days this repetition occurred. Time of - * day must be midnight (UTC). - * - * @param timestamp the time this repetition occurred. - */ - public Repetition(Timestamp timestamp, int value) - { - this.timestamp = timestamp; - this.value = value; - } - - public static int nextToggleValueWithSkip(int value) - { - switch(value) { - case NO: - case UNKNOWN: - case YES_AUTO: - return YES_MANUAL; - case YES_MANUAL: - return SKIP; - default: - case SKIP: - return NO; - } - } - - public static int nextToggleValueWithoutSkip(int value) - { - switch(value) { - case NO: - case UNKNOWN: - case YES_AUTO: - return YES_MANUAL; - default: - return NO; - } - } - - - @Override - public boolean equals(Object o) - { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - - Repetition that = (Repetition) o; - - return new EqualsBuilder() - .append(timestamp, that.timestamp) - .append(value, that.value) - .isEquals(); - } - - public Timestamp getTimestamp() - { - return timestamp; - } - - public int getValue() - { - return value; - } - - @Override - public int hashCode() - { - return new HashCodeBuilder(17, 37) - .append(timestamp) - .append(value) - .toHashCode(); - } - - @Override - public String toString() - { - return new ToStringBuilder(this, defaultToStringStyle()) - .append("timestamp", timestamp) - .append("value", value) - .toString(); - } -} diff --git a/android/uhabits-core/src/main/java/org/isoron/uhabits/core/models/Repetition.kt b/android/uhabits-core/src/main/java/org/isoron/uhabits/core/models/Repetition.kt new file mode 100644 index 000000000..248a0bd16 --- /dev/null +++ b/android/uhabits-core/src/main/java/org/isoron/uhabits/core/models/Repetition.kt @@ -0,0 +1,32 @@ +/* + * Copyright (C) 2016 Álinson Santos Xavier + * + * This file is part of Loop Habit Tracker. + * + * Loop Habit Tracker is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by the + * Free Software Foundation, either version 3 of the License, or (at your + * option) any later version. + * + * Loop Habit Tracker is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License along + * with this program. If not, see . + */ +package org.isoron.uhabits.core.models + +data class Repetition( + /** + * Time the repetition took place. + */ + val timestamp: Timestamp, + /** + * For boolean habits, [value] 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. + */ + val value: Int, +); \ No newline at end of file diff --git a/android/uhabits-core/src/main/java/org/isoron/uhabits/core/ui/widgets/WidgetBehavior.java b/android/uhabits-core/src/main/java/org/isoron/uhabits/core/ui/widgets/WidgetBehavior.java index fae0b53d4..9f6abce6b 100644 --- a/android/uhabits-core/src/main/java/org/isoron/uhabits/core/ui/widgets/WidgetBehavior.java +++ b/android/uhabits-core/src/main/java/org/isoron/uhabits/core/ui/widgets/WidgetBehavior.java @@ -73,9 +73,9 @@ public class WidgetBehavior int currentValue = habit.getRepetitions().getValue(timestamp); int newValue; if(preferences.isSkipEnabled()) - newValue = Repetition.nextToggleValueWithSkip(currentValue); + newValue = Checkmark.Companion.nextToggleValueWithSkip(currentValue); else - newValue = Repetition.nextToggleValueWithoutSkip(currentValue); + newValue = Checkmark.Companion.nextToggleValueWithoutSkip(currentValue); setValue(habit, timestamp, newValue); notificationTray.cancel(habit); } diff --git a/android/uhabits-core/src/test/java/org/isoron/uhabits/core/models/RepetitionListTest.java b/android/uhabits-core/src/test/java/org/isoron/uhabits/core/models/RepetitionListTest.java index add47d86a..4c53e1d57 100644 --- a/android/uhabits-core/src/test/java/org/isoron/uhabits/core/models/RepetitionListTest.java +++ b/android/uhabits-core/src/test/java/org/isoron/uhabits/core/models/RepetitionListTest.java @@ -161,11 +161,4 @@ public class RepetitionListTest extends BaseUnitTest verify(listener, times(2)).onModelChange(); reset(listener); } - - @Test - public void testToString() throws Exception - { - Repetition rep = new Repetition(Timestamp.ZERO.plus(100), 20); - assertThat(rep.toString(), equalTo("{timestamp: 1970-04-11, value: 20}")); - } } \ No newline at end of file diff --git a/android/uhabits-core/src/test/java/org/isoron/uhabits/core/ui/widgets/WidgetBehaviorTest.java b/android/uhabits-core/src/test/java/org/isoron/uhabits/core/ui/widgets/WidgetBehaviorTest.java index eea405019..a999dd2b1 100644 --- a/android/uhabits-core/src/test/java/org/isoron/uhabits/core/ui/widgets/WidgetBehaviorTest.java +++ b/android/uhabits-core/src/test/java/org/isoron/uhabits/core/ui/widgets/WidgetBehaviorTest.java @@ -29,7 +29,6 @@ import org.junit.*; import java.util.*; import static org.isoron.uhabits.core.models.Checkmark.*; -import static org.junit.Assert.*; import static org.mockito.Mockito.*; public class WidgetBehaviorTest extends BaseUnitTest @@ -89,8 +88,8 @@ public class WidgetBehaviorTest extends BaseUnitTest when(preferences.isSkipEnabled()).thenReturn(skipEnabled); int nextValue; - if(skipEnabled) nextValue = Repetition.nextToggleValueWithSkip(currentValue); - else nextValue = Repetition.nextToggleValueWithoutSkip(currentValue); + if(skipEnabled) nextValue = Checkmark.Companion.nextToggleValueWithSkip(currentValue); + else nextValue = Checkmark.Companion.nextToggleValueWithoutSkip(currentValue); habit.getRepetitions().setValue(timestamp, currentValue); behavior.onToggleRepetition(habit, timestamp);