From 2523c8e15f5025d3f11b57f3c0d29fa01baf7eb5 Mon Sep 17 00:00:00 2001 From: Jakub Kalinowski Date: Wed, 9 Mar 2022 18:58:44 +0100 Subject: [PATCH] Experimenting --- .../org/isoron/uhabits/core/models/Entry.kt | 2 +- .../screens/habits/show/views/HistoryCard.kt | 64 +++++++++++++------ 2 files changed, 47 insertions(+), 19 deletions(-) diff --git a/uhabits-core/src/jvmMain/java/org/isoron/uhabits/core/models/Entry.kt b/uhabits-core/src/jvmMain/java/org/isoron/uhabits/core/models/Entry.kt index e7aefb8a6..7a5c50408 100644 --- a/uhabits-core/src/jvmMain/java/org/isoron/uhabits/core/models/Entry.kt +++ b/uhabits-core/src/jvmMain/java/org/isoron/uhabits/core/models/Entry.kt @@ -26,7 +26,7 @@ data class Entry( /** * Value indicating that the habit is not applicable for this timestamp. */ - const val SKIP = 3 + const val SKIP = -3 /** * Value indicating that the user has performed the habit at this timestamp. diff --git a/uhabits-core/src/jvmMain/java/org/isoron/uhabits/core/ui/screens/habits/show/views/HistoryCard.kt b/uhabits-core/src/jvmMain/java/org/isoron/uhabits/core/ui/screens/habits/show/views/HistoryCard.kt index bd201e0c5..563da0403 100644 --- a/uhabits-core/src/jvmMain/java/org/isoron/uhabits/core/ui/screens/habits/show/views/HistoryCard.kt +++ b/uhabits-core/src/jvmMain/java/org/isoron/uhabits/core/ui/screens/habits/show/views/HistoryCard.kt @@ -60,19 +60,34 @@ class HistoryCardPresenter( val timestamp = Timestamp.fromLocalDate(date) screen.showFeedback() if (habit.isNumerical) { - val entries = habit.computedEntries - val oldValue = entries.get(timestamp).value - screen.showNumberPicker(oldValue / 1000.0, habit.unit) { newValue: Double -> - val thousands = (newValue * 1000).roundToInt() - commandRunner.run( - CreateRepetitionCommand( - habitList, - habit, - timestamp, - thousands, - ), - ) - } +// val entries = habit.computedEntries +// val oldValue = entries.get(timestamp).value +// screen.showNumberPicker(oldValue / 1000.0, habit.unit) { newValue: Double -> +// val thousands = (newValue * 1000).roundToInt() +// commandRunner.run( +// CreateRepetitionCommand( +// habitList, +// habit, +// timestamp, +// thousands, +// ), +// ) +// } + + val currentValue = habit.computedEntries.get(timestamp).value + val nextValue = Entry.nextToggleValue( + value = currentValue, + isSkipEnabled = preferences.isSkipEnabled, + areQuestionMarksEnabled = preferences.areQuestionMarksEnabled + ) + commandRunner.run( + CreateRepetitionCommand( + habitList, + habit, + timestamp, + nextValue, + ), + ) } else { val currentValue = habit.computedEntries.get(timestamp).value val nextValue = Entry.nextToggleValue( @@ -105,12 +120,25 @@ class HistoryCardPresenter( val oldest = habit.computedEntries.getKnown().lastOrNull()?.timestamp ?: today val entries = habit.computedEntries.getByInterval(oldest, today) val series = if (habit.isNumerical) { +// entries.map { +// Entry(it.timestamp, max(0, it.value)) +// }.map { +// when (it.value) { +// 0 -> HistoryChart.Square.OFF +// else -> HistoryChart.Square.ON +// } +// } entries.map { - Entry(it.timestamp, max(0, it.value)) - }.map { - when (it.value) { - 0 -> HistoryChart.Square.OFF - else -> HistoryChart.Square.ON + when { + it.value == SKIP -> { + HistoryChart.Square.HATCHED + } + it.value > 0 -> { + HistoryChart.Square.ON + } + else -> { + HistoryChart.Square.OFF + } } } } else {