diff --git a/android/uhabits-android/src/androidTest/java/org/isoron/uhabits/activities/habits/list/views/CheckmarkPanelViewTest.kt b/android/uhabits-android/src/androidTest/java/org/isoron/uhabits/activities/habits/list/views/CheckmarkPanelViewTest.kt index f1f8301a4..40c269f06 100644 --- a/android/uhabits-android/src/androidTest/java/org/isoron/uhabits/activities/habits/list/views/CheckmarkPanelViewTest.kt +++ b/android/uhabits-android/src/androidTest/java/org/isoron/uhabits/activities/habits/list/views/CheckmarkPanelViewTest.kt @@ -19,13 +19,15 @@ package org.isoron.uhabits.activities.habits.list.views -import androidx.test.ext.junit.runners.AndroidJUnit4 +import androidx.test.ext.junit.runners.* import androidx.test.filters.* import org.hamcrest.CoreMatchers.* import org.hamcrest.MatcherAssert.* import org.isoron.uhabits.* import org.isoron.uhabits.core.models.* -import org.isoron.uhabits.core.models.Checkmark.* +import org.isoron.uhabits.core.models.Checkmark.Companion.NO +import org.isoron.uhabits.core.models.Checkmark.Companion.YES_AUTO +import org.isoron.uhabits.core.models.Checkmark.Companion.YES_MANUAL import org.isoron.uhabits.utils.* import org.junit.* import org.junit.runner.* 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 cb4f5d3f4..2faaf416e 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 @@ -25,9 +25,12 @@ import android.text.* import android.view.* import android.view.View.MeasureSpec.* import com.google.auto.factory.* -import org.isoron.uhabits.R +import org.isoron.uhabits.* import org.isoron.uhabits.core.models.* -import org.isoron.uhabits.core.models.Checkmark.* +import org.isoron.uhabits.core.models.Checkmark.Companion.NO +import org.isoron.uhabits.core.models.Checkmark.Companion.SKIP +import org.isoron.uhabits.core.models.Checkmark.Companion.UNKNOWN +import org.isoron.uhabits.core.models.Checkmark.Companion.YES_MANUAL import org.isoron.uhabits.core.preferences.* import org.isoron.uhabits.inject.* import org.isoron.uhabits.utils.* diff --git a/android/uhabits-android/src/main/java/org/isoron/uhabits/activities/habits/list/views/CheckmarkPanelView.kt b/android/uhabits-android/src/main/java/org/isoron/uhabits/activities/habits/list/views/CheckmarkPanelView.kt index 0b9f6d0f1..6ef8d5708 100644 --- a/android/uhabits-android/src/main/java/org/isoron/uhabits/activities/habits/list/views/CheckmarkPanelView.kt +++ b/android/uhabits-android/src/main/java/org/isoron/uhabits/activities/habits/list/views/CheckmarkPanelView.kt @@ -22,7 +22,7 @@ package org.isoron.uhabits.activities.habits.list.views import android.content.* import com.google.auto.factory.* import org.isoron.uhabits.core.models.* -import org.isoron.uhabits.core.models.Checkmark.* +import org.isoron.uhabits.core.models.Checkmark.Companion.UNKNOWN import org.isoron.uhabits.core.preferences.* import org.isoron.uhabits.core.utils.* import org.isoron.uhabits.inject.* diff --git a/android/uhabits-core/src/main/java/org/isoron/uhabits/core/models/Checkmark.java b/android/uhabits-core/src/main/java/org/isoron/uhabits/core/models/Checkmark.java deleted file mode 100644 index acaada1ca..000000000 --- a/android/uhabits-core/src/main/java/org/isoron/uhabits/core/models/Checkmark.java +++ /dev/null @@ -1,132 +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 javax.annotation.concurrent.*; - -import static org.isoron.uhabits.core.utils.StringUtils.defaultToStringStyle; - -/** - * A Checkmark represents the completion status of the habit for a given day. - *

- * While repetitions simply record that the habit was performed at a given date, - * a checkmark provides more information, such as whether a repetition was - * expected at that day or not. - *

- *

- * Note that the status comparator in - * {@link org.isoron.uhabits.core.models.memory.MemoryHabitList} - * relies on SKIP > YES_MANUAL > YES_AUTO > NO. - *

- * Checkmarks are computed automatically from the list of repetitions. - */ -@ThreadSafe -public final class Checkmark -{ - /** - * Checkmark value indicating that the habit is not applicable for this timestamp. - */ - public static final int SKIP = 3; - - /** - * Checkmark value indicating that the user has performed the habit at this timestamp. - */ - public static final int YES_MANUAL = 2; - - /** - * Checkmark value indicating that the user did not perform the habit, but they were not - * expected to, because of the frequency of the habit. - */ - public static final int YES_AUTO = 1; - - /** - * Checkmark value indicating that the user did not perform the habit, even though they were - * expected to perform it. - */ - 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; - - /** - * The value of the checkmark. - *

- * For boolean habits, this equals either NO, YES_AUTO, YES_MANUAL or SKIP. - *

- * 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. - */ - private final int value; - - public Checkmark(Timestamp timestamp, int value) - { - this.timestamp = timestamp; - this.value = value; - } - - @Override - public boolean equals(Object o) - { - if (this == o) return true; - - if (o == null || getClass() != o.getClass()) return false; - - Checkmark checkmark = (Checkmark) o; - - return new EqualsBuilder() - .append(timestamp, checkmark.timestamp) - .append(value, checkmark.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/Checkmark.kt b/android/uhabits-core/src/main/java/org/isoron/uhabits/core/models/Checkmark.kt new file mode 100644 index 000000000..2f52f00e5 --- /dev/null +++ b/android/uhabits-core/src/main/java/org/isoron/uhabits/core/models/Checkmark.kt @@ -0,0 +1,63 @@ +/* + * 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 + +/** + * A Checkmark represents the completion status of the habit for a given day. + * + * While repetitions simply record that the habit was performed at a given date, a checkmark + * provides more information, such as whether a repetition was expected at that day or not. + * + * Checkmarks are computed automatically from the list of repetitions. + * + * Note that the status comparator in relies on SKIP > YES_MANUAL > YES_AUTO > NO. + */ +data class Checkmark( + val timestamp: Timestamp, + val value: Int, +) { + companion object { + /** + * Checkmark value indicating that the habit is not applicable for this timestamp. + */ + const val SKIP = 3 + + /** + * Checkmark value indicating that the user has performed the habit at this timestamp. + */ + const val YES_MANUAL = 2 + + /** + * Checkmark value indicating that the user did not perform the habit, but they were not + * expected to, because of the frequency of the habit. + */ + const val YES_AUTO = 1 + + /** + * Checkmark value indicating that the user did not perform the habit, even though they were + * expected to perform it. + */ + const val NO = 0 + + /** + * Checkmark value indicating that no data is available for the given timestamp. + */ + const val UNKNOWN = -1 + } +} \ No newline at end of file diff --git a/android/uhabits-core/src/test/java/org/isoron/uhabits/core/models/CheckmarkListTest.java b/android/uhabits-core/src/test/java/org/isoron/uhabits/core/models/CheckmarkListTest.java index 54787bed1..6a35b40cc 100644 --- a/android/uhabits-core/src/test/java/org/isoron/uhabits/core/models/CheckmarkListTest.java +++ b/android/uhabits-core/src/test/java/org/isoron/uhabits/core/models/CheckmarkListTest.java @@ -392,20 +392,6 @@ public class CheckmarkListTest extends BaseUnitTest FIXED_LOCAL_TIME + days * Timestamp.DAY_LENGTH); } - @Test - public void testToString() throws Exception - { - Timestamp t = Timestamp.ZERO.plus(100); - Checkmark checkmark = new Checkmark(t, 2); - assertThat(checkmark.toString(), - equalTo("{timestamp: 1970-04-11, value: 2}")); - - CheckmarkList.Interval interval = - new CheckmarkList.Interval(t, t.plus(1), t.plus(2)); - assertThat(interval.toString(), equalTo( - "{begin: 1970-04-11, center: 1970-04-12, end: 1970-04-13}")); - } - @Test public void testEquals() throws Exception {