mirror of
https://github.com/iSoron/uhabits.git
synced 2025-12-06 09:08:52 -06:00
Convert Checkmark to Kotlin
This commit is contained in:
@@ -19,13 +19,15 @@
|
|||||||
|
|
||||||
package org.isoron.uhabits.activities.habits.list.views
|
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 androidx.test.filters.*
|
||||||
import org.hamcrest.CoreMatchers.*
|
import org.hamcrest.CoreMatchers.*
|
||||||
import org.hamcrest.MatcherAssert.*
|
import org.hamcrest.MatcherAssert.*
|
||||||
import org.isoron.uhabits.*
|
import org.isoron.uhabits.*
|
||||||
import org.isoron.uhabits.core.models.*
|
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.isoron.uhabits.utils.*
|
||||||
import org.junit.*
|
import org.junit.*
|
||||||
import org.junit.runner.*
|
import org.junit.runner.*
|
||||||
|
|||||||
@@ -25,9 +25,12 @@ import android.text.*
|
|||||||
import android.view.*
|
import android.view.*
|
||||||
import android.view.View.MeasureSpec.*
|
import android.view.View.MeasureSpec.*
|
||||||
import com.google.auto.factory.*
|
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.*
|
||||||
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.core.preferences.*
|
||||||
import org.isoron.uhabits.inject.*
|
import org.isoron.uhabits.inject.*
|
||||||
import org.isoron.uhabits.utils.*
|
import org.isoron.uhabits.utils.*
|
||||||
|
|||||||
@@ -22,7 +22,7 @@ package org.isoron.uhabits.activities.habits.list.views
|
|||||||
import android.content.*
|
import android.content.*
|
||||||
import com.google.auto.factory.*
|
import com.google.auto.factory.*
|
||||||
import org.isoron.uhabits.core.models.*
|
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.preferences.*
|
||||||
import org.isoron.uhabits.core.utils.*
|
import org.isoron.uhabits.core.utils.*
|
||||||
import org.isoron.uhabits.inject.*
|
import org.isoron.uhabits.inject.*
|
||||||
|
|||||||
@@ -1,132 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (C) 2016 Álinson Santos Xavier <isoron@gmail.com>
|
|
||||||
*
|
|
||||||
* 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 <http://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
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.
|
|
||||||
* <p>
|
|
||||||
* 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.
|
|
||||||
* </p>
|
|
||||||
* <p>
|
|
||||||
* Note that the status comparator in
|
|
||||||
* {@link org.isoron.uhabits.core.models.memory.MemoryHabitList}
|
|
||||||
* relies on SKIP > YES_MANUAL > YES_AUTO > NO.
|
|
||||||
* <p>
|
|
||||||
* 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.
|
|
||||||
* <p>
|
|
||||||
* 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.
|
|
||||||
*/
|
|
||||||
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();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -0,0 +1,63 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2016 Álinson Santos Xavier <isoron@gmail.com>
|
||||||
|
*
|
||||||
|
* 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 <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
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
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -392,20 +392,6 @@ public class CheckmarkListTest extends BaseUnitTest
|
|||||||
FIXED_LOCAL_TIME + days * Timestamp.DAY_LENGTH);
|
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
|
@Test
|
||||||
public void testEquals() throws Exception
|
public void testEquals() throws Exception
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user