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 bf1544ba..e708c00d 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 @@ -111,12 +111,10 @@ class DailyDigestNotifier @Inject constructor( } } - /** Whether the app's notifications or the summary's channel are switched off in the system. */ - fun isBlocked(): Boolean { - val manager = context.getSystemService(NotificationManager::class.java) - if (!manager.areNotificationsEnabled()) return true - return manager.getNotificationChannel(CHANNEL_ID)?.importance == NotificationManager.IMPORTANCE_NONE - } + /** Whether the summary's own channel is switched off in the system settings. */ + fun isChannelOff(): Boolean = + context.getSystemService(NotificationManager::class.java) + .getNotificationChannel(CHANNEL_ID)?.importance == NotificationManager.IMPORTANCE_NONE /** Withdraw the summary showing, if any. */ fun cancel() { diff --git a/app/src/main/java/de/jeanlucmakiola/calendula/data/reminders/ReminderScanner.kt b/app/src/main/java/de/jeanlucmakiola/calendula/data/reminders/ReminderScanner.kt index 1c72dfae..7a1e7f24 100644 --- a/app/src/main/java/de/jeanlucmakiola/calendula/data/reminders/ReminderScanner.kt +++ b/app/src/main/java/de/jeanlucmakiola/calendula/data/reminders/ReminderScanner.kt @@ -163,7 +163,8 @@ class ReminderScanner @Inject constructor( lastListedDay = listed, ) val day = schedule.dueDay - if (day != null && notifier.canPost()) { + // A blocked channel would swallow it; the day stays owed until allowed. + if (day != null && notifier.canPost() && !digestNotifier.isChannelOff()) { // A failed summary must not cost the event reminders this pass owes. try { // A day either side: all-day occurrences sit at UTC midnight, which diff --git a/app/src/main/java/de/jeanlucmakiola/calendula/ui/settings/NotificationSettings.kt b/app/src/main/java/de/jeanlucmakiola/calendula/ui/settings/NotificationSettings.kt index 240d3c01..21f9de42 100644 --- a/app/src/main/java/de/jeanlucmakiola/calendula/ui/settings/NotificationSettings.kt +++ b/app/src/main/java/de/jeanlucmakiola/calendula/ui/settings/NotificationSettings.kt @@ -140,6 +140,8 @@ internal fun NotificationsScreen( viewModel.dismissNotificationCategoryHint() scope.launch { viewModel.syncReminderChannels() + // The summary's category too, so it is on the list to check. + if (state.dailyDigest.enabled) viewModel.digestChannel() context.openNotificationSettings() } }, @@ -201,12 +203,15 @@ internal fun NotificationsScreen( Spacer(Modifier.height(24.dp)) DailyDigestRows( digest = state.dailyDigest, - blocked = digestBlocked, + blocked = channelStatus.appBlocked || digestBlocked, onEnable = toggleDigest, onPickDay = { showDigestDay = true }, onPickTime = { showDigestTime = true }, onOpenSound = { - scope.launch { viewModel.digestChannel()?.let { context.openNotificationSettings(it) } } + // The app's own page while the app is blocked: the channel's would be greyed out. + scope.launch { + context.openNotificationSettings(viewModel.digestChannel().takeUnless { channelStatus.appBlocked }) + } }, ) @@ -261,6 +266,10 @@ internal fun NotificationsScreen( GroupedRow( title = calendar.displayName.orUnnamed(), summary = when { + // Still in the summary, so only its reminders are off. + !notifying && state.dailyDigest.enabled && + calendar.id !in state.dailyDigest.excludedCalendarIds -> + stringResource(R.string.settings_calendar_reminders_off) !notifying -> stringResource(R.string.settings_calendar_notifications_off) blocked -> stringResource(R.string.settings_notifications_blocked) else -> null 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 fe528362..f94853ee 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 @@ -398,13 +398,16 @@ class SettingsViewModel @Inject constructor( channelStatusJob?.cancel() channelStatusJob = viewModelScope.launch { onChannels { status(calendarIds) }?.let { _channelStatus.value = it } - _digestBlocked.value = withContext(io) { runCatching { digestNotifier.isBlocked() }.getOrDefault(false) } + _digestBlocked.value = withContext(io) { runCatching { digestNotifier.isChannelOff() }.getOrDefault(false) } } } private val _digestBlocked = MutableStateFlow(false) - /** Whether the system blocks the daily summary's channel (#459); refreshed with [refreshChannelStatus]. */ + /** + * Whether the daily summary's own channel is switched off (#459); the app-wide + * block is [channelStatus]'s. Refreshed with [refreshChannelStatus]. + */ val digestBlocked: StateFlow = _digestBlocked.asStateFlow() fun dismissNotificationCategoryHint() = save { dismissNotificationCategoryHint() } @@ -467,6 +470,12 @@ class SettingsViewModel @Inject constructor( fun setDailyDigestEnabled(enabled: Boolean) { viewModelScope.launch { prefs.setDailyDigestEnabled(enabled) + // Created now, so a phone that starts new categories switched off + // shows it blocked here rather than dropping the first summary. + if (enabled) { + digestChannel() + _digestBlocked.value = withContext(io) { runCatching { digestNotifier.isChannelOff() }.getOrDefault(false) } + } // 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() diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 6bd92618..045a6bc1 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -735,6 +735,7 @@ Notifications Notify at this calendar\'s reminder times Notifications off + Reminders off Notification sound Sound, vibration and pop-ups for each calendar, in system settings Blocked in system settings diff --git a/docs/ARCHITECTURE.md b/docs/ARCHITECTURE.md index 6e46c8b8..5899e507 100644 --- a/docs/ARCHITECTURE.md +++ b/docs/ARCHITECTURE.md @@ -447,6 +447,11 @@ event reminders of the same pass, and a failing reminder pass still arms a retry 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. +Its channel's blocked state is read separately (`DailyDigestNotifier.isChannelOff`, +with the app-wide block from `ReminderChannels.status`); while it is off the +scan neither posts nor records the day, so allowing it brings the summary back. +The channel is created when the summary is switched on, so a phone that starts +new categories off shows it blocked in settings before the first summary. 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.