improve numerical dialog design

This commit is contained in:
Bindu
2021-10-02 11:06:51 -07:00
parent 79e302f922
commit 71f400f587
14 changed files with 163 additions and 58 deletions

View File

@@ -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))
}

View File

@@ -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(

View File

@@ -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(

View File

@@ -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)
}
}

View File

@@ -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))