fix(#459): review round 4 — dated summary that times out, mode switch lists afresh, cancel after the scan, no lead doubling a set-time reminder

This commit is contained in:
makiolaj committed 2026-11-13 18:37:22 +01:00
1 parent c353ac8072
commit 13e4908c1e
6 files changed
+44 -10

No files matched your search

@@ -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")
@@ -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 {
@@ -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) {
@@ -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) }
+2
View File
@@ -768,6 +768,8 @@
<item quantity="one">%1$s: %2$d event</item>
<item quantity="other">%1$s: %2$d events</item>
</plurals>
<!-- %1$s is "Today" or "Tomorrow", %2$s a short date, e.g. "Fri, 14 Nov". -->
<string name="digest_day_relative">%1$s, %2$s</string>
<!-- One event in the summary: %1$s its time ("09:00 – 10:00" or "All day"), %2$s its title. -->
<string name="digest_line">%1$s · %2$s</string>
<plurals name="digest_more">
+3 -1
View File
@@ -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.