show habit desc on recording popup

pull/2195/head
zenador 2 months ago
parent a9acbd6cab
commit 72a36c6d81

@ -43,6 +43,24 @@ class CheckmarkDialog : AppCompatDialogFragment() {
val prefs = appComponent.preferences val prefs = appComponent.preferences
val view = CheckmarkPopupBinding.inflate(LayoutInflater.from(context)) val view = CheckmarkPopupBinding.inflate(LayoutInflater.from(context))
val color = requireArguments().getInt("color") 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 { arrayOf(view.yesBtn, view.skipBtn).forEach {
it.setTextColor(color) it.setTextColor(color)
} }

@ -36,6 +36,24 @@ class NumberDialog : AppCompatDialogFragment() {
val appComponent = (requireActivity().application as HabitsApplication).component val appComponent = (requireActivity().application as HabitsApplication).component
val prefs = appComponent.preferences val prefs = appComponent.preferences
view = CheckmarkPopupBinding.inflate(LayoutInflater.from(context)) 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 { arrayOf(view.yesBtn).forEach {
it.setTextColor(requireArguments().getInt("color")) it.setTextColor(requireArguments().getInt("color"))
} }

@ -270,13 +270,15 @@ class ListHabitsScreen
override fun showNumberPopup( override fun showNumberPopup(
value: Double, value: Double,
notes: String, notes: String,
callback: ListHabitsBehavior.NumberPickerCallback callback: ListHabitsBehavior.NumberPickerCallback,
habit: Habit?
) { ) {
val fm = (context as AppCompatActivity).supportFragmentManager val fm = (context as AppCompatActivity).supportFragmentManager
val dialog = NumberDialog() val dialog = NumberDialog()
dialog.arguments = Bundle().apply { dialog.arguments = Bundle().apply {
putDouble("value", value) putDouble("value", value)
putString("notes", notes) putString("notes", notes)
habit?.id?.let { putLong("habitId", it) }
} }
dialog.onToggle = { v, n -> callback.onNumberPicked(v, n) } dialog.onToggle = { v, n -> callback.onNumberPicked(v, n) }
dialog.dismissCurrentAndShow(fm, "numberDialog") dialog.dismissCurrentAndShow(fm, "numberDialog")
@ -286,7 +288,8 @@ class ListHabitsScreen
selectedValue: Int, selectedValue: Int,
notes: String, notes: String,
color: PaletteColor, color: PaletteColor,
callback: ListHabitsBehavior.CheckMarkDialogCallback callback: ListHabitsBehavior.CheckMarkDialogCallback,
habit: Habit?
) { ) {
val theme = rootView.get().currentTheme() val theme = rootView.get().currentTheme()
val fm = (context as AppCompatActivity).supportFragmentManager val fm = (context as AppCompatActivity).supportFragmentManager
@ -295,6 +298,7 @@ class ListHabitsScreen
putInt("color", theme.color(color).toInt()) putInt("color", theme.color(color).toInt())
putInt("value", selectedValue) putInt("value", selectedValue)
putString("notes", notes) putString("notes", notes)
habit?.id?.let { putLong("habitId", it) }
} }
dialog.onToggle = { v, n -> callback.onNotesSaved(v, n) } dialog.onToggle = { v, n -> callback.onNotesSaved(v, n) }
dialog.dismissCurrentAndShow(fm, "checkmarkDialog") dialog.dismissCurrentAndShow(fm, "checkmarkDialog")

@ -174,12 +174,14 @@ class ShowHabitActivity : AppCompatActivity(), CommandRunner.Listener {
override fun showNumberPopup( override fun showNumberPopup(
value: Double, value: Double,
notes: String, notes: String,
callback: ListHabitsBehavior.NumberPickerCallback callback: ListHabitsBehavior.NumberPickerCallback,
habit: Habit?
) { ) {
val dialog = NumberDialog() val dialog = NumberDialog()
dialog.arguments = Bundle().apply { dialog.arguments = Bundle().apply {
putDouble("value", value) putDouble("value", value)
putString("notes", notes) putString("notes", notes)
putLong("habitId", habit?.id ?: -1)
} }
dialog.onToggle = { v, n -> callback.onNumberPicked(v, n) } dialog.onToggle = { v, n -> callback.onNumberPicked(v, n) }
dialog.dismissCurrentAndShow(supportFragmentManager, "numberDialog") dialog.dismissCurrentAndShow(supportFragmentManager, "numberDialog")
@ -189,7 +191,8 @@ class ShowHabitActivity : AppCompatActivity(), CommandRunner.Listener {
selectedValue: Int, selectedValue: Int,
notes: String, notes: String,
color: PaletteColor, color: PaletteColor,
callback: ListHabitsBehavior.CheckMarkDialogCallback callback: ListHabitsBehavior.CheckMarkDialogCallback,
habit: Habit?
) { ) {
val theme = view.currentTheme() val theme = view.currentTheme()
val dialog = CheckmarkDialog() val dialog = CheckmarkDialog()
@ -197,6 +200,7 @@ class ShowHabitActivity : AppCompatActivity(), CommandRunner.Listener {
putInt("color", theme.color(color).toInt()) putInt("color", theme.color(color).toInt())
putInt("value", selectedValue) putInt("value", selectedValue)
putString("notes", notes) putString("notes", notes)
putLong("habitId", habit?.id ?: -1)
} }
dialog.onToggle = { v, n -> callback.onNotesSaved(v, n) } dialog.onToggle = { v, n -> callback.onNotesSaved(v, n) }
dialog.dismissCurrentAndShow(supportFragmentManager, "checkmarkDialog") dialog.dismissCurrentAndShow(supportFragmentManager, "checkmarkDialog")

@ -30,6 +30,17 @@
app:divider="@drawable/checkmark_dialog_divider" app:divider="@drawable/checkmark_dialog_divider"
app:showDividers="middle"> app:showDividers="middle">
<androidx.appcompat.widget.AppCompatTextView
android:id="@+id/habitDescription"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:background="@color/transparent"
android:gravity="center"
android:padding="4dp"
android:textStyle="italic"
android:textSize="@dimen/smallTextSize" />
<androidx.appcompat.widget.AppCompatEditText <androidx.appcompat.widget.AppCompatEditText
android:id="@+id/notes" android:id="@+id/notes"
android:layout_width="match_parent" android:layout_width="match_parent"

@ -55,7 +55,7 @@ open class ListHabitsBehavior @Inject constructor(
val entry = habit.computedEntries.get(timestamp!!) val entry = habit.computedEntries.get(timestamp!!)
if (habit.type == HabitType.NUMERICAL) { if (habit.type == HabitType.NUMERICAL) {
val oldValue = entry.value.toDouble() / 1000 val oldValue = entry.value.toDouble() / 1000
screen.showNumberPopup(oldValue, entry.notes) { newValue: Double, newNotes: String -> screen.showNumberPopup(oldValue, entry.notes, { newValue: Double, newNotes: String ->
val value = (newValue * 1000).roundToInt() val value = (newValue * 1000).roundToInt()
if (newValue != oldValue) { if (newValue != oldValue) {
if ( if (
@ -66,16 +66,18 @@ open class ListHabitsBehavior @Inject constructor(
} }
} }
commandRunner.run(CreateRepetitionCommand(habitList, habit, timestamp, value, newNotes)) commandRunner.run(CreateRepetitionCommand(habitList, habit, timestamp, value, newNotes))
} }, habit)
} else { } else {
screen.showCheckmarkPopup( screen.showCheckmarkPopup(
entry.value, entry.value,
entry.notes, entry.notes,
habit.color habit.color,
) { newValue: Int, newNotes: String -> { newValue: Int, newNotes: String ->
if (newValue != entry.value && newValue == YES_MANUAL) screen.showConfetti(habit.color, x, y) if (newValue != entry.value && newValue == YES_MANUAL) screen.showConfetti(habit.color, x, y)
commandRunner.run(CreateRepetitionCommand(habitList, habit, timestamp, newValue, newNotes)) commandRunner.run(CreateRepetitionCommand(habitList, habit, timestamp, newValue, newNotes))
} },
habit
)
} }
} }
@ -179,13 +181,15 @@ open class ListHabitsBehavior @Inject constructor(
fun showNumberPopup( fun showNumberPopup(
value: Double, value: Double,
notes: String, notes: String,
callback: NumberPickerCallback callback: NumberPickerCallback,
habit: Habit? = null
) )
fun showCheckmarkPopup( fun showCheckmarkPopup(
selectedValue: Int, selectedValue: Int,
notes: String, notes: String,
color: PaletteColor, color: PaletteColor,
callback: CheckMarkDialogCallback callback: CheckMarkDialogCallback,
habit: Habit? = null
) )
fun showSendBugReportToDeveloperScreen(log: String) fun showSendBugReportToDeveloperScreen(log: String)
fun showSendFileScreen(filename: String) fun showSendFileScreen(filename: String)

@ -97,8 +97,8 @@ class HistoryCardPresenter(
screen.showCheckmarkPopup( screen.showCheckmarkPopup(
entry.value, entry.value,
entry.notes, entry.notes,
habit.color habit.color,
) { newValue, newNotes -> { newValue, newNotes ->
commandRunner.run( commandRunner.run(
CreateRepetitionCommand( CreateRepetitionCommand(
habitList, habitList,
@ -108,7 +108,9 @@ class HistoryCardPresenter(
newNotes newNotes
) )
) )
} },
habit
)
} }
private fun toggle(timestamp: Timestamp) { private fun toggle(timestamp: Timestamp) {
@ -134,8 +136,8 @@ class HistoryCardPresenter(
val oldValue = entry.value val oldValue = entry.value
screen.showNumberPopup( screen.showNumberPopup(
value = oldValue / 1000.0, value = oldValue / 1000.0,
notes = entry.notes notes = entry.notes,
) { newValue: Double, newNotes: String -> { newValue: Double, newNotes: String ->
val thousands = (newValue * 1000).roundToInt() val thousands = (newValue * 1000).roundToInt()
commandRunner.run( commandRunner.run(
CreateRepetitionCommand( CreateRepetitionCommand(
@ -146,7 +148,9 @@ class HistoryCardPresenter(
newNotes newNotes
) )
) )
} },
habit
)
} }
fun onClickEditButton() { fun onClickEditButton() {
@ -207,13 +211,15 @@ class HistoryCardPresenter(
fun showNumberPopup( fun showNumberPopup(
value: Double, value: Double,
notes: String, notes: String,
callback: ListHabitsBehavior.NumberPickerCallback callback: ListHabitsBehavior.NumberPickerCallback,
habit: Habit? = null
) )
fun showCheckmarkPopup( fun showCheckmarkPopup(
selectedValue: Int, selectedValue: Int,
notes: String, notes: String,
color: PaletteColor, color: PaletteColor,
callback: ListHabitsBehavior.CheckMarkDialogCallback callback: ListHabitsBehavior.CheckMarkDialogCallback,
habit: Habit? = null
) )
} }
} }

@ -82,7 +82,8 @@ class ListHabitsBehaviorTest : BaseUnitTest() {
verify(screen).showNumberPopup( verify(screen).showNumberPopup(
eq(0.1), eq(0.1),
eq(""), eq(""),
picker.capture() picker.capture(),
eq(habit2)
) )
picker.lastValue.onNumberPicked(100.0, "") picker.lastValue.onNumberPicked(100.0, "")
val today = getTodayWithOffset() val today = getTodayWithOffset()

Loading…
Cancel
Save