diff --git a/app/src/main/java/de/jeanlucmakiola/calendula/ui/common/Picker.kt b/app/src/main/java/de/jeanlucmakiola/calendula/ui/common/Picker.kt index cd13a282..15cb7422 100644 --- a/app/src/main/java/de/jeanlucmakiola/calendula/ui/common/Picker.kt +++ b/app/src/main/java/de/jeanlucmakiola/calendula/ui/common/Picker.kt @@ -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) } diff --git a/app/src/main/java/de/jeanlucmakiola/calendula/ui/common/ReminderFormatting.kt b/app/src/main/java/de/jeanlucmakiola/calendula/ui/common/ReminderFormatting.kt index 078e5990..bfddb2ca 100644 --- a/app/src/main/java/de/jeanlucmakiola/calendula/ui/common/ReminderFormatting.kt +++ b/app/src/main/java/de/jeanlucmakiola/calendula/ui/common/ReminderFormatting.kt @@ -30,16 +30,9 @@ fun reminderPresets(isAllDay: Boolean): List = fun customReminderUnits(isAllDay: Boolean): List = 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): 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, isAllDay: Boolean): List = - 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): Boolean = presets.any { it in 1 until DAY } diff --git a/app/src/main/java/de/jeanlucmakiola/calendula/ui/edit/EventEditScreen.kt b/app/src/main/java/de/jeanlucmakiola/calendula/ui/edit/EventEditScreen.kt index 92627e46..4e58a91d 100644 --- a/app/src/main/java/de/jeanlucmakiola/calendula/ui/edit/EventEditScreen.kt +++ b/app/src/main/java/de/jeanlucmakiola/calendula/ui/edit/EventEditScreen.kt @@ -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( diff --git a/app/src/test/java/de/jeanlucmakiola/calendula/ui/common/ReminderPresetsTest.kt b/app/src/test/java/de/jeanlucmakiola/calendula/ui/common/ReminderPresetsTest.kt index feee4d9c..f3a2363f 100644 --- a/app/src/test/java/de/jeanlucmakiola/calendula/ui/common/ReminderPresetsTest.kt +++ b/app/src/test/java/de/jeanlucmakiola/calendula/ui/common/ReminderPresetsTest.kt @@ -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