From 2dbc4c49b7d6d536ac2979b089a343869df70fc1 Mon Sep 17 00:00:00 2001 From: Jean-Luc Makiola Date: Sat, 14 Nov 2026 00:49:32 +0100 Subject: [PATCH] fix(#365): all-day custom reminders offer only days and weeks --- .../calendula/ui/common/Picker.kt | 21 ++++++++++++------- .../calendula/ui/common/ReminderFormatting.kt | 7 +++++++ .../calendula/ui/edit/EventEditScreen.kt | 10 +++++---- .../ui/settings/NotificationSettings.kt | 7 +++---- .../ui/settings/SpecialDatesSettings.kt | 3 +-- .../ui/common/ReminderPresetsTest.kt | 8 +++++++ 6 files changed, 38 insertions(+), 18 deletions(-) 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 49502175..9b560995 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 @@ -39,8 +39,8 @@ import kotlinx.datetime.toLocalDateTime import kotlin.time.Clock /** - * Reminder-default picker, full-screen and **multi-select**: each [presets] - * lead time (plus any chosen custom value) is a checkbox row that toggles + * Reminder-default picker, full-screen and **multi-select**: each preset + * lead time ([reminderPresets] for [isAllDay]) (plus any chosen custom value) is a checkbox row that toggles * independently, so a default can carry several reminders ("1 week before" *and* * "on the day"). Two exclusive checkmark rows sit above the list: an explicit * "No reminder" (both pickers, so the empty state stays visible and reachable) @@ -60,7 +60,7 @@ import kotlin.time.Clock @Composable fun ReminderDefaultPicker( title: String, - presets: List, + isAllDay: Boolean, selected: ReminderOverride, allowInherit: Boolean, onSelect: (ReminderOverride) -> Unit, @@ -88,6 +88,8 @@ fun ReminderDefaultPicker( // Custom (non-preset) lead times seen this session, so unchecking one keeps // its row (unchecked) until the picker closes instead of vanishing mid-tap, // which would strand a hand-entered value with no way to re-check it. + val presets = reminderPresets(isAllDay) + val units = customReminderUnits(isAllDay) val seenCustom = remember { mutableSetOf() } seenCustom += selectedMinutes.filter { it !in presets } // Presets plus every custom value seen this session, each as its own row. @@ -95,7 +97,8 @@ fun ReminderDefaultPicker( var customExpanded by rememberSaveable { mutableStateOf(false) } var amountText by rememberSaveable { mutableStateOf("") } - var unit by rememberSaveable { mutableStateOf(ReminderUnit.Minutes) } + var pickedUnit by rememberSaveable { mutableStateOf(units.first()) } + val unit = pickedUnit.takeIf { it in units } ?: units.first() fun apply(override: ReminderOverride) { userEdited = true @@ -150,8 +153,9 @@ fun ReminderDefaultPicker( CustomReminderEditor( amountText = amountText, onAmountChange = { amountText = it }, + units = units, unit = unit, - onUnitChange = { unit = it }, + onUnitChange = { pickedUnit = it }, onConfirm = { minutes -> emit(selectedMinutes + minutes) amountText = "" @@ -199,6 +203,7 @@ internal fun GroupedLeadTimeRows( private fun CustomReminderEditor( amountText: String, onAmountChange: (String) -> Unit, + units: List, unit: ReminderUnit, onUnitChange: (ReminderUnit) -> Unit, onConfirm: (Int) -> Unit, @@ -207,9 +212,9 @@ private fun CustomReminderEditor( CustomAmountEditor( amountText = amountText, onAmountChange = onAmountChange, - unitLabels = ReminderUnit.entries.map { stringResource(reminderUnitLabel(it)) }, - selectedUnit = unit.ordinal, - onUnitChange = { onUnitChange(ReminderUnit.entries[it]) }, + unitLabels = units.map { stringResource(reminderUnitLabel(it)) }, + selectedUnit = units.indexOf(unit), + onUnitChange = { onUnitChange(units[it]) }, preview = amount?.let { reminderLeadTimeLabel(it * unit.minutesFactor) } ?: stringResource(R.string.reminder_custom_amount), setLabel = stringResource(R.string.reminder_custom_set), 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 4692088c..d166be23 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 @@ -23,6 +23,13 @@ val ALLDAY_REMINDER_PRESETS = listOf(0) + DAY_SCALE_PRESETS fun reminderPresets(isAllDay: Boolean): List = if (isAllDay) ALLDAY_REMINDER_PRESETS else REMINDER_PRESETS +/** + * Units the Custom step offers. All-day reminders fire on whole days at the + * all-day reminder time, so minutes and hours would be dropped on save. + */ +fun customReminderUnits(isAllDay: Boolean): List = + if (isAllDay) listOf(ReminderUnit.Days, ReminderUnit.Weeks) else ReminderUnit.entries + /** 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 54cc2d8a..70dc77ba 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 @@ -166,10 +166,10 @@ import de.jeanlucmakiola.floret.components.Position import de.jeanlucmakiola.floret.components.groupedShape as floretGroupedShape 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.splitsSubDay import de.jeanlucmakiola.calendula.ui.common.GroupedLeadTimeRows import de.jeanlucmakiola.calendula.ui.common.TimePickerAlert -import de.jeanlucmakiola.floret.reminders.ReminderUnit import de.jeanlucmakiola.floret.locale.currentLocale import de.jeanlucmakiola.calendula.ui.common.LocalUse24HourFormat import de.jeanlucmakiola.calendula.ui.common.formatTimeOfDay @@ -1590,7 +1590,9 @@ private fun ReminderPickerDialog( ) { var customMode by rememberSaveable { mutableStateOf(false) } var amountText by rememberSaveable { mutableStateOf("") } - var unit by rememberSaveable { mutableStateOf(ReminderUnit.Minutes) } + val units = customReminderUnits(isAllDay) + var pickedUnit by rememberSaveable { mutableStateOf(units.first()) } + val unit = pickedUnit.takeIf { it in units } ?: units.first() val customMinutes = amountText.toIntOrNull() ?.takeIf { it in 1..999 } ?.let { it * unit.minutesFactor } @@ -1641,8 +1643,8 @@ private fun ReminderPickerDialog( Spacer(Modifier.width(12.dp)) DialogUnitDropdown( label = stringResource(reminderUnitLabel(unit)), - entries = ReminderUnit.entries.map { stringResource(reminderUnitLabel(it)) }, - onPick = { unit = ReminderUnit.entries[it] }, + entries = units.map { stringResource(reminderUnitLabel(it)) }, + onPick = { pickedUnit = units[it] }, ) } } diff --git a/app/src/main/java/de/jeanlucmakiola/calendula/ui/settings/NotificationSettings.kt b/app/src/main/java/de/jeanlucmakiola/calendula/ui/settings/NotificationSettings.kt index 47cdd39e..ff468ba2 100644 --- a/app/src/main/java/de/jeanlucmakiola/calendula/ui/settings/NotificationSettings.kt +++ b/app/src/main/java/de/jeanlucmakiola/calendula/ui/settings/NotificationSettings.kt @@ -37,7 +37,6 @@ import de.jeanlucmakiola.calendula.ui.common.ReminderDefaultPicker import de.jeanlucmakiola.calendula.ui.common.TimePickerAlert import de.jeanlucmakiola.calendula.ui.common.durationLabel import de.jeanlucmakiola.calendula.ui.common.orUnnamed -import de.jeanlucmakiola.calendula.ui.common.reminderPresets import de.jeanlucmakiola.floret.android.hasPermission import de.jeanlucmakiola.floret.components.CollapsingScaffold import de.jeanlucmakiola.floret.components.ExpandIcon @@ -244,7 +243,7 @@ internal fun NotificationsScreen( if (showDefaultReminder) { ReminderDefaultPicker( title = stringResource(R.string.settings_default_reminder), - presets = reminderPresets(isAllDay = false), + isAllDay = false, selected = state.defaultReminderMinutes.toReminderChoice(), allowInherit = false, onSelect = { viewModel.setDefaultReminderMinutes(it.minutesOrEmpty()) }, @@ -254,7 +253,7 @@ internal fun NotificationsScreen( if (showAllDayReminder) { ReminderDefaultPicker( title = stringResource(R.string.settings_default_reminder_allday), - presets = reminderPresets(isAllDay = true), + isAllDay = true, selected = state.defaultAllDayReminderMinutes.toReminderChoice(), allowInherit = false, onSelect = { viewModel.setDefaultAllDayReminderMinutes(it.minutesOrEmpty()) }, @@ -289,7 +288,7 @@ internal fun NotificationsScreen( R.string.settings_default_reminder }, ), - presets = reminderPresets(target.isAllDay), + isAllDay = target.isAllDay, selected = map.reminderOverrideFor(target.calendarId), allowInherit = true, onSelect = { diff --git a/app/src/main/java/de/jeanlucmakiola/calendula/ui/settings/SpecialDatesSettings.kt b/app/src/main/java/de/jeanlucmakiola/calendula/ui/settings/SpecialDatesSettings.kt index e57b27ea..33f96d92 100644 --- a/app/src/main/java/de/jeanlucmakiola/calendula/ui/settings/SpecialDatesSettings.kt +++ b/app/src/main/java/de/jeanlucmakiola/calendula/ui/settings/SpecialDatesSettings.kt @@ -29,7 +29,6 @@ import androidx.lifecycle.compose.collectAsStateWithLifecycle import de.jeanlucmakiola.calendula.R import de.jeanlucmakiola.calendula.data.contacts.hasContactsPermission import de.jeanlucmakiola.calendula.domain.contacts.SpecialDateType -import de.jeanlucmakiola.calendula.ui.common.ALLDAY_REMINDER_PRESETS import de.jeanlucmakiola.calendula.ui.common.ReminderDefaultPicker import de.jeanlucmakiola.floret.components.CollapsingScaffold import de.jeanlucmakiola.floret.components.GroupedRow @@ -197,7 +196,7 @@ internal fun SpecialDatesScreen( reminderPickerType?.let { type -> ReminderDefaultPicker( title = stringResource(R.string.settings_special_dates_reminders), - presets = ALLDAY_REMINDER_PRESETS, + isAllDay = true, selected = state.reminderChoices[type] ?: ReminderOverride.None, // Managed calendars own their reminders outright — no "inherit global". allowInherit = false, 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 5db872cc..b5ab133d 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,6 +1,7 @@ package de.jeanlucmakiola.calendula.ui.common import com.google.common.truth.Truth.assertThat +import de.jeanlucmakiola.floret.reminders.ReminderUnit import org.junit.jupiter.api.Test class ReminderPresetsTest { @@ -30,6 +31,13 @@ class ReminderPresetsTest { .containsExactly(listOf(0, 10, 45), listOf(1_440, 2_880)).inOrder() } + @Test + fun `all-day custom offers whole-day units only`() { + assertThat(customReminderUnits(isAllDay = true)) + .containsExactly(ReminderUnit.Days, ReminderUnit.Weeks).inOrder() + assertThat(customReminderUnits(isAllDay = false)).containsExactlyElementsIn(ReminderUnit.entries) + } + @Test fun `only the timed list splits`() { assertThat(splitsSubDay(REMINDER_PRESETS)).isTrue()