fix(#365): no duplicate day reminders on all-day events, one placeholder rule

This commit is contained in:
makiolaj committed 2026-11-14 01:06:06 +01:00
1 parent 9ed6bbbe8e
commit 126f1d51ef
4 files changed
+24 -4

No files matched your search

@@ -213,7 +213,7 @@ private fun CustomReminderEditor(
amountText = amountText,
onAmountChange = onAmountChange,
unitLabels = units.map { stringResource(reminderUnitLabel(it)) },
placeholder = if (ReminderUnit.Minutes in units) "10" else "1",
placeholder = customReminderPlaceholder(units),
selectedUnit = units.indexOf(unit),
onUnitChange = { onUnitChange(units[it]) },
preview = amount?.let { reminderLeadTimeLabel(it * unit.minutesFactor) }
@@ -30,6 +30,17 @@ 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 { it / DAY * DAY } else alreadyChosen
/** 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 }
@@ -167,6 +167,8 @@ 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.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
@@ -1593,6 +1595,7 @@ 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 }
@@ -1604,7 +1607,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 alreadyChosen,
enabled = customMinutes != null && customMinutes !in taken,
onClick = { customMinutes?.let(onSelect) },
) { Text(stringResource(R.string.event_edit_add)) }
}
@@ -1613,7 +1616,7 @@ private fun ReminderPickerDialog(
if (!customMode) {
val presets = reminderPresets(isAllDay)
GroupedLeadTimeRows(
minutes = presets.filterNot { it in alreadyChosen },
minutes = presets.filterNot { it in taken },
splitSubDay = splitsSubDay(presets),
row = { minutes, position ->
GroupedRow(
@@ -1638,7 +1641,7 @@ private fun ReminderPickerDialog(
DialogAmountField(
value = amountText,
onValueChange = { amountText = it },
placeholder = if (isAllDay) "1" else "10",
placeholder = customReminderPlaceholder(units),
)
Spacer(Modifier.width(12.dp))
DialogUnitDropdown(
@@ -38,6 +38,12 @@ class ReminderPresetsTest {
assertThat(customReminderUnits(isAllDay = false)).containsExactlyElementsIn(ReminderUnit.entries)
}
@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(10), isAllDay = false)).containsExactly(10)
}
@Test
fun `only the timed list splits`() {
assertThat(splitsSubDay(REMINDER_PRESETS)).isTrue()