mirror of
https://github.com/iSoron/uhabits.git
synced 2025-12-06 09:08:52 -06:00
Show numerical habits
This commit is contained in:
@@ -66,7 +66,7 @@ class Backend(databaseName: String,
|
||||
habits.putAll(habitsRepository.findAll())
|
||||
for ((key, habit) in habits) {
|
||||
val checks = checkmarkRepository.findAll(key)
|
||||
checkmarks[habit] = CheckmarkList(habit.frequency)
|
||||
checkmarks[habit] = CheckmarkList(habit.frequency, habit.type)
|
||||
checkmarks[habit]?.setManualCheckmarks(checks)
|
||||
}
|
||||
}
|
||||
@@ -81,7 +81,7 @@ class Backend(databaseName: String,
|
||||
habit.id = id
|
||||
habit.position = habits.size
|
||||
habits[id] = habit
|
||||
checkmarks[habit] = CheckmarkList(habit.frequency)
|
||||
checkmarks[habit] = CheckmarkList(habit.frequency, habit.type)
|
||||
habitsRepository.insert(habit)
|
||||
mainScreenDataSource.requestData()
|
||||
}
|
||||
|
||||
@@ -57,7 +57,8 @@ class MainScreenDataSource(val preferences: Preferences,
|
||||
|
||||
if (!preferences.showCompleted) {
|
||||
filtered = filtered.filter { habit ->
|
||||
recentCheckmarks.getValue(habit)[0] == UNCHECKED
|
||||
(habit.type == HabitType.BOOLEAN_HABIT && recentCheckmarks.getValue(habit)[0] == UNCHECKED) ||
|
||||
(habit.type == HabitType.NUMERICAL_HABIT && recentCheckmarks.getValue(habit)[0] * 1000 < habit.target)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -24,7 +24,8 @@ import org.isoron.uhabits.models.Checkmark.Companion.CHECKED_AUTOMATIC
|
||||
import org.isoron.uhabits.models.Checkmark.Companion.CHECKED_MANUAL
|
||||
import org.isoron.uhabits.models.Checkmark.Companion.UNCHECKED
|
||||
|
||||
class CheckmarkList(private val frequency: Frequency) {
|
||||
class CheckmarkList(private val frequency: Frequency,
|
||||
private val habitType: HabitType) {
|
||||
|
||||
private val manualCheckmarks = mutableListOf<Checkmark>()
|
||||
private val automaticCheckmarks = mutableListOf<Checkmark>()
|
||||
@@ -37,8 +38,12 @@ class CheckmarkList(private val frequency: Frequency) {
|
||||
manualCheckmarks.clear()
|
||||
automaticCheckmarks.clear()
|
||||
manualCheckmarks.addAll(checks)
|
||||
automaticCheckmarks.addAll(computeAutomaticCheckmarks(checks,
|
||||
frequency))
|
||||
if (habitType == HabitType.NUMERICAL_HABIT) {
|
||||
automaticCheckmarks.addAll(checks)
|
||||
} else {
|
||||
val computed = computeAutomaticCheckmarks(checks, frequency)
|
||||
automaticCheckmarks.addAll(computed)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -75,7 +75,7 @@ class HabitRepository(var db: Database) {
|
||||
position = stmt.getInt(7),
|
||||
unit = stmt.getText(8),
|
||||
target = stmt.getReal(9),
|
||||
type = if (stmt.getInt(10) == 0) HabitType.YES_NO_HABIT else HabitType.NUMERICAL_HABIT)
|
||||
type = if (stmt.getInt(10) == 0) HabitType.BOOLEAN_HABIT else HabitType.NUMERICAL_HABIT)
|
||||
}
|
||||
|
||||
private fun bindHabitToStatement(habit: Habit, statement: PreparedStatement) {
|
||||
|
||||
@@ -20,6 +20,6 @@
|
||||
package org.isoron.uhabits.models
|
||||
|
||||
enum class HabitType(val code: Int) {
|
||||
YES_NO_HABIT(0),
|
||||
BOOLEAN_HABIT(0),
|
||||
NUMERICAL_HABIT(1),
|
||||
}
|
||||
@@ -159,7 +159,7 @@ class CheckmarkListTest : BaseTest() {
|
||||
|
||||
@Test
|
||||
fun testGetValuesUntil() {
|
||||
val list = CheckmarkList(Frequency(1, 2))
|
||||
val list = CheckmarkList(Frequency(1, 2), HabitType.BOOLEAN_HABIT)
|
||||
list.setManualCheckmarks(listOf(Checkmark(day(4), CHECKED_MANUAL),
|
||||
Checkmark(day(7), CHECKED_MANUAL)))
|
||||
val expected = listOf(UNCHECKED,
|
||||
@@ -182,7 +182,7 @@ class CheckmarkListTest : BaseTest() {
|
||||
|
||||
@Test
|
||||
fun testGetValuesUntil2() {
|
||||
val list = CheckmarkList(Frequency(1, 2))
|
||||
val list = CheckmarkList(Frequency(1, 2), HabitType.BOOLEAN_HABIT)
|
||||
val expected = listOf<Int>()
|
||||
assertEquals(expected, list.getValuesUntil(day(0)))
|
||||
}
|
||||
|
||||
@@ -44,7 +44,7 @@ class HabitRepositoryTest : BaseTest() {
|
||||
position = 0,
|
||||
unit = "",
|
||||
target = 0.0,
|
||||
type = HabitType.YES_NO_HABIT)
|
||||
type = HabitType.BOOLEAN_HABIT)
|
||||
|
||||
original1 = Habit(id = 1,
|
||||
name = "Exercise",
|
||||
@@ -55,7 +55,7 @@ class HabitRepositoryTest : BaseTest() {
|
||||
position = 1,
|
||||
unit = "",
|
||||
target = 0.0,
|
||||
type = HabitType.YES_NO_HABIT)
|
||||
type = HabitType.BOOLEAN_HABIT)
|
||||
|
||||
original2 = Habit(id = 2,
|
||||
name = "Learn Japanese",
|
||||
@@ -66,7 +66,7 @@ class HabitRepositoryTest : BaseTest() {
|
||||
position = 2,
|
||||
unit = "",
|
||||
target = 0.0,
|
||||
type = HabitType.YES_NO_HABIT)
|
||||
type = HabitType.BOOLEAN_HABIT)
|
||||
|
||||
repository = HabitRepository(db)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user