mirror of
https://github.com/iSoron/uhabits.git
synced 2025-12-06 01:08:50 -06:00
improve numerical dialog design
This commit is contained in:
@@ -20,6 +20,7 @@ package org.isoron.uhabits.core.models
|
||||
|
||||
import org.isoron.platform.time.LocalDate
|
||||
import org.isoron.uhabits.core.utils.DateFormats.Companion.getCSVDateFormat
|
||||
import org.isoron.uhabits.core.utils.DateFormats.Companion.getDialogDateFormat
|
||||
import org.isoron.uhabits.core.utils.DateUtils
|
||||
import org.isoron.uhabits.core.utils.DateUtils.Companion.getStartOfTodayCalendar
|
||||
import org.isoron.uhabits.core.utils.DateUtils.Companion.truncate
|
||||
@@ -81,6 +82,10 @@ data class Timestamp(var unixTime: Long) : Comparable<Timestamp> {
|
||||
return day
|
||||
}
|
||||
|
||||
fun toDialogDateString(): String {
|
||||
return getDialogDateFormat().format(Date(unixTime))
|
||||
}
|
||||
|
||||
override fun toString(): String {
|
||||
return getCSVDateFormat().format(Date(unixTime))
|
||||
}
|
||||
|
||||
@@ -54,7 +54,8 @@ open class ListHabitsBehavior @Inject constructor(
|
||||
screen.showNumberPicker(
|
||||
oldValue / 1000,
|
||||
habit.unit,
|
||||
entry.notes
|
||||
entry.notes,
|
||||
timestamp.toDialogDateString(),
|
||||
) { newValue: Double, newNotes: String, ->
|
||||
val value = (newValue * 1000).roundToInt()
|
||||
commandRunner.run(CreateRepetitionCommand(habitList, habit, timestamp, value, newNotes))
|
||||
@@ -159,6 +160,7 @@ open class ListHabitsBehavior @Inject constructor(
|
||||
value: Double,
|
||||
unit: String,
|
||||
notes: String,
|
||||
dateString: String,
|
||||
callback: NumberPickerCallback
|
||||
)
|
||||
fun showCheckmarkDialog(
|
||||
|
||||
@@ -110,7 +110,8 @@ class HistoryCardPresenter(
|
||||
screen.showNumberPicker(
|
||||
oldValue / 1000.0,
|
||||
habit.unit,
|
||||
entry.notes
|
||||
entry.notes,
|
||||
timestamp.toDialogDateString(),
|
||||
) { newValue: Double, newNotes: String ->
|
||||
val thousands = (newValue * 1000).roundToInt()
|
||||
commandRunner.run(
|
||||
@@ -195,6 +196,7 @@ class HistoryCardPresenter(
|
||||
value: Double,
|
||||
unit: String,
|
||||
notes: String,
|
||||
dateString: String,
|
||||
callback: ListHabitsBehavior.NumberPickerCallback,
|
||||
)
|
||||
fun showCheckmarkDialog(
|
||||
|
||||
@@ -41,5 +41,8 @@ class DateFormats {
|
||||
|
||||
@JvmStatic fun getCSVDateFormat(): SimpleDateFormat =
|
||||
fromSkeleton("yyyy-MM-dd", Locale.US)
|
||||
|
||||
@JvmStatic fun getDialogDateFormat(): SimpleDateFormat =
|
||||
fromSkeleton("MMM dd, yyyy", Locale.US)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -79,7 +79,7 @@ class ListHabitsBehaviorTest : BaseUnitTest() {
|
||||
@Test
|
||||
fun testOnEdit() {
|
||||
behavior.onEdit(habit2, getToday())
|
||||
verify(screen).showNumberPicker(eq(0.1), eq("miles"), eq(""), picker.capture())
|
||||
verify(screen).showNumberPicker(eq(0.1), eq("miles"), eq(""), eq("Jan 25, 2015"), picker.capture())
|
||||
picker.lastValue.onNumberPicked(100.0, "")
|
||||
val today = getTodayWithOffset()
|
||||
assertThat(habit2.computedEntries.get(today).value, equalTo(100000))
|
||||
|
||||
Reference in New Issue
Block a user