From 72a36c6d818c2b680188f867e59a0d890bf646fb Mon Sep 17 00:00:00 2001 From: zenador Date: Mon, 4 Aug 2025 01:42:06 +0800 Subject: [PATCH] show habit desc on recording popup --- .../common/dialogs/CheckmarkDialog.kt | 18 ++++++ .../activities/common/dialogs/NumberDialog.kt | 18 ++++++ .../habits/list/ListHabitsScreen.kt | 8 ++- .../habits/show/ShowHabitActivity.kt | 8 ++- .../src/main/res/layout/checkmark_popup.xml | 11 ++++ .../screens/habits/list/ListHabitsBehavior.kt | 22 +++++--- .../screens/habits/show/views/HistoryCard.kt | 56 ++++++++++--------- .../habits/list/ListHabitsBehaviorTest.kt | 3 +- 8 files changed, 105 insertions(+), 39 deletions(-) diff --git a/uhabits-android/src/main/java/org/isoron/uhabits/activities/common/dialogs/CheckmarkDialog.kt b/uhabits-android/src/main/java/org/isoron/uhabits/activities/common/dialogs/CheckmarkDialog.kt index 5bebfb08d..88e271a75 100644 --- a/uhabits-android/src/main/java/org/isoron/uhabits/activities/common/dialogs/CheckmarkDialog.kt +++ b/uhabits-android/src/main/java/org/isoron/uhabits/activities/common/dialogs/CheckmarkDialog.kt @@ -43,6 +43,24 @@ class CheckmarkDialog : AppCompatDialogFragment() { val prefs = appComponent.preferences val view = CheckmarkPopupBinding.inflate(LayoutInflater.from(context)) val color = requireArguments().getInt("color") + + // Get the habit ID and load description + val habitId = requireArguments().getLong("habitId", -1) + if (habitId != -1L) { + val habit = appComponent.habitList.getById(habitId) + habit?.let { + val description = it.question.trim() + if (description.isNotEmpty()) { + view.habitDescription.text = description + view.habitDescription.visibility = VISIBLE + } else { + view.habitDescription.visibility = GONE + } + } + } else { + view.habitDescription.visibility = GONE + } + arrayOf(view.yesBtn, view.skipBtn).forEach { it.setTextColor(color) } diff --git a/uhabits-android/src/main/java/org/isoron/uhabits/activities/common/dialogs/NumberDialog.kt b/uhabits-android/src/main/java/org/isoron/uhabits/activities/common/dialogs/NumberDialog.kt index 4025bc2e6..5eb66e226 100644 --- a/uhabits-android/src/main/java/org/isoron/uhabits/activities/common/dialogs/NumberDialog.kt +++ b/uhabits-android/src/main/java/org/isoron/uhabits/activities/common/dialogs/NumberDialog.kt @@ -36,6 +36,24 @@ class NumberDialog : AppCompatDialogFragment() { val appComponent = (requireActivity().application as HabitsApplication).component val prefs = appComponent.preferences view = CheckmarkPopupBinding.inflate(LayoutInflater.from(context)) + + // Get the habit ID and load description + val habitId = requireArguments().getLong("habitId", -1) + if (habitId != -1L) { + val habit = appComponent.habitList.getById(habitId) + habit?.let { + val description = it.question.trim() + if (description.isNotEmpty()) { + view.habitDescription.text = description + view.habitDescription.visibility = View.VISIBLE + } else { + view.habitDescription.visibility = View.GONE + } + } + } else { + view.habitDescription.visibility = View.GONE + } + arrayOf(view.yesBtn).forEach { it.setTextColor(requireArguments().getInt("color")) } diff --git a/uhabits-android/src/main/java/org/isoron/uhabits/activities/habits/list/ListHabitsScreen.kt b/uhabits-android/src/main/java/org/isoron/uhabits/activities/habits/list/ListHabitsScreen.kt index 14e53298b..576fd7a18 100644 --- a/uhabits-android/src/main/java/org/isoron/uhabits/activities/habits/list/ListHabitsScreen.kt +++ b/uhabits-android/src/main/java/org/isoron/uhabits/activities/habits/list/ListHabitsScreen.kt @@ -270,13 +270,15 @@ class ListHabitsScreen override fun showNumberPopup( value: Double, notes: String, - callback: ListHabitsBehavior.NumberPickerCallback + callback: ListHabitsBehavior.NumberPickerCallback, + habit: Habit? ) { val fm = (context as AppCompatActivity).supportFragmentManager val dialog = NumberDialog() dialog.arguments = Bundle().apply { putDouble("value", value) putString("notes", notes) + habit?.id?.let { putLong("habitId", it) } } dialog.onToggle = { v, n -> callback.onNumberPicked(v, n) } dialog.dismissCurrentAndShow(fm, "numberDialog") @@ -286,7 +288,8 @@ class ListHabitsScreen selectedValue: Int, notes: String, color: PaletteColor, - callback: ListHabitsBehavior.CheckMarkDialogCallback + callback: ListHabitsBehavior.CheckMarkDialogCallback, + habit: Habit? ) { val theme = rootView.get().currentTheme() val fm = (context as AppCompatActivity).supportFragmentManager @@ -295,6 +298,7 @@ class ListHabitsScreen putInt("color", theme.color(color).toInt()) putInt("value", selectedValue) putString("notes", notes) + habit?.id?.let { putLong("habitId", it) } } dialog.onToggle = { v, n -> callback.onNotesSaved(v, n) } dialog.dismissCurrentAndShow(fm, "checkmarkDialog") diff --git a/uhabits-android/src/main/java/org/isoron/uhabits/activities/habits/show/ShowHabitActivity.kt b/uhabits-android/src/main/java/org/isoron/uhabits/activities/habits/show/ShowHabitActivity.kt index fb7e3382c..022e79d4a 100644 --- a/uhabits-android/src/main/java/org/isoron/uhabits/activities/habits/show/ShowHabitActivity.kt +++ b/uhabits-android/src/main/java/org/isoron/uhabits/activities/habits/show/ShowHabitActivity.kt @@ -174,12 +174,14 @@ class ShowHabitActivity : AppCompatActivity(), CommandRunner.Listener { override fun showNumberPopup( value: Double, notes: String, - callback: ListHabitsBehavior.NumberPickerCallback + callback: ListHabitsBehavior.NumberPickerCallback, + habit: Habit? ) { val dialog = NumberDialog() dialog.arguments = Bundle().apply { putDouble("value", value) putString("notes", notes) + putLong("habitId", habit?.id ?: -1) } dialog.onToggle = { v, n -> callback.onNumberPicked(v, n) } dialog.dismissCurrentAndShow(supportFragmentManager, "numberDialog") @@ -189,7 +191,8 @@ class ShowHabitActivity : AppCompatActivity(), CommandRunner.Listener { selectedValue: Int, notes: String, color: PaletteColor, - callback: ListHabitsBehavior.CheckMarkDialogCallback + callback: ListHabitsBehavior.CheckMarkDialogCallback, + habit: Habit? ) { val theme = view.currentTheme() val dialog = CheckmarkDialog() @@ -197,6 +200,7 @@ class ShowHabitActivity : AppCompatActivity(), CommandRunner.Listener { putInt("color", theme.color(color).toInt()) putInt("value", selectedValue) putString("notes", notes) + putLong("habitId", habit?.id ?: -1) } dialog.onToggle = { v, n -> callback.onNotesSaved(v, n) } dialog.dismissCurrentAndShow(supportFragmentManager, "checkmarkDialog") diff --git a/uhabits-android/src/main/res/layout/checkmark_popup.xml b/uhabits-android/src/main/res/layout/checkmark_popup.xml index 7661735f4..9d3d8f5e5 100644 --- a/uhabits-android/src/main/res/layout/checkmark_popup.xml +++ b/uhabits-android/src/main/res/layout/checkmark_popup.xml @@ -29,6 +29,17 @@ android:orientation="vertical" app:divider="@drawable/checkmark_dialog_divider" app:showDividers="middle"> + + + screen.showNumberPopup(oldValue, entry.notes, { newValue: Double, newNotes: String -> val value = (newValue * 1000).roundToInt() if (newValue != oldValue) { if ( @@ -66,16 +66,18 @@ open class ListHabitsBehavior @Inject constructor( } } commandRunner.run(CreateRepetitionCommand(habitList, habit, timestamp, value, newNotes)) - } + }, habit) } else { screen.showCheckmarkPopup( entry.value, entry.notes, - habit.color - ) { newValue: Int, newNotes: String -> - if (newValue != entry.value && newValue == YES_MANUAL) screen.showConfetti(habit.color, x, y) - commandRunner.run(CreateRepetitionCommand(habitList, habit, timestamp, newValue, newNotes)) - } + habit.color, + { newValue: Int, newNotes: String -> + if (newValue != entry.value && newValue == YES_MANUAL) screen.showConfetti(habit.color, x, y) + commandRunner.run(CreateRepetitionCommand(habitList, habit, timestamp, newValue, newNotes)) + }, + habit + ) } } @@ -179,13 +181,15 @@ open class ListHabitsBehavior @Inject constructor( fun showNumberPopup( value: Double, notes: String, - callback: NumberPickerCallback + callback: NumberPickerCallback, + habit: Habit? = null ) fun showCheckmarkPopup( selectedValue: Int, notes: String, color: PaletteColor, - callback: CheckMarkDialogCallback + callback: CheckMarkDialogCallback, + habit: Habit? = null ) fun showSendBugReportToDeveloperScreen(log: String) fun showSendFileScreen(filename: String) 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 cfbe5e0f3..f5cf5be4f 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 @@ -97,18 +97,20 @@ class HistoryCardPresenter( screen.showCheckmarkPopup( entry.value, entry.notes, - habit.color - ) { newValue, newNotes -> - commandRunner.run( - CreateRepetitionCommand( - habitList, - habit, - timestamp, - newValue, - newNotes + habit.color, + { newValue, newNotes -> + commandRunner.run( + CreateRepetitionCommand( + habitList, + habit, + timestamp, + newValue, + newNotes + ) ) - ) - } + }, + habit + ) } private fun toggle(timestamp: Timestamp) { @@ -134,19 +136,21 @@ class HistoryCardPresenter( val oldValue = entry.value screen.showNumberPopup( value = oldValue / 1000.0, - notes = entry.notes - ) { newValue: Double, newNotes: String -> - val thousands = (newValue * 1000).roundToInt() - commandRunner.run( - CreateRepetitionCommand( - habitList, - habit, - timestamp, - thousands, - newNotes + notes = entry.notes, + { newValue: Double, newNotes: String -> + val thousands = (newValue * 1000).roundToInt() + commandRunner.run( + CreateRepetitionCommand( + habitList, + habit, + timestamp, + thousands, + newNotes + ) ) - ) - } + }, + habit + ) } fun onClickEditButton() { @@ -207,13 +211,15 @@ class HistoryCardPresenter( fun showNumberPopup( value: Double, notes: String, - callback: ListHabitsBehavior.NumberPickerCallback + callback: ListHabitsBehavior.NumberPickerCallback, + habit: Habit? = null ) fun showCheckmarkPopup( selectedValue: Int, notes: String, color: PaletteColor, - callback: ListHabitsBehavior.CheckMarkDialogCallback + callback: ListHabitsBehavior.CheckMarkDialogCallback, + habit: Habit? = null ) } } diff --git a/uhabits-core/src/jvmTest/java/org/isoron/uhabits/core/ui/screens/habits/list/ListHabitsBehaviorTest.kt b/uhabits-core/src/jvmTest/java/org/isoron/uhabits/core/ui/screens/habits/list/ListHabitsBehaviorTest.kt index 19f49a8a4..e58bddca3 100644 --- a/uhabits-core/src/jvmTest/java/org/isoron/uhabits/core/ui/screens/habits/list/ListHabitsBehaviorTest.kt +++ b/uhabits-core/src/jvmTest/java/org/isoron/uhabits/core/ui/screens/habits/list/ListHabitsBehaviorTest.kt @@ -82,7 +82,8 @@ class ListHabitsBehaviorTest : BaseUnitTest() { verify(screen).showNumberPopup( eq(0.1), eq(""), - picker.capture() + picker.capture(), + eq(habit2) ) picker.lastValue.onNumberPicked(100.0, "") val today = getTodayWithOffset()