refactor(#365): one rule for reminder grouping and preset choice

This commit is contained in:
makiolaj committed 2026-11-13 21:26:18 +01:00
1 parent 2269c2648b
commit d05af5d765
5 files changed
+17 -8

No files matched your search

@@ -128,7 +128,7 @@ fun ReminderDefaultPicker(
Spacer(Modifier.height(24.dp))
GroupedLeadTimeRows(
minutes = rows,
splitSubDay = presets.any { it in 1 until ReminderUnit.Days.minutesFactor },
splitSubDay = splitsSubDay(presets),
row = { minute, position ->
val checked = minute in selectedMinutes
GroupedRow(
@@ -23,8 +23,11 @@ val ALLDAY_REMINDER_PRESETS = listOf(0) + DAY_SCALE_PRESETS
fun reminderPresets(isAllDay: Boolean): List<Int> =
if (isAllDay) ALLDAY_REMINDER_PRESETS else REMINDER_PRESETS
/** 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 }
/**
* Sorts lead times and, when [splitSubDay], splits them into a sub-day group and
* Sorts lead times and, when [splitSubDay] (see [splitsSubDay]), splits them into a sub-day group and
* a day-scale group so a long picker list reads as two connected sections.
* Empty groups are dropped.
*/
@@ -166,6 +166,7 @@ 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.splitsSubDay
import de.jeanlucmakiola.calendula.ui.common.GroupedLeadTimeRows
import de.jeanlucmakiola.calendula.ui.common.TimePickerAlert
import de.jeanlucmakiola.floret.reminders.ReminderUnit
@@ -1608,9 +1609,10 @@ private fun ReminderPickerDialog(
},
) {
if (!customMode) {
val presets = reminderPresets(isAllDay)
GroupedLeadTimeRows(
minutes = reminderPresets(isAllDay).filterNot { it in alreadyChosen },
splitSubDay = !isAllDay,
minutes = presets.filterNot { it in alreadyChosen },
splitSubDay = splitsSubDay(presets),
row = { minutes, position ->
GroupedRow(
title = reminderLeadTimeLabel(minutes),
@@ -31,10 +31,8 @@ import androidx.lifecycle.Lifecycle
import androidx.lifecycle.LifecycleEventObserver
import androidx.lifecycle.compose.LocalLifecycleOwner
import de.jeanlucmakiola.calendula.R
import de.jeanlucmakiola.calendula.ui.common.ALLDAY_REMINDER_PRESETS
import de.jeanlucmakiola.calendula.ui.common.CalendarColorChip
import de.jeanlucmakiola.calendula.ui.common.DurationPicker
import de.jeanlucmakiola.calendula.ui.common.REMINDER_PRESETS
import de.jeanlucmakiola.calendula.ui.common.ReminderDefaultPicker
import de.jeanlucmakiola.calendula.ui.common.TimePickerAlert
import de.jeanlucmakiola.calendula.ui.common.durationLabel
@@ -246,7 +244,7 @@ internal fun NotificationsScreen(
if (showDefaultReminder) {
ReminderDefaultPicker(
title = stringResource(R.string.settings_default_reminder),
presets = REMINDER_PRESETS,
presets = reminderPresets(isAllDay = false),
selected = state.defaultReminderMinutes.toReminderChoice(),
allowInherit = false,
onSelect = { viewModel.setDefaultReminderMinutes(it.minutesOrEmpty()) },
@@ -256,7 +254,7 @@ internal fun NotificationsScreen(
if (showAllDayReminder) {
ReminderDefaultPicker(
title = stringResource(R.string.settings_default_reminder_allday),
presets = ALLDAY_REMINDER_PRESETS,
presets = reminderPresets(isAllDay = true),
selected = state.defaultAllDayReminderMinutes.toReminderChoice(),
allowInherit = false,
onSelect = { viewModel.setDefaultAllDayReminderMinutes(it.minutesOrEmpty()) },
@@ -30,6 +30,12 @@ class ReminderPresetsTest {
.containsExactly(listOf(0, 10, 45), listOf(1_440, 2_880)).inOrder()
}
@Test
fun `only the timed list splits`() {
assertThat(splitsSubDay(REMINDER_PRESETS)).isTrue()
assertThat(splitsSubDay(ALLDAY_REMINDER_PRESETS)).isFalse()
}
@Test
fun `unsplit list is one sorted group`() {
assertThat(groupReminderLeadTimes(listOf(2_880, 0, 30), splitSubDay = false))