From 6a384b03e97fc3b6f37bb05c353c1e75882db257 Mon Sep 17 00:00:00 2001 From: Jean-Luc Makiola Date: Sat, 14 Nov 2026 02:33:38 +0100 Subject: [PATCH] refactor(#514): one firing-reminders view for the editor and the import prompt --- .../data/calendar/AllDayReminderEncoding.kt | 4 ++-- .../calendula/ui/edit/EventEditScreen.kt | 13 ++----------- .../calendula/ui/edit/EventEditViewModel.kt | 13 +++++++++++-- 3 files changed, 15 insertions(+), 15 deletions(-) diff --git a/app/src/main/java/de/jeanlucmakiola/calendula/data/calendar/AllDayReminderEncoding.kt b/app/src/main/java/de/jeanlucmakiola/calendula/data/calendar/AllDayReminderEncoding.kt index 7d7c025f..5d88d4f6 100644 --- a/app/src/main/java/de/jeanlucmakiola/calendula/data/calendar/AllDayReminderEncoding.kt +++ b/app/src/main/java/de/jeanlucmakiola/calendula/data/calendar/AllDayReminderEncoding.kt @@ -47,7 +47,7 @@ internal fun toProviderAllDayMinutes( ): Int { if (semanticMinutes == MINUTES_DEFAULT) return semanticMinutes val utcMidnight = startDate.atStartOfDay(ZoneOffset.UTC).toInstant().toEpochMilli() - val fire = startDate.minusDays((wholeDayLeadMinutes(semanticMinutes) / MINUTES_PER_DAY).toLong()) + val fire = startDate.minusDays((semanticMinutes / MINUTES_PER_DAY).toLong()) .atTime(LocalTime.of(timeOfDayMinutes / 60, timeOfDayMinutes % 60)) .atZone(zone).toInstant().toEpochMilli() val raw = ((utcMidnight - fire) / MILLIS_PER_MINUTE).toInt() @@ -56,7 +56,7 @@ internal fun toProviderAllDayMinutes( /** * A lead time as the whole days an all-day reminder actually fires at: the - * sub-day part is dropped, the same truncation [toProviderAllDayMinutes] applies. + * sub-day part is dropped, matching [toProviderAllDayMinutes]'s day count. * [MINUTES_DEFAULT] passes through. */ internal fun wholeDayLeadMinutes(minutes: Int): Int = 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 c9ac7869..eda33ebb 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,7 +166,6 @@ 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.data.calendar.wholeDayLeadTimes import de.jeanlucmakiola.calendula.ui.common.customReminderUnits import de.jeanlucmakiola.calendula.ui.common.customReminderPlaceholder import de.jeanlucmakiola.calendula.ui.common.splitsSubDay @@ -878,7 +877,7 @@ private fun EventEditContent( OptionalFormSection(visible = EventFormField.Reminders in state.visibleFields) { Spacer(Modifier.height(gap)) RemindersSection( - reminders = form.shownReminders(), + reminders = form.firingReminders(), onRemove = viewModel::removeReminder, onAdd = { sheet = EditSheet.Reminder }, ) @@ -1283,14 +1282,6 @@ private fun LocationCard( } } -/** - * Reminders as they fire: an all-day event fires on whole days, so a sub-day lead - * time kept from the timed form shows as its day. The form keeps the raw values, - * so switching all-day off again restores them. - */ -private fun EventForm.shownReminders(): List = - if (isAllDay) wholeDayLeadTimes(reminders) else reminders - /** * A grouped list like guests: each reminder is its own tonal card with * connected corners, the last row being "Add reminder". @@ -1501,7 +1492,7 @@ private fun EditSheetHost( } EditSheet.Reminder -> ReminderPickerDialog( isAllDay = form.isAllDay, - alreadyChosen = form.shownReminders(), + alreadyChosen = form.firingReminders(), onSelect = { minutes -> viewModel.addReminder(minutes) onClose() diff --git a/app/src/main/java/de/jeanlucmakiola/calendula/ui/edit/EventEditViewModel.kt b/app/src/main/java/de/jeanlucmakiola/calendula/ui/edit/EventEditViewModel.kt index 85a61253..041642a2 100644 --- a/app/src/main/java/de/jeanlucmakiola/calendula/ui/edit/EventEditViewModel.kt +++ b/app/src/main/java/de/jeanlucmakiola/calendula/ui/edit/EventEditViewModel.kt @@ -8,6 +8,7 @@ import dagger.hilt.android.lifecycle.HiltViewModel import de.jeanlucmakiola.calendula.data.calendar.CalendarRepository import de.jeanlucmakiola.calendula.data.calendar.NoSuchEventException import de.jeanlucmakiola.calendula.data.calendar.wholeDayLeadMinutes +import de.jeanlucmakiola.calendula.data.calendar.wholeDayLeadTimes import de.jeanlucmakiola.calendula.data.ics.IcsExporter import de.jeanlucmakiola.calendula.data.prefs.CalendarPrefs import de.jeanlucmakiola.calendula.data.prefs.SettingsPrefs @@ -537,9 +538,9 @@ class EventEditViewModel @Inject constructor( if (opened != session) return@launch val current = _form.value ?: return@launch if (_editTarget.value != null) return@launch - if (default.isEmpty() || default == current.reminders) return@launch + if (default.isEmpty() || default == current.firingReminders()) return@launch _importReminderPrompt.value = ImportReminderPrompt( - currentReminderCount = current.reminders.size, + currentReminderCount = current.firingReminders().size, defaultReminders = default, ) } @@ -962,3 +963,11 @@ class EventEditViewModel @Inject constructor( _form.value = _form.value?.let(block) } } + +/** + * Reminders as they fire: an all-day event fires on whole days, so a sub-day lead + * time kept from the timed form reads as its day. The form keeps the raw values, + * so switching all-day off again restores them. + */ +internal fun EventForm.firingReminders(): List = + if (isAllDay) wholeDayLeadTimes(reminders) else reminders