Added Streaks info for numeric habits

pull/1514/merge
Abdul Majeed 11 months ago committed by Alinson S. Xavier
parent 2296a49999
commit 13ecc2a386

@ -52,10 +52,7 @@ class ShowHabitView(context: Context) : FrameLayout(context) {
binding.frequencyCard.setState(data.frequency)
binding.historyCard.setState(data.history)
binding.barCard.setState(data.bar)
if (data.isNumerical) {
binding.overviewCard.visibility = GONE
binding.streakCard.visibility = GONE
} else {
if (!data.isNumerical) {
binding.targetCard.visibility = GONE
}
}

@ -100,7 +100,10 @@ data class Habit(
streaks.recompute(
computedEntries,
from,
to
to,
isNumerical,
targetValue,
targetType
)
}

@ -37,12 +37,25 @@ class StreakList {
fun recompute(
computedEntries: EntryList,
from: Timestamp,
to: Timestamp
to: Timestamp,
isNumerical: Boolean,
targetValue: Double,
targetType: NumericalHabitType
) {
list.clear()
val timestamps = computedEntries
.getByInterval(from, to)
.filter { it.value > 0 }
.filter {
val value = it.value
if (isNumerical) {
when (targetType) {
NumericalHabitType.AT_LEAST -> value / 1000.0 >= targetValue
NumericalHabitType.AT_MOST -> value != Entry.UNKNOWN && value / 1000.0 <= targetValue
}
} else {
value > 0
}
}
.map { it.timestamp }
.toTypedArray()

Loading…
Cancel
Save