Skip to content

Commit 13ecc2a

Browse files
Abdul MajeediSoron
authored andcommitted
Added Streaks info for numeric habits
1 parent 2296a49 commit 13ecc2a

File tree

3 files changed

+20
-7
lines changed

3 files changed

+20
-7
lines changed

uhabits-android/src/main/java/org/isoron/uhabits/activities/habits/show/ShowHabitView.kt

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,10 +52,7 @@ class ShowHabitView(context: Context) : FrameLayout(context) {
5252
binding.frequencyCard.setState(data.frequency)
5353
binding.historyCard.setState(data.history)
5454
binding.barCard.setState(data.bar)
55-
if (data.isNumerical) {
56-
binding.overviewCard.visibility = GONE
57-
binding.streakCard.visibility = GONE
58-
} else {
55+
if (!data.isNumerical) {
5956
binding.targetCard.visibility = GONE
6057
}
6158
}

uhabits-core/src/jvmMain/java/org/isoron/uhabits/core/models/Habit.kt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,10 @@ data class Habit(
100100
streaks.recompute(
101101
computedEntries,
102102
from,
103-
to
103+
to,
104+
isNumerical,
105+
targetValue,
106+
targetType
104107
)
105108
}
106109

uhabits-core/src/jvmMain/java/org/isoron/uhabits/core/models/StreakList.kt

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,25 @@ class StreakList {
3737
fun recompute(
3838
computedEntries: EntryList,
3939
from: Timestamp,
40-
to: Timestamp
40+
to: Timestamp,
41+
isNumerical: Boolean,
42+
targetValue: Double,
43+
targetType: NumericalHabitType
4144
) {
4245
list.clear()
4346
val timestamps = computedEntries
4447
.getByInterval(from, to)
45-
.filter { it.value > 0 }
48+
.filter {
49+
val value = it.value
50+
if (isNumerical) {
51+
when (targetType) {
52+
NumericalHabitType.AT_LEAST -> value / 1000.0 >= targetValue
53+
NumericalHabitType.AT_MOST -> value != Entry.UNKNOWN && value / 1000.0 <= targetValue
54+
}
55+
} else {
56+
value > 0
57+
}
58+
}
4659
.map { it.timestamp }
4760
.toTypedArray()
4861

0 commit comments

Comments
 (0)