refactor(#365): drop picker-side day rounding, placeholder follows the selected unit
This commit is contained in:
1 parent
08d2452c51
commit
1e2ed15e82
4 files changed
+10
-21
No files matched your search
@@ -213,7 +213,7 @@ private fun CustomReminderEditor(
|
||||
amountText = amountText,
|
||||
onAmountChange = onAmountChange,
|
||||
unitLabels = units.map { stringResource(reminderUnitLabel(it)) },
|
||||
placeholder = customReminderPlaceholder(units),
|
||||
placeholder = customReminderPlaceholder(unit),
|
||||
selectedUnit = units.indexOf(unit),
|
||||
onUnitChange = { onUnitChange(units[it]) },
|
||||
preview = amount?.let { reminderLeadTimeLabel(it * unit.minutesFactor) }
|
||||
|
||||
@@ -30,16 +30,9 @@ fun reminderPresets(isAllDay: Boolean): List<Int> =
|
||||
fun customReminderUnits(isAllDay: Boolean): List<ReminderUnit> =
|
||||
if (isAllDay) listOf(ReminderUnit.Days, ReminderUnit.Weeks) else ReminderUnit.entries
|
||||
|
||||
/** Placeholder for the Custom amount field: a typical amount in the first unit offered. */
|
||||
fun customReminderPlaceholder(units: List<ReminderUnit>): String =
|
||||
if (ReminderUnit.Minutes in units) "10" else "1"
|
||||
|
||||
/**
|
||||
* Lead times an all-day event already covers, as the whole days they save as, so
|
||||
* a sub-day value carried over from a timed event blocks the day it lands on.
|
||||
*/
|
||||
fun reminderDaysTaken(alreadyChosen: List<Int>, isAllDay: Boolean): List<Int> =
|
||||
if (isAllDay) alreadyChosen.map { if (it == MINUTES_DEFAULT) it else it / DAY * DAY } else alreadyChosen
|
||||
/** Placeholder for the Custom amount field: a typical amount in [unit]. */
|
||||
fun customReminderPlaceholder(unit: ReminderUnit): String =
|
||||
if (unit == ReminderUnit.Minutes) "10" else "1"
|
||||
|
||||
/** Whether a picker over [presets] splits its rows into sub-day and day-scale groups. */
|
||||
fun splitsSubDay(presets: Collection<Int>): Boolean = presets.any { it in 1 until DAY }
|
||||
|
||||
@@ -168,7 +168,6 @@ import de.jeanlucmakiola.floret.components.positionOf
|
||||
import de.jeanlucmakiola.calendula.ui.common.reminderPresets
|
||||
import de.jeanlucmakiola.calendula.ui.common.customReminderUnits
|
||||
import de.jeanlucmakiola.calendula.ui.common.customReminderPlaceholder
|
||||
import de.jeanlucmakiola.calendula.ui.common.reminderDaysTaken
|
||||
import de.jeanlucmakiola.calendula.ui.common.splitsSubDay
|
||||
import de.jeanlucmakiola.calendula.ui.common.GroupedLeadTimeRows
|
||||
import de.jeanlucmakiola.calendula.ui.common.TimePickerAlert
|
||||
@@ -1595,7 +1594,6 @@ private fun ReminderPickerDialog(
|
||||
val units = customReminderUnits(isAllDay)
|
||||
var pickedUnit by rememberSaveable { mutableStateOf(units.first()) }
|
||||
val unit = pickedUnit.takeIf { it in units } ?: units.first()
|
||||
val taken = reminderDaysTaken(alreadyChosen, isAllDay)
|
||||
val customMinutes = amountText.toIntOrNull()
|
||||
?.takeIf { it in 1..999 }
|
||||
?.let { it * unit.minutesFactor }
|
||||
@@ -1607,7 +1605,7 @@ private fun ReminderPickerDialog(
|
||||
// The quick-pick list adds on tap; only the custom step needs Add.
|
||||
if (customMode) {
|
||||
TextButton(
|
||||
enabled = customMinutes != null && customMinutes !in taken,
|
||||
enabled = customMinutes != null && customMinutes !in alreadyChosen,
|
||||
onClick = { customMinutes?.let(onSelect) },
|
||||
) { Text(stringResource(R.string.event_edit_add)) }
|
||||
}
|
||||
@@ -1616,7 +1614,7 @@ private fun ReminderPickerDialog(
|
||||
if (!customMode) {
|
||||
val presets = reminderPresets(isAllDay)
|
||||
GroupedLeadTimeRows(
|
||||
minutes = presets.filterNot { it in taken },
|
||||
minutes = presets.filterNot { it in alreadyChosen },
|
||||
splitSubDay = splitsSubDay(presets),
|
||||
row = { minutes, position ->
|
||||
GroupedRow(
|
||||
@@ -1641,7 +1639,7 @@ private fun ReminderPickerDialog(
|
||||
DialogAmountField(
|
||||
value = amountText,
|
||||
onValueChange = { amountText = it },
|
||||
placeholder = customReminderPlaceholder(units),
|
||||
placeholder = customReminderPlaceholder(unit),
|
||||
)
|
||||
Spacer(Modifier.width(12.dp))
|
||||
DialogUnitDropdown(
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
package de.jeanlucmakiola.calendula.ui.common
|
||||
|
||||
import com.google.common.truth.Truth.assertThat
|
||||
import de.jeanlucmakiola.calendula.data.calendar.MINUTES_DEFAULT
|
||||
import de.jeanlucmakiola.floret.reminders.ReminderUnit
|
||||
import org.junit.jupiter.api.Test
|
||||
|
||||
@@ -40,10 +39,9 @@ class ReminderPresetsTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `sub-day reminders on an all-day event block the day they save as`() {
|
||||
assertThat(reminderDaysTaken(listOf(10, 1_500), isAllDay = true)).containsExactly(0, 1_440)
|
||||
assertThat(reminderDaysTaken(listOf(MINUTES_DEFAULT), isAllDay = true)).containsExactly(MINUTES_DEFAULT)
|
||||
assertThat(reminderDaysTaken(listOf(10), isAllDay = false)).containsExactly(10)
|
||||
fun `custom placeholder fits the selected unit`() {
|
||||
assertThat(customReminderPlaceholder(ReminderUnit.Minutes)).isEqualTo("10")
|
||||
assertThat(customReminderPlaceholder(ReminderUnit.Days)).isEqualTo("1")
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
Reference in new issue
Block a user