From 13e4908c1e3fe4e30edce2a5732720078c964afc Mon Sep 17 00:00:00 2001 From: Jean-Luc Makiola Date: Fri, 13 Nov 2026 18:37:22 +0100 Subject: [PATCH] =?UTF-8?q?fix(#459):=20review=20round=204=20=E2=80=94=20d?= =?UTF-8?q?ated=20summary=20that=20times=20out,=20mode=20switch=20lists=20?= =?UTF-8?q?afresh,=20cancel=20after=20the=20scan,=20no=20lead=20doubling?= =?UTF-8?q?=20a=20set-time=20reminder?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../data/prefs/ReminderStatePrefs.kt | 2 ++ .../data/reminders/DailyDigestNotifier.kt | 19 +++++++++++++---- .../calendula/ui/edit/EventEditViewModel.kt | 6 +++++- .../ui/settings/SettingsViewModel.kt | 21 +++++++++++++++---- app/src/main/res/values/strings.xml | 2 ++ docs/ARCHITECTURE.md | 4 +++- 6 files changed, 44 insertions(+), 10 deletions(-) diff --git a/app/src/main/java/de/jeanlucmakiola/calendula/data/prefs/ReminderStatePrefs.kt b/app/src/main/java/de/jeanlucmakiola/calendula/data/prefs/ReminderStatePrefs.kt index 80f1504b..7c989bd5 100644 --- a/app/src/main/java/de/jeanlucmakiola/calendula/data/prefs/ReminderStatePrefs.kt +++ b/app/src/main/java/de/jeanlucmakiola/calendula/data/prefs/ReminderStatePrefs.kt @@ -39,6 +39,8 @@ class ReminderStatePrefs @Inject constructor( suspend fun setLastDigestDay(day: LocalDate) = prefs.set(LAST_DIGEST_DAY, day.toString()) + suspend fun clearLastDigestDay() = prefs.set(LAST_DIGEST_DAY, null) + private companion object { val LAST_SCAN = nullableLongPref("reminder_last_scan_millis") val LAST_DIGEST_DAY = nullableStringPref("reminder_last_digest_day") diff --git a/app/src/main/java/de/jeanlucmakiola/calendula/data/reminders/DailyDigestNotifier.kt b/app/src/main/java/de/jeanlucmakiola/calendula/data/reminders/DailyDigestNotifier.kt index 6579bf63..1755ec1e 100644 --- a/app/src/main/java/de/jeanlucmakiola/calendula/data/reminders/DailyDigestNotifier.kt +++ b/app/src/main/java/de/jeanlucmakiola/calendula/data/reminders/DailyDigestNotifier.kt @@ -21,7 +21,6 @@ import java.time.DayOfWeek import java.time.LocalDate import java.time.ZoneId import java.time.format.DateTimeFormatter -import java.time.format.FormatStyle import java.util.Locale import javax.inject.Inject import javax.inject.Singleton @@ -53,10 +52,17 @@ class DailyDigestNotifier @Inject constructor( .is24Hour(android.text.format.DateFormat.is24HourFormat(context)) val today = LocalDate.now(zone) val firstDayOfWeek = DayOfWeek.of(settingsPrefs.weekStart.first().resolveFirstDay(locale).isoDayNumber) + // The date rides along: the summary stays up into the day it lists, + // when "Tomorrow" alone would point at the wrong one. + val date = DateTimeFormatter.ofPattern( + android.text.format.DateFormat.getBestDateTimePattern(locale, "EEEdMMM"), + locale, + ).format(day) val dayLabel = when (day) { - today -> context.getString(R.string.reminder_day_today) - today.plusDays(1) -> context.getString(R.string.reminder_day_tomorrow) - else -> DateTimeFormatter.ofLocalizedDate(FormatStyle.MEDIUM).withLocale(locale).format(day) + today -> context.getString(R.string.digest_day_relative, context.getString(R.string.reminder_day_today), date) + today.plusDays(1) -> + context.getString(R.string.digest_day_relative, context.getString(R.string.reminder_day_tomorrow), date) + else -> date } val allDay = context.getString(R.string.event_detail_all_day) val lines = listed.map { entry -> @@ -91,6 +97,11 @@ class DailyDigestNotifier @Inject constructor( .setStyle(style) .setCategory(NotificationCompat.CATEGORY_REMINDER) .setAutoCancel(true) + // Gone once its day is over; "Tomorrow" would read wrong by then anyway. + .setTimeoutAfter( + (day.plusDays(1).atStartOfDay(zone).toInstant().toEpochMilli() - System.currentTimeMillis()) + .coerceAtLeast(1L), + ) .setContentIntent(openDay(day)) .build() try { 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 6792ba3b..08a6aeac 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 @@ -718,7 +718,11 @@ class EventEditViewModel @Inject constructor( fun addReminder(minutes: Int) { _remindersTouched.value = true - edit { it.copy(reminders = (it.reminders + minutes).distinct().sorted()) } + edit { + // A lead firing with a set-time reminder would be one row once saved. + if (minutes in it.fixedReminderOffsets(zoneSource.current())) it + else it.copy(reminders = (it.reminders + minutes).distinct().sorted()) + } } fun removeReminder(minutes: Int) { diff --git a/app/src/main/java/de/jeanlucmakiola/calendula/ui/settings/SettingsViewModel.kt b/app/src/main/java/de/jeanlucmakiola/calendula/ui/settings/SettingsViewModel.kt index df141e92..3ae763cf 100644 --- a/app/src/main/java/de/jeanlucmakiola/calendula/ui/settings/SettingsViewModel.kt +++ b/app/src/main/java/de/jeanlucmakiola/calendula/ui/settings/SettingsViewModel.kt @@ -21,6 +21,7 @@ import de.jeanlucmakiola.floret.android.stateWhileSubscribed import de.jeanlucmakiola.floret.di.IoDispatcher import de.jeanlucmakiola.calendula.data.prefs.FixedTimeOverride import de.jeanlucmakiola.calendula.data.prefs.dailyDigest +import de.jeanlucmakiola.calendula.data.prefs.ReminderStatePrefs import de.jeanlucmakiola.calendula.data.reminders.DailyDigestNotifier import de.jeanlucmakiola.calendula.domain.reminders.DigestDay import de.jeanlucmakiola.calendula.domain.reminders.FixedTimeReminder @@ -77,6 +78,7 @@ class SettingsViewModel @Inject constructor( private val reminderScanner: ReminderScanner, private val reminderChannels: ReminderChannels, private val digestNotifier: DailyDigestNotifier, + private val reminderState: ReminderStatePrefs, @IoDispatcher private val io: CoroutineDispatcher, @ApplicationContext private val appContext: Context, ) : ViewModel() { @@ -418,14 +420,25 @@ class SettingsViewModel @Inject constructor( /** Every summary change re-plans, so the next one is armed for its new moment (#459). */ fun setDailyDigestEnabled(enabled: Boolean) { - saveAndScan { setDailyDigestEnabled(enabled) } - // A summary left showing would go stale with nothing to replace it. - if (!enabled) digestNotifier.cancel() + viewModelScope.launch { + prefs.setDailyDigestEnabled(enabled) + // After the scan, so one already under way can't post past the cancel; + // a summary left showing would go stale with nothing to replace it. + reminderScanner.scan() + if (!enabled) digestNotifier.cancel() + } } fun setDailyDigestTimeMinutes(minutesOfDay: Int) = saveAndScan { setDailyDigestTimeMinutes(minutesOfDay) } - fun setDailyDigestDay(day: DigestDay) = saveAndScan { setDailyDigestDay(day) } + /** A new mode lists afresh: from "tomorrow" to "today", the day just listed comes again. */ + fun setDailyDigestDay(day: DigestDay) { + viewModelScope.launch { + prefs.setDailyDigestDay(day) + reminderState.clearLastDigestDay() + reminderScanner.scan() + } + } fun setCalendarInDailyDigest(calendarId: Long, included: Boolean) = save { setCalendarInDailyDigest(calendarId, included) } diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index ec68a4c1..aac2bfc1 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -768,6 +768,8 @@ %1$s: %2$d event %1$s: %2$d events + + %1$s, %2$s %1$s · %2$s diff --git a/docs/ARCHITECTURE.md b/docs/ARCHITECTURE.md index f19dc21c..2128021e 100644 --- a/docs/ARCHITECTURE.md +++ b/docs/ARCHITECTURE.md @@ -442,7 +442,9 @@ time picked the same evening lists it twice, and changing the switch, time or day stamps `dailyDigestArmedAt`, so a moment that passed before the change is not owed by it. A failing summary is logged and skipped; it never costs the event reminders of the same pass, and a failing reminder pass still arms a retry -and the summary's next moment. +and the summary's next moment. Switching between "today's" and "tomorrow's" +events clears the day last listed, so the first summary of the new mode comes. +The notification names its date and times out when that day ends. The per-calendar reminder mute does not apply: a calendar too noisy to ping per event can still belong in the overview, and the summary has its own per-calendar switch next to it.