mirror of
https://github.com/iSoron/uhabits.git
synced 2025-12-06 09:08:52 -06:00
Added Streaks info for numeric habits
This commit is contained in:
@@ -52,10 +52,7 @@ class ShowHabitView(context: Context) : FrameLayout(context) {
|
|||||||
binding.frequencyCard.setState(data.frequency)
|
binding.frequencyCard.setState(data.frequency)
|
||||||
binding.historyCard.setState(data.history)
|
binding.historyCard.setState(data.history)
|
||||||
binding.barCard.setState(data.bar)
|
binding.barCard.setState(data.bar)
|
||||||
if (data.isNumerical) {
|
if (!data.isNumerical) {
|
||||||
binding.overviewCard.visibility = GONE
|
|
||||||
binding.streakCard.visibility = GONE
|
|
||||||
} else {
|
|
||||||
binding.targetCard.visibility = GONE
|
binding.targetCard.visibility = GONE
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -100,7 +100,10 @@ data class Habit(
|
|||||||
streaks.recompute(
|
streaks.recompute(
|
||||||
computedEntries,
|
computedEntries,
|
||||||
from,
|
from,
|
||||||
to
|
to,
|
||||||
|
isNumerical,
|
||||||
|
targetValue,
|
||||||
|
targetType
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -37,12 +37,25 @@ class StreakList {
|
|||||||
fun recompute(
|
fun recompute(
|
||||||
computedEntries: EntryList,
|
computedEntries: EntryList,
|
||||||
from: Timestamp,
|
from: Timestamp,
|
||||||
to: Timestamp
|
to: Timestamp,
|
||||||
|
isNumerical: Boolean,
|
||||||
|
targetValue: Double,
|
||||||
|
targetType: NumericalHabitType
|
||||||
) {
|
) {
|
||||||
list.clear()
|
list.clear()
|
||||||
val timestamps = computedEntries
|
val timestamps = computedEntries
|
||||||
.getByInterval(from, to)
|
.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 }
|
.map { it.timestamp }
|
||||||
.toTypedArray()
|
.toTypedArray()
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user