mirror of
https://github.com/iSoron/uhabits.git
synced 2025-12-07 17:48:52 -06:00
Merge branch 'number-popup' into release/2.1.0
This commit is contained in:
@@ -18,10 +18,8 @@
|
||||
*/
|
||||
package org.isoron.uhabits.core.ui.screens.habits.list
|
||||
|
||||
import org.isoron.platform.gui.ScreenLocation
|
||||
import org.isoron.uhabits.core.commands.CommandRunner
|
||||
import org.isoron.uhabits.core.commands.CreateRepetitionCommand
|
||||
import org.isoron.uhabits.core.models.Frequency
|
||||
import org.isoron.uhabits.core.models.Habit
|
||||
import org.isoron.uhabits.core.models.HabitList
|
||||
import org.isoron.uhabits.core.models.HabitType
|
||||
@@ -50,17 +48,11 @@ open class ListHabitsBehavior @Inject constructor(
|
||||
screen.showHabitScreen(h)
|
||||
}
|
||||
|
||||
fun onEdit(location: ScreenLocation, habit: Habit, timestamp: Timestamp?) {
|
||||
fun onEdit(habit: Habit, timestamp: Timestamp?) {
|
||||
val entry = habit.computedEntries.get(timestamp!!)
|
||||
if (habit.type == HabitType.NUMERICAL) {
|
||||
val oldValue = entry.value.toDouble()
|
||||
screen.showNumberPicker(
|
||||
oldValue / 1000,
|
||||
habit.unit,
|
||||
entry.notes,
|
||||
timestamp.toDialogDateString(),
|
||||
habit.frequency
|
||||
) { newValue: Double, newNotes: String, ->
|
||||
val oldValue = entry.value.toDouble() / 1000
|
||||
screen.showNumberPopup(oldValue, entry.notes) { newValue: Double, newNotes: String ->
|
||||
val value = (newValue * 1000).roundToInt()
|
||||
commandRunner.run(CreateRepetitionCommand(habitList, habit, timestamp, value, newNotes))
|
||||
}
|
||||
@@ -69,7 +61,6 @@ open class ListHabitsBehavior @Inject constructor(
|
||||
entry.value,
|
||||
entry.notes,
|
||||
habit.color,
|
||||
location,
|
||||
) { newValue, newNotes ->
|
||||
commandRunner.run(CreateRepetitionCommand(habitList, habit, timestamp, newValue, newNotes))
|
||||
}
|
||||
@@ -162,19 +153,15 @@ open class ListHabitsBehavior @Inject constructor(
|
||||
fun showHabitScreen(h: Habit)
|
||||
fun showIntroScreen()
|
||||
fun showMessage(m: Message)
|
||||
fun showNumberPicker(
|
||||
fun showNumberPopup(
|
||||
value: Double,
|
||||
unit: String,
|
||||
notes: String,
|
||||
dateString: String,
|
||||
frequency: Frequency,
|
||||
callback: NumberPickerCallback
|
||||
)
|
||||
fun showCheckmarkPopup(
|
||||
selectedValue: Int,
|
||||
notes: String,
|
||||
color: PaletteColor,
|
||||
location: ScreenLocation,
|
||||
callback: CheckMarkDialogCallback
|
||||
)
|
||||
fun showSendBugReportToDeveloperScreen(log: String)
|
||||
|
||||
@@ -19,7 +19,6 @@
|
||||
|
||||
package org.isoron.uhabits.core.ui.screens.habits.show.views
|
||||
|
||||
import org.isoron.platform.gui.ScreenLocation
|
||||
import org.isoron.platform.time.DayOfWeek
|
||||
import org.isoron.platform.time.LocalDate
|
||||
import org.isoron.uhabits.core.commands.CommandRunner
|
||||
@@ -28,7 +27,6 @@ import org.isoron.uhabits.core.models.Entry
|
||||
import org.isoron.uhabits.core.models.Entry.Companion.SKIP
|
||||
import org.isoron.uhabits.core.models.Entry.Companion.YES_AUTO
|
||||
import org.isoron.uhabits.core.models.Entry.Companion.YES_MANUAL
|
||||
import org.isoron.uhabits.core.models.Frequency
|
||||
import org.isoron.uhabits.core.models.Habit
|
||||
import org.isoron.uhabits.core.models.HabitList
|
||||
import org.isoron.uhabits.core.models.NumericalHabitType.AT_LEAST
|
||||
@@ -66,36 +64,35 @@ class HistoryCardPresenter(
|
||||
val screen: Screen,
|
||||
) : OnDateClickedListener {
|
||||
|
||||
override fun onDateLongPress(location: ScreenLocation, date: LocalDate) {
|
||||
override fun onDateLongPress(date: LocalDate) {
|
||||
val timestamp = Timestamp.fromLocalDate(date)
|
||||
screen.showFeedback()
|
||||
if (habit.isNumerical) {
|
||||
showNumberPicker(timestamp)
|
||||
showNumberPopup(timestamp)
|
||||
} else {
|
||||
if (preferences.isShortToggleEnabled) showCheckmarkPopup(location, timestamp)
|
||||
if (preferences.isShortToggleEnabled) showCheckmarkPopup(timestamp)
|
||||
else toggle(timestamp)
|
||||
}
|
||||
}
|
||||
|
||||
override fun onDateShortPress(location: ScreenLocation, date: LocalDate) {
|
||||
override fun onDateShortPress(date: LocalDate) {
|
||||
val timestamp = Timestamp.fromLocalDate(date)
|
||||
screen.showFeedback()
|
||||
if (habit.isNumerical) {
|
||||
showNumberPicker(timestamp)
|
||||
showNumberPopup(timestamp)
|
||||
} else {
|
||||
if (preferences.isShortToggleEnabled) toggle(timestamp)
|
||||
else showCheckmarkPopup(location, timestamp)
|
||||
else showCheckmarkPopup(timestamp)
|
||||
}
|
||||
}
|
||||
|
||||
private fun showCheckmarkPopup(location: ScreenLocation, timestamp: Timestamp) {
|
||||
private fun showCheckmarkPopup(timestamp: Timestamp) {
|
||||
val entry = habit.computedEntries.get(timestamp)
|
||||
screen.showCheckmarkPopup(
|
||||
entry.value,
|
||||
entry.notes,
|
||||
preferences,
|
||||
habit.color,
|
||||
location,
|
||||
) { newValue, newNotes ->
|
||||
commandRunner.run(
|
||||
CreateRepetitionCommand(
|
||||
@@ -127,15 +124,13 @@ class HistoryCardPresenter(
|
||||
)
|
||||
}
|
||||
|
||||
private fun showNumberPicker(timestamp: Timestamp) {
|
||||
private fun showNumberPopup(timestamp: Timestamp) {
|
||||
val entry = habit.computedEntries.get(timestamp)
|
||||
val oldValue = entry.value
|
||||
screen.showNumberPicker(
|
||||
oldValue / 1000.0,
|
||||
habit.unit,
|
||||
entry.notes,
|
||||
timestamp.toDialogDateString(),
|
||||
frequency = habit.frequency
|
||||
screen.showNumberPopup(
|
||||
value = oldValue / 1000.0,
|
||||
notes = entry.notes,
|
||||
preferences = preferences,
|
||||
) { newValue: Double, newNotes: String ->
|
||||
val thousands = (newValue * 1000).roundToInt()
|
||||
commandRunner.run(
|
||||
@@ -205,21 +200,17 @@ class HistoryCardPresenter(
|
||||
interface Screen {
|
||||
fun showHistoryEditorDialog(listener: OnDateClickedListener)
|
||||
fun showFeedback()
|
||||
fun showNumberPicker(
|
||||
fun showNumberPopup(
|
||||
value: Double,
|
||||
unit: String,
|
||||
notes: String,
|
||||
dateString: String,
|
||||
frequency: Frequency,
|
||||
callback: ListHabitsBehavior.NumberPickerCallback
|
||||
preferences: Preferences,
|
||||
callback: ListHabitsBehavior.NumberPickerCallback,
|
||||
)
|
||||
|
||||
fun showCheckmarkPopup(
|
||||
selectedValue: Int,
|
||||
notes: String,
|
||||
preferences: Preferences,
|
||||
color: PaletteColor,
|
||||
location: ScreenLocation,
|
||||
callback: ListHabitsBehavior.CheckMarkDialogCallback,
|
||||
)
|
||||
}
|
||||
|
||||
@@ -22,7 +22,6 @@ package org.isoron.uhabits.core.ui.views
|
||||
import org.isoron.platform.gui.Canvas
|
||||
import org.isoron.platform.gui.Color
|
||||
import org.isoron.platform.gui.DataView
|
||||
import org.isoron.platform.gui.ScreenLocation
|
||||
import org.isoron.platform.gui.TextAlign
|
||||
import org.isoron.platform.time.DayOfWeek
|
||||
import org.isoron.platform.time.LocalDate
|
||||
@@ -34,8 +33,8 @@ import kotlin.math.min
|
||||
import kotlin.math.round
|
||||
|
||||
interface OnDateClickedListener {
|
||||
fun onDateShortPress(location: ScreenLocation, date: LocalDate) {}
|
||||
fun onDateLongPress(location: ScreenLocation, date: LocalDate) {}
|
||||
fun onDateShortPress(date: LocalDate) {}
|
||||
fun onDateLongPress(date: LocalDate) {}
|
||||
}
|
||||
|
||||
class HistoryChart(
|
||||
@@ -91,11 +90,10 @@ class HistoryChart(
|
||||
if (x - padding < 0 || row == 0 || row > 7 || col == nColumns) return
|
||||
val clickedDate = topLeftDate.plus(offset)
|
||||
if (clickedDate.isNewerThan(today)) return
|
||||
val location = ScreenLocation(x, y)
|
||||
if (isLongClick) {
|
||||
onDateClickedListener.onDateLongPress(location, clickedDate)
|
||||
onDateClickedListener.onDateLongPress(clickedDate)
|
||||
} else {
|
||||
onDateClickedListener.onDateShortPress(location, clickedDate)
|
||||
onDateClickedListener.onDateShortPress(clickedDate)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user