mirror of
https://github.com/iSoron/uhabits.git
synced 2025-12-06 09:08:52 -06:00
Compare commits
6 Commits
62d9d29e91
...
107c898f51
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
107c898f51 | ||
|
|
4a7d7ef490 | ||
|
|
13ecc2a386 | ||
|
|
2296a49999 | ||
|
|
303020a8c0 | ||
|
|
37219cb13f |
@@ -18,5 +18,6 @@ allprojects {
|
||||
maven(url = "https://plugins.gradle.org/m2/")
|
||||
maven(url = "https://oss.sonatype.org/content/repositories/snapshots/")
|
||||
maven(url = "https://jitpack.io")
|
||||
maven(url = "https://maven.pkg.jetbrains.space/kotlin/p/kotlin/kotlin-js-wrappers/") // Repository for kotlin-css-jvm old versions, now that the Gradle Plugin Portal no longer brings these in by mirroring JCenter
|
||||
}
|
||||
}
|
||||
|
||||
@@ -54,7 +54,6 @@ class ShowHabitView(context: Context) : FrameLayout(context) {
|
||||
binding.barCard.setState(data.bar)
|
||||
if (data.isNumerical) {
|
||||
binding.overviewCard.visibility = GONE
|
||||
binding.streakCard.visibility = GONE
|
||||
} else {
|
||||
binding.targetCard.visibility = GONE
|
||||
}
|
||||
|
||||
@@ -61,7 +61,7 @@ data class Habit(
|
||||
return if (isNumerical) {
|
||||
when (targetType) {
|
||||
NumericalHabitType.AT_LEAST -> value / 1000.0 >= targetValue
|
||||
NumericalHabitType.AT_MOST -> value != Entry.UNKNOWN && value / 1000.0 <= targetValue
|
||||
NumericalHabitType.AT_MOST -> false
|
||||
}
|
||||
} else {
|
||||
value != Entry.NO && value != Entry.UNKNOWN
|
||||
@@ -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()
|
||||
|
||||
|
||||
@@ -24,6 +24,7 @@ import org.isoron.uhabits.core.commands.CommandRunner
|
||||
import org.isoron.uhabits.core.commands.CreateRepetitionCommand
|
||||
import org.isoron.uhabits.core.commands.DeleteHabitsCommand
|
||||
import org.isoron.uhabits.core.models.Habit
|
||||
import org.isoron.uhabits.core.models.NumericalHabitType
|
||||
import org.isoron.uhabits.core.models.Timestamp
|
||||
import org.isoron.uhabits.core.preferences.Preferences
|
||||
import org.isoron.uhabits.core.tasks.Task
|
||||
@@ -120,7 +121,7 @@ class NotificationTray @Inject constructor(
|
||||
|
||||
override fun onPostExecute() {
|
||||
systemTray.log("Showing notification for habit=" + habit.id)
|
||||
if (isCompleted) {
|
||||
if (isCompleted && habit.targetType != NumericalHabitType.AT_MOST) {
|
||||
systemTray.log(
|
||||
String.format(
|
||||
Locale.US,
|
||||
|
||||
@@ -110,10 +110,10 @@ class HabitTest : BaseUnitTest() {
|
||||
assertFalse(h.isCompletedToday())
|
||||
h.originalEntries.add(Entry(getToday(), 100000))
|
||||
h.recompute()
|
||||
assertTrue(h.isCompletedToday())
|
||||
assertFalse(h.isCompletedToday())
|
||||
h.originalEntries.add(Entry(getToday(), 50000))
|
||||
h.recompute()
|
||||
assertTrue(h.isCompletedToday())
|
||||
assertFalse(h.isCompletedToday())
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
Reference in New Issue
Block a user