fix(#365): all-day custom reminders offer only days and weeks

This commit is contained in:
makiolaj committed 2026-11-14 00:49:32 +01:00
1 parent d05af5d765
commit 2dbc4c49b7
6 files changed
+38 -18

No files matched your search

@@ -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<Int>,
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<Int>() }
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<ReminderUnit>,
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),
@@ -23,6 +23,13 @@ val ALLDAY_REMINDER_PRESETS = listOf(0) + DAY_SCALE_PRESETS
fun reminderPresets(isAllDay: Boolean): List<Int> =
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<ReminderUnit> =
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<Int>): Boolean = presets.any { it in 1 until DAY }
@@ -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] },
)
}
}
@@ -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 = {
@@ -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,
@@ -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()