From 955dccff2b0528b51056bf8a77eb399b87462e1e Mon Sep 17 00:00:00 2001 From: Jean-Luc Makiola Date: Sat, 14 Nov 2026 02:25:34 +0100 Subject: [PATCH 1/4] feat(#145): show calendars blocked in system settings, one-time Samsung category hint --- .../calendula/data/prefs/SettingsPrefs.kt | 9 +++ .../data/reminders/ReminderChannelPlan.kt | 22 ++++++ .../data/reminders/ReminderChannels.kt | 21 +++++ .../ui/settings/NotificationSettings.kt | 78 ++++++++++++++++++- .../calendula/ui/settings/SettingsUiState.kt | 2 + .../ui/settings/SettingsViewModel.kt | 15 ++++ app/src/main/res/values/strings.xml | 4 + .../data/reminders/ReminderChannelPlanTest.kt | 16 ++++ docs/ARCHITECTURE.md | 4 +- 9 files changed, 166 insertions(+), 5 deletions(-) diff --git a/app/src/main/java/de/jeanlucmakiola/calendula/data/prefs/SettingsPrefs.kt b/app/src/main/java/de/jeanlucmakiola/calendula/data/prefs/SettingsPrefs.kt index bd98b6ab..13e6c7b3 100644 --- a/app/src/main/java/de/jeanlucmakiola/calendula/data/prefs/SettingsPrefs.kt +++ b/app/src/main/java/de/jeanlucmakiola/calendula/data/prefs/SettingsPrefs.kt @@ -167,6 +167,7 @@ class SettingsPrefs @Inject constructor( val perCalendarEventDuration: Flow> = prefs.flow(SettingsKeys.perCalendarEventDuration) val remindersEnabled: Flow = prefs.flow(SettingsKeys.remindersEnabled) val mutedReminderCalendarIds: Flow> = prefs.flow(SettingsKeys.mutedReminderCalendarIds) + val notificationCategoryHintDismissed: Flow = prefs.flow(SettingsKeys.notificationCategoryHintDismissed) val allowColorOnUnsupportedCalendars: Flow = prefs.flow(SettingsKeys.allowColorOnUnsupportedCalendars) val defaultReminderMinutes: Flow> = prefs.flow(SettingsKeys.defaultReminderMinutes) @@ -274,6 +275,8 @@ class SettingsPrefs @Inject constructor( suspend fun setRemindersEnabled(enabled: Boolean) = prefs.set(SettingsKeys.remindersEnabled, enabled) + suspend fun dismissNotificationCategoryHint() = prefs.set(SettingsKeys.notificationCategoryHintDismissed, true) + suspend fun setCalendarRemindersEnabled(calendarId: Long, enabled: Boolean) { prefs.update(SettingsKeys.mutedReminderCalendarIds) { if (enabled) it - calendarId else it + calendarId } } @@ -605,6 +608,12 @@ object SettingsKeys { */ val mutedReminderCalendarIds: Pref> = idSetPref("muted_reminder_calendar_ids") + /** + * Whether the one-time hint that some skins (Samsung) start new notification + * categories switched off has been dismissed (#145). + */ + val notificationCategoryHintDismissed: Pref = booleanPref("notification_category_hint_dismissed", false) + /** * Whether to offer a custom event colour on calendars that publish no colour * palette; synced ones without a palette (some CalDAV) may drop or overwrite diff --git a/app/src/main/java/de/jeanlucmakiola/calendula/data/reminders/ReminderChannelPlan.kt b/app/src/main/java/de/jeanlucmakiola/calendula/data/reminders/ReminderChannelPlan.kt index 1f070222..f75eb262 100644 --- a/app/src/main/java/de/jeanlucmakiola/calendula/data/reminders/ReminderChannelPlan.kt +++ b/app/src/main/java/de/jeanlucmakiola/calendula/data/reminders/ReminderChannelPlan.kt @@ -128,3 +128,25 @@ fun planReminderChannels( } private fun accountGroupId(type: String, name: String): String = "$GROUP_PREFIX$type/$name" + +/** A channel as far as its blocked state goes: switched off itself, and the group it sits in. */ +data class ReminderChannelState(val blocked: Boolean, val groupId: String?) + +/** + * The calendars among [calendarIds] whose reminders the system blocks: all of + * them while the app's notifications are off, otherwise those whose channel, + * or the group it sits in, is switched off. A calendar without a channel yet + * isn't blocked. + */ +fun blockedReminderCalendars( + calendarIds: Collection, + appEnabled: Boolean, + channels: Map, + blockedGroupIds: Set, +): Set { + if (!appEnabled) return calendarIds.toSet() + return calendarIds.filterTo(HashSet()) { id -> + val channel = channels[reminderChannelId(id)] ?: return@filterTo false + channel.blocked || channel.groupId in blockedGroupIds + } +} diff --git a/app/src/main/java/de/jeanlucmakiola/calendula/data/reminders/ReminderChannels.kt b/app/src/main/java/de/jeanlucmakiola/calendula/data/reminders/ReminderChannels.kt index 2f80a55c..95fbfff5 100644 --- a/app/src/main/java/de/jeanlucmakiola/calendula/data/reminders/ReminderChannels.kt +++ b/app/src/main/java/de/jeanlucmakiola/calendula/data/reminders/ReminderChannels.kt @@ -102,6 +102,21 @@ class ReminderChannels @Inject constructor( return id } + /** What the system currently lets through for [calendarIds]' reminders (#145). */ + fun status(calendarIds: Collection): ReminderChannelStatus { + val manager = manager + val appEnabled = manager.areNotificationsEnabled() + val blocked = blockedReminderCalendars( + calendarIds = calendarIds, + appEnabled = appEnabled, + channels = manager.notificationChannels.associate { + it.id to ReminderChannelState(it.importance == NotificationManager.IMPORTANCE_NONE, it.group) + }, + blockedGroupIds = manager.notificationChannelGroups.filter { it.isBlocked }.mapTo(HashSet()) { it.id }, + ) + return ReminderChannelStatus(appBlocked = !appEnabled, blockedCalendarIds = blocked) + } + private fun plan( calendars: List, existing: List, @@ -190,3 +205,9 @@ class ReminderChannels @Inject constructor( const val TAG = "ReminderChannels" } } + +/** Reminder notifications the system blocks, while Calendula would post them. */ +data class ReminderChannelStatus( + val appBlocked: Boolean = false, + val blockedCalendarIds: Set = emptySet(), +) 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 b87b4b9c..85d5b064 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 @@ -9,6 +9,16 @@ import android.provider.Settings import androidx.activity.compose.rememberLauncherForActivityResult import androidx.activity.result.contract.ActivityResultContracts import androidx.compose.animation.AnimatedVisibility +import androidx.compose.foundation.layout.Arrangement +import androidx.compose.foundation.layout.Row +import androidx.compose.foundation.layout.fillMaxWidth +import androidx.compose.material.icons.outlined.Info +import androidx.compose.material3.Text +import androidx.compose.material3.TextButton +import androidx.compose.ui.Alignment +import androidx.lifecycle.compose.LifecycleResumeEffect +import androidx.lifecycle.compose.collectAsStateWithLifecycle +import de.jeanlucmakiola.floret.components.IconInfoCard import androidx.compose.foundation.layout.Column import androidx.compose.foundation.layout.Spacer import androidx.compose.foundation.layout.height @@ -92,8 +102,19 @@ internal fun NotificationsScreen( var calendarSectionExpanded by remember { mutableStateOf(false) } var expandedCalendars by remember { mutableStateOf(emptySet()) } val scope = rememberCoroutineScope() + val channelStatus by viewModel.channelStatus.collectAsStateWithLifecycle() + val calendarIds = state.reminderCalendars.map { it.id } + // Re-read whenever the screen returns from the system settings it links to. + LifecycleResumeEffect(calendarIds) { + viewModel.refreshChannelStatus(calendarIds) + onPauseOrDispose { } + } val openCalendarSound: (Long) -> Unit = { calendarId -> - scope.launch { context.openNotificationSettings(viewModel.reminderChannelFor(calendarId)) } + scope.launch { + val channelId = viewModel.reminderChannelFor(calendarId) + // With the whole app blocked, only the app's own screen can allow it. + context.openNotificationSettings(channelId.takeUnless { channelStatus.appBlocked }) + } } CollapsingScaffold( @@ -102,6 +123,18 @@ internal fun NotificationsScreen( predictiveBack = true, visible = visible, ) { + if (IS_SAMSUNG && !state.notificationCategoryHintDismissed) { + NotificationCategoryHint( + onOpen = { + scope.launch { + viewModel.syncReminderChannels() + context.openNotificationSettings() + } + }, + onDismiss = viewModel::dismissNotificationCategoryHint, + ) + Spacer(Modifier.height(16.dp)) + } GroupedSwitchRow( title = stringResource(R.string.settings_reminders), checked = state.remindersEnabled, @@ -111,7 +144,11 @@ internal fun NotificationsScreen( ) GroupedRow( title = stringResource(R.string.settings_notification_sound), - summary = stringResource(R.string.settings_notification_sound_hint), + summary = if (channelStatus.appBlocked) { + stringResource(R.string.settings_notifications_blocked_hint) + } else { + stringResource(R.string.settings_notification_sound_hint) + }, position = Position.Middle, trailing = { ExternalLinkIcon() }, onClick = { @@ -192,9 +229,14 @@ internal fun NotificationsScreen( Spacer(Modifier.height(16.dp)) val expanded = calendar.id in expandedCalendars val notifying = calendar.id !in state.mutedReminderCalendarIds + val blocked = notifying && calendar.id in channelStatus.blockedCalendarIds GroupedRow( title = calendar.displayName.orUnnamed(), - summary = if (notifying) null else stringResource(R.string.settings_calendar_notifications_off), + summary = when { + !notifying -> stringResource(R.string.settings_calendar_notifications_off) + blocked -> stringResource(R.string.settings_notifications_blocked) + else -> null + }, position = if (expanded) Position.Top else Position.Alone, leading = { CalendarColorChip(calendar.color) }, trailing = { ExpandIcon(expanded) }, @@ -215,6 +257,7 @@ internal fun NotificationsScreen( calendar = calendar, state = state, notifying = notifying, + blocked = blocked, onSetNotifying = { viewModel.setCalendarRemindersEnabled(calendar.id, it) }, onOpenSound = { openCalendarSound(calendar.id) }, onOpenSpecialDates = onOpenSpecialDates, @@ -316,6 +359,7 @@ private fun CalendarNotificationRows( calendar: CalendarSource, state: SettingsUiState, notifying: Boolean, + blocked: Boolean, onSetNotifying: (Boolean) -> Unit, onOpenSound: () -> Unit, onOpenSpecialDates: () -> Unit, @@ -333,7 +377,11 @@ private fun CalendarNotificationRows( ) GroupedRow( title = stringResource(R.string.settings_notification_sound), - summary = stringResource(R.string.settings_calendar_notification_sound_hint), + summary = if (blocked) { + stringResource(R.string.settings_notifications_blocked_hint) + } else { + stringResource(R.string.settings_calendar_notification_sound_hint) + }, position = if (managed || takesOverrides) Position.Middle else Position.Bottom, trailing = { ExternalLinkIcon() }, onClick = onOpenSound, @@ -371,6 +419,28 @@ private fun CalendarNotificationRows( } } +/** Samsung's One UI can start a new notification category switched off (#145). */ +private val IS_SAMSUNG = Build.MANUFACTURER.equals("samsung", ignoreCase = true) + +/** The one-time Samsung note, with a way into the app's notification settings. */ +@Composable +private fun NotificationCategoryHint(onOpen: () -> Unit, onDismiss: () -> Unit) { + IconInfoCard( + icon = Icons.Outlined.Info, + iconContentDescription = null, + iconAlignment = Alignment.Top, + ) { + Text( + text = stringResource(R.string.settings_notification_category_hint), + style = MaterialTheme.typography.bodyMedium, + ) + Row(Modifier.fillMaxWidth(), horizontalArrangement = Arrangement.End) { + TextButton(onClick = onDismiss) { Text(stringResource(R.string.reminder_action_dismiss)) } + TextButton(onClick = onOpen) { Text(stringResource(R.string.settings_notification_category_hint_open)) } + } + } +} + @Composable private fun ExternalLinkIcon() { Icon( diff --git a/app/src/main/java/de/jeanlucmakiola/calendula/ui/settings/SettingsUiState.kt b/app/src/main/java/de/jeanlucmakiola/calendula/ui/settings/SettingsUiState.kt index 43a8edce..1a0cc2fc 100644 --- a/app/src/main/java/de/jeanlucmakiola/calendula/ui/settings/SettingsUiState.kt +++ b/app/src/main/java/de/jeanlucmakiola/calendula/ui/settings/SettingsUiState.kt @@ -102,6 +102,8 @@ data class SettingsUiState( val reminderCalendars: List = emptyList(), /** Calendars whose reminders Calendula doesn't post (#272). */ val mutedReminderCalendarIds: Set = emptySet(), + /** Whether the Samsung notification-category hint has been dismissed (#145). */ + val notificationCategoryHintDismissed: Boolean = false, /** * Whether the event-colour picker is offered on calendars that publish no * colour palette (the colour may then not survive their next sync). 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 5dae73ee..ce2e2adf 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 @@ -34,6 +34,7 @@ import de.jeanlucmakiola.calendula.data.prefs.SpecialDatesStalledReason import de.jeanlucmakiola.floret.prefs.ThemeMode import de.jeanlucmakiola.calendula.data.prefs.TimeFormatPref import de.jeanlucmakiola.calendula.data.prefs.WeekStartPref +import de.jeanlucmakiola.calendula.data.reminders.ReminderChannelStatus import de.jeanlucmakiola.calendula.data.reminders.ReminderChannels import de.jeanlucmakiola.calendula.data.reminders.ReminderScanner import de.jeanlucmakiola.calendula.domain.CalendarSource @@ -131,6 +132,7 @@ class SettingsViewModel @Inject constructor( writableCalendars = calendars.filter { it.canModifyContents }, reminderCalendars = calendars, mutedReminderCalendarIds = this[SettingsKeys.mutedReminderCalendarIds], + notificationCategoryHintDismissed = this[SettingsKeys.notificationCategoryHintDismissed], allowColorOnUnsupportedCalendars = this[SettingsKeys.allowColorOnUnsupportedCalendars], managedCalendarIds = specialDatesCalendars.values.toSet(), ) @@ -370,6 +372,19 @@ class SettingsViewModel @Inject constructor( } } + private val _channelStatus = MutableStateFlow(ReminderChannelStatus()) + + /** What the system blocks of the reminders; re-read with [refreshChannelStatus] (#145). */ + val channelStatus: StateFlow = _channelStatus.asStateFlow() + + fun refreshChannelStatus(calendarIds: Collection) { + viewModelScope.launch { + onChannels { status(calendarIds) }?.let { _channelStatus.value = it } + } + } + + fun dismissNotificationCategoryHint() = save { dismissNotificationCategoryHint() } + /** [calendarId]'s reminder channel, created if needed so its system settings can open (#340). */ suspend fun reminderChannelFor(calendarId: Long): String? = onChannels { channelFor(calendarId) } diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index cc92c56e..3e7b8d77 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -737,6 +737,10 @@ Notifications off Notification sound Sound, vibration and pop-ups for each calendar, in system settings + Blocked in system settings + Blocked in system settings — tap to allow + On Samsung phones, new notification categories can start switched off. If a calendar\'s reminders don\'t arrive, check that its category is on. + Open settings Sound, vibration and pop-ups for this calendar, in system settings Default (%1$s) Reliable delivery diff --git a/app/src/test/java/de/jeanlucmakiola/calendula/data/reminders/ReminderChannelPlanTest.kt b/app/src/test/java/de/jeanlucmakiola/calendula/data/reminders/ReminderChannelPlanTest.kt index e32fa3a4..84d0c21d 100644 --- a/app/src/test/java/de/jeanlucmakiola/calendula/data/reminders/ReminderChannelPlanTest.kt +++ b/app/src/test/java/de/jeanlucmakiola/calendula/data/reminders/ReminderChannelPlanTest.kt @@ -127,6 +127,22 @@ class ReminderChannelPlanTest { assertThat(posted.groupsInUse).hasSize(1) } + @Test + fun `blocked calendars follow app, channel and group`() { + val channels = mapOf( + reminderChannelId(1) to ReminderChannelState(blocked = true, groupId = "g1"), + reminderChannelId(2) to ReminderChannelState(blocked = false, groupId = "g2"), + reminderChannelId(3) to ReminderChannelState(blocked = false, groupId = "g1"), + ) + val ids = listOf(1L, 2L, 3L, 4L) + assertThat(blockedReminderCalendars(ids, appEnabled = true, channels, blockedGroupIds = setOf("g2"))) + .containsExactly(1L, 2L) + assertThat(blockedReminderCalendars(ids, appEnabled = true, channels, blockedGroupIds = emptySet())) + .containsExactly(1L) + assertThat(blockedReminderCalendars(ids, appEnabled = false, channels, blockedGroupIds = emptySet())) + .containsExactly(1L, 2L, 3L, 4L) + } + private companion object { const val DESC = "Reminders" } diff --git a/docs/ARCHITECTURE.md b/docs/ARCHITECTURE.md index 4822bd47..8f0a77ba 100644 --- a/docs/ARCHITECTURE.md +++ b/docs/ARCHITECTURE.md @@ -407,7 +407,9 @@ the system's channel screens (#340); the app never sets a sound itself. Separate from both, `SettingsPrefs.mutedReminderCalendarIds` is the in-app per-calendar off switch (#272): the scan plans nothing for those calendars (so they arm no wake-ups; toggling it re-scans), and `ReminderNotifier.post` checks it again -for snoozes. +for snoozes. The settings screen re-reads `ReminderChannels.status` on every +resume and marks a calendar "Blocked in system settings" when the app, its +channel or its account group is switched off there. Deliberately absent: a fallback to the provider's `EVENT_REMINDER` broadcast. Keeping both would double-post wherever the provider works, and Etar's way out — From 2e71e4dc5fbe31acbfce40cb5222a56647e64530 Mon Sep 17 00:00:00 2001 From: Jean-Luc Makiola Date: Sat, 14 Nov 2026 02:34:07 +0100 Subject: [PATCH 2/4] =?UTF-8?q?fix(#145):=20review=20round=20A=20=E2=80=94?= =?UTF-8?q?=20group-blocked=20deep-link,=20status=20refresh=20race,=20hint?= =?UTF-8?q?=20dismiss=20on=20open?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../data/reminders/ReminderChannels.kt | 21 +++++++++++-------- .../ui/settings/NotificationSettings.kt | 10 ++++----- .../ui/settings/SettingsViewModel.kt | 6 +++++- floret-kit | 2 +- 4 files changed, 22 insertions(+), 17 deletions(-) diff --git a/app/src/main/java/de/jeanlucmakiola/calendula/data/reminders/ReminderChannels.kt b/app/src/main/java/de/jeanlucmakiola/calendula/data/reminders/ReminderChannels.kt index 95fbfff5..0a82fe55 100644 --- a/app/src/main/java/de/jeanlucmakiola/calendula/data/reminders/ReminderChannels.kt +++ b/app/src/main/java/de/jeanlucmakiola/calendula/data/reminders/ReminderChannels.kt @@ -106,15 +106,17 @@ class ReminderChannels @Inject constructor( fun status(calendarIds: Collection): ReminderChannelStatus { val manager = manager val appEnabled = manager.areNotificationsEnabled() - val blocked = blockedReminderCalendars( - calendarIds = calendarIds, - appEnabled = appEnabled, - channels = manager.notificationChannels.associate { - it.id to ReminderChannelState(it.importance == NotificationManager.IMPORTANCE_NONE, it.group) + val channels = manager.notificationChannels.associate { + it.id to ReminderChannelState(it.importance == NotificationManager.IMPORTANCE_NONE, it.group) + } + val blockedGroups = manager.notificationChannelGroups.filter { it.isBlocked }.mapTo(HashSet()) { it.id } + return ReminderChannelStatus( + appBlocked = !appEnabled, + blockedCalendarIds = blockedReminderCalendars(calendarIds, appEnabled, channels, blockedGroups), + groupBlockedCalendarIds = calendarIds.filterTo(HashSet()) { + channels[reminderChannelId(it)]?.groupId in blockedGroups }, - blockedGroupIds = manager.notificationChannelGroups.filter { it.isBlocked }.mapTo(HashSet()) { it.id }, ) - return ReminderChannelStatus(appBlocked = !appEnabled, blockedCalendarIds = blocked) } private fun plan( @@ -141,8 +143,7 @@ class ReminderChannels @Inject constructor( if (channels.isEmpty()) return val byId = existing.associateBy { it.id } val template = byId[LEGACY_REMINDER_CHANNEL_ID] - // Only a channel's first creation sets its behaviour; later calls just - // rename it, so an existing one passes its own importance back. + // Importance only applies on creation; an existing channel keeps its own. manager.createNotificationChannels( channels.map { spec -> val current = byId[spec.id] @@ -210,4 +211,6 @@ class ReminderChannels @Inject constructor( data class ReminderChannelStatus( val appBlocked: Boolean = false, val blockedCalendarIds: Set = emptySet(), + /** The blocked ones whose whole account group is off, which only the app's own screen can undo. */ + val groupBlockedCalendarIds: Set = emptySet(), ) 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 85d5b064..46b90ee7 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 @@ -104,7 +104,6 @@ internal fun NotificationsScreen( val scope = rememberCoroutineScope() val channelStatus by viewModel.channelStatus.collectAsStateWithLifecycle() val calendarIds = state.reminderCalendars.map { it.id } - // Re-read whenever the screen returns from the system settings it links to. LifecycleResumeEffect(calendarIds) { viewModel.refreshChannelStatus(calendarIds) onPauseOrDispose { } @@ -112,8 +111,8 @@ internal fun NotificationsScreen( val openCalendarSound: (Long) -> Unit = { calendarId -> scope.launch { val channelId = viewModel.reminderChannelFor(calendarId) - // With the whole app blocked, only the app's own screen can allow it. - context.openNotificationSettings(channelId.takeUnless { channelStatus.appBlocked }) + val appScreen = channelStatus.appBlocked || calendarId in channelStatus.groupBlockedCalendarIds + context.openNotificationSettings(channelId.takeUnless { appScreen }) } } @@ -126,6 +125,7 @@ internal fun NotificationsScreen( if (IS_SAMSUNG && !state.notificationCategoryHintDismissed) { NotificationCategoryHint( onOpen = { + viewModel.dismissNotificationCategoryHint() scope.launch { viewModel.syncReminderChannels() context.openNotificationSettings() @@ -207,9 +207,7 @@ internal fun NotificationsScreen( onClick = { showSnooze = true }, ) - // Per-calendar settings, folded behind one header: every switched-on - // calendar gets its notification switch and sound (#145, #272); the ones - // you can edit also keep, drop or replace the default reminders. + // Per-calendar notifications and reminder overrides (#145, #272). if (state.reminderCalendars.isNotEmpty()) { Spacer(Modifier.height(24.dp)) GroupedRow( 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 ce2e2adf..8b287aff 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 @@ -50,6 +50,7 @@ import de.jeanlucmakiola.calendula.ui.theme.AppFontSettings import de.jeanlucmakiola.calendula.ui.theme.FONT_CUSTOM_TOKEN import kotlinx.coroutines.CancellationException import kotlinx.coroutines.CoroutineDispatcher +import kotlinx.coroutines.Job import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.MutableSharedFlow import kotlinx.coroutines.flow.MutableStateFlow @@ -377,8 +378,11 @@ class SettingsViewModel @Inject constructor( /** What the system blocks of the reminders; re-read with [refreshChannelStatus] (#145). */ val channelStatus: StateFlow = _channelStatus.asStateFlow() + private var channelStatusJob: Job? = null + fun refreshChannelStatus(calendarIds: Collection) { - viewModelScope.launch { + channelStatusJob?.cancel() + channelStatusJob = viewModelScope.launch { onChannels { status(calendarIds) }?.let { _channelStatus.value = it } } } diff --git a/floret-kit b/floret-kit index 730c9eb2..20b136aa 160000 --- a/floret-kit +++ b/floret-kit @@ -1 +1 @@ -Subproject commit 730c9eb25a6bf2f93e3388bf132769d6dd1afd91 +Subproject commit 20b136aaf71277643267018ed1c57dae0b0c54ec From 99a584a82d295c2e796eeed7f8736c0c9d8f46a6 Mon Sep 17 00:00:00 2001 From: Jean-Luc Makiola Date: Sat, 14 Nov 2026 02:42:22 +0100 Subject: [PATCH 3/4] =?UTF-8?q?fix(#145):=20review=20round=20B=20=E2=80=94?= =?UTF-8?q?=20fresh=20status=20for=20the=20sound=20deep-link,=20one=20test?= =?UTF-8?q?ed=20status=20function,=20no=20hint=20flash?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../data/reminders/ReminderChannelPlan.kt | 29 ++++++++++++------- .../data/reminders/ReminderChannels.kt | 18 ++---------- .../data/reminders/ReminderNotifier.kt | 5 +++- .../ui/settings/NotificationSettings.kt | 24 +++++++-------- .../calendula/ui/settings/SettingsUiState.kt | 6 ++-- .../ui/settings/SettingsViewModel.kt | 12 ++++++-- .../data/reminders/ReminderChannelPlanTest.kt | 12 ++++---- 7 files changed, 56 insertions(+), 50 deletions(-) diff --git a/app/src/main/java/de/jeanlucmakiola/calendula/data/reminders/ReminderChannelPlan.kt b/app/src/main/java/de/jeanlucmakiola/calendula/data/reminders/ReminderChannelPlan.kt index f75eb262..e67a7727 100644 --- a/app/src/main/java/de/jeanlucmakiola/calendula/data/reminders/ReminderChannelPlan.kt +++ b/app/src/main/java/de/jeanlucmakiola/calendula/data/reminders/ReminderChannelPlan.kt @@ -132,21 +132,30 @@ private fun accountGroupId(type: String, name: String): String = "$GROUP_PREFIX$ /** A channel as far as its blocked state goes: switched off itself, and the group it sits in. */ data class ReminderChannelState(val blocked: Boolean, val groupId: String?) +/** Reminder notifications the system blocks, while Calendula would post them. */ +data class ReminderChannelStatus( + val appBlocked: Boolean = false, + val blockedCalendarIds: Set = emptySet(), + /** The blocked ones whose whole account group is off, which only the app's own screen can undo. */ + val groupBlockedCalendarIds: Set = emptySet(), +) + /** - * The calendars among [calendarIds] whose reminders the system blocks: all of - * them while the app's notifications are off, otherwise those whose channel, - * or the group it sits in, is switched off. A calendar without a channel yet - * isn't blocked. + * What the system blocks of [calendarIds]' reminders: all of them while the + * app's notifications are off, otherwise those whose channel, or the group it + * sits in, is switched off. A calendar without a channel yet isn't blocked. */ -fun blockedReminderCalendars( +fun reminderChannelStatus( calendarIds: Collection, appEnabled: Boolean, channels: Map, blockedGroupIds: Set, -): Set { - if (!appEnabled) return calendarIds.toSet() - return calendarIds.filterTo(HashSet()) { id -> - val channel = channels[reminderChannelId(id)] ?: return@filterTo false - channel.blocked || channel.groupId in blockedGroupIds +): ReminderChannelStatus { + val groupBlocked = calendarIds.filterTo(HashSet()) { channels[reminderChannelId(it)]?.groupId in blockedGroupIds } + val blocked = if (!appEnabled) { + calendarIds.toSet() + } else { + calendarIds.filterTo(HashSet()) { channels[reminderChannelId(it)]?.blocked == true } + groupBlocked } + return ReminderChannelStatus(appBlocked = !appEnabled, blockedCalendarIds = blocked, groupBlockedCalendarIds = groupBlocked) } diff --git a/app/src/main/java/de/jeanlucmakiola/calendula/data/reminders/ReminderChannels.kt b/app/src/main/java/de/jeanlucmakiola/calendula/data/reminders/ReminderChannels.kt index 0a82fe55..717292b8 100644 --- a/app/src/main/java/de/jeanlucmakiola/calendula/data/reminders/ReminderChannels.kt +++ b/app/src/main/java/de/jeanlucmakiola/calendula/data/reminders/ReminderChannels.kt @@ -110,13 +110,7 @@ class ReminderChannels @Inject constructor( it.id to ReminderChannelState(it.importance == NotificationManager.IMPORTANCE_NONE, it.group) } val blockedGroups = manager.notificationChannelGroups.filter { it.isBlocked }.mapTo(HashSet()) { it.id } - return ReminderChannelStatus( - appBlocked = !appEnabled, - blockedCalendarIds = blockedReminderCalendars(calendarIds, appEnabled, channels, blockedGroups), - groupBlockedCalendarIds = calendarIds.filterTo(HashSet()) { - channels[reminderChannelId(it)]?.groupId in blockedGroups - }, - ) + return reminderChannelStatus(calendarIds, appEnabled, channels, blockedGroups) } private fun plan( @@ -142,6 +136,7 @@ class ReminderChannels @Inject constructor( } if (channels.isEmpty()) return val byId = existing.associateBy { it.id } + val description = context.getString(R.string.reminder_channel_description) val template = byId[LEGACY_REMINDER_CHANNEL_ID] // Importance only applies on creation; an existing channel keeps its own. manager.createNotificationChannels( @@ -152,7 +147,7 @@ class ReminderChannels @Inject constructor( spec.name, current?.importance ?: template?.importance ?: NotificationManager.IMPORTANCE_HIGH, ).apply { - description = context.getString(R.string.reminder_channel_description) + this.description = description spec.groupId?.let { group = it } if (current == null && template != null) inheritFrom(template) } @@ -207,10 +202,3 @@ class ReminderChannels @Inject constructor( } } -/** Reminder notifications the system blocks, while Calendula would post them. */ -data class ReminderChannelStatus( - val appBlocked: Boolean = false, - val blockedCalendarIds: Set = emptySet(), - /** The blocked ones whose whole account group is off, which only the app's own screen can undo. */ - val groupBlockedCalendarIds: Set = emptySet(), -) diff --git a/app/src/main/java/de/jeanlucmakiola/calendula/data/reminders/ReminderNotifier.kt b/app/src/main/java/de/jeanlucmakiola/calendula/data/reminders/ReminderNotifier.kt index 3631482e..7f03769c 100644 --- a/app/src/main/java/de/jeanlucmakiola/calendula/data/reminders/ReminderNotifier.kt +++ b/app/src/main/java/de/jeanlucmakiola/calendula/data/reminders/ReminderNotifier.kt @@ -70,7 +70,10 @@ class ReminderNotifier @Inject constructor( } catch (e: Exception) { Log.w(TAG, "No channel for the reminder of event ${alert.eventId}", e) null - } ?: return + } ?: run { + Log.i(TAG, "Dropped the reminder of event ${alert.eventId}: calendar ${alert.calendarId} is gone") + return + } val title = displayTitle(alert) val is24Hour = settingsPrefs.timeFormat.first() .is24Hour(android.text.format.DateFormat.is24HourFormat(context)) 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 46b90ee7..efa61104 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 @@ -10,23 +10,19 @@ import androidx.activity.compose.rememberLauncherForActivityResult import androidx.activity.result.contract.ActivityResultContracts import androidx.compose.animation.AnimatedVisibility import androidx.compose.foundation.layout.Arrangement -import androidx.compose.foundation.layout.Row -import androidx.compose.foundation.layout.fillMaxWidth -import androidx.compose.material.icons.outlined.Info -import androidx.compose.material3.Text -import androidx.compose.material3.TextButton -import androidx.compose.ui.Alignment -import androidx.lifecycle.compose.LifecycleResumeEffect -import androidx.lifecycle.compose.collectAsStateWithLifecycle -import de.jeanlucmakiola.floret.components.IconInfoCard import androidx.compose.foundation.layout.Column +import androidx.compose.foundation.layout.Row import androidx.compose.foundation.layout.Spacer +import androidx.compose.foundation.layout.fillMaxWidth import androidx.compose.foundation.layout.height import androidx.compose.material.icons.Icons import androidx.compose.material.icons.automirrored.filled.KeyboardArrowRight import androidx.compose.material.icons.automirrored.filled.OpenInNew +import androidx.compose.material.icons.outlined.Info import androidx.compose.material3.Icon import androidx.compose.material3.MaterialTheme +import androidx.compose.material3.Text +import androidx.compose.material3.TextButton import androidx.compose.runtime.Composable import androidx.compose.runtime.DisposableEffect import androidx.compose.runtime.getValue @@ -34,6 +30,7 @@ import androidx.compose.runtime.mutableStateOf import androidx.compose.runtime.remember import androidx.compose.runtime.rememberCoroutineScope import androidx.compose.runtime.setValue +import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier import androidx.compose.ui.platform.LocalContext import androidx.compose.ui.res.stringResource @@ -41,7 +38,9 @@ import androidx.compose.ui.unit.dp import androidx.core.net.toUri import androidx.lifecycle.Lifecycle import androidx.lifecycle.LifecycleEventObserver +import androidx.lifecycle.compose.LifecycleResumeEffect import androidx.lifecycle.compose.LocalLifecycleOwner +import androidx.lifecycle.compose.collectAsStateWithLifecycle import de.jeanlucmakiola.calendula.R import de.jeanlucmakiola.calendula.domain.CalendarSource import de.jeanlucmakiola.calendula.ui.common.CalendarColorChip @@ -57,6 +56,7 @@ import de.jeanlucmakiola.floret.components.CollapsingScaffold import de.jeanlucmakiola.floret.components.ExpandIcon import de.jeanlucmakiola.floret.components.GroupedRow import de.jeanlucmakiola.floret.components.GroupedSwitchRow +import de.jeanlucmakiola.floret.components.IconInfoCard import de.jeanlucmakiola.floret.components.Position import de.jeanlucmakiola.floret.components.SelectedCheck import de.jeanlucmakiola.floret.identity.collapseExit @@ -109,11 +109,7 @@ internal fun NotificationsScreen( onPauseOrDispose { } } val openCalendarSound: (Long) -> Unit = { calendarId -> - scope.launch { - val channelId = viewModel.reminderChannelFor(calendarId) - val appScreen = channelStatus.appBlocked || calendarId in channelStatus.groupBlockedCalendarIds - context.openNotificationSettings(channelId.takeUnless { appScreen }) - } + scope.launch { context.openNotificationSettings(viewModel.soundSettingsChannel(calendarId)) } } CollapsingScaffold( diff --git a/app/src/main/java/de/jeanlucmakiola/calendula/ui/settings/SettingsUiState.kt b/app/src/main/java/de/jeanlucmakiola/calendula/ui/settings/SettingsUiState.kt index 1a0cc2fc..34e603b3 100644 --- a/app/src/main/java/de/jeanlucmakiola/calendula/ui/settings/SettingsUiState.kt +++ b/app/src/main/java/de/jeanlucmakiola/calendula/ui/settings/SettingsUiState.kt @@ -96,14 +96,14 @@ data class SettingsUiState( val perCalendarReminderOverride: Map> = emptyMap(), /** Per-calendar overrides of [defaultAllDayReminderMinutes] for all-day events. */ val perCalendarAllDayReminderOverride: Map> = emptyMap(), - /** Switched-on calendars you can edit: the per-calendar duration and reminder-override rows. */ + /** Switched-on calendars you can edit: the per-calendar event-duration rows. */ val writableCalendars: List = emptyList(), /** Switched-on calendars, each with its own notification switch and channel (#145, #272). */ val reminderCalendars: List = emptyList(), /** Calendars whose reminders Calendula doesn't post (#272). */ val mutedReminderCalendarIds: Set = emptySet(), - /** Whether the Samsung notification-category hint has been dismissed (#145). */ - val notificationCategoryHintDismissed: Boolean = false, + /** Whether the Samsung notification-category hint has been dismissed (#145); hidden until prefs load. */ + val notificationCategoryHintDismissed: Boolean = true, /** * Whether the event-colour picker is offered on calendars that publish no * colour palette (the colour may then not survive their next sync). 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 8b287aff..18d7ed6b 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 @@ -389,8 +389,16 @@ class SettingsViewModel @Inject constructor( fun dismissNotificationCategoryHint() = save { dismissNotificationCategoryHint() } - /** [calendarId]'s reminder channel, created if needed so its system settings can open (#340). */ - suspend fun reminderChannelFor(calendarId: Long): String? = onChannels { channelFor(calendarId) } + /** + * The channel whose system screen to open for [calendarId] (#340), created + * if needed; null when only the app's own screen can help — the app or the + * calendar's account group is blocked there, or the channel couldn't be made. + */ + suspend fun soundSettingsChannel(calendarId: Long): String? = onChannels { + val channelId = channelFor(calendarId) ?: return@onChannels null + val status = status(listOf(calendarId)) + channelId.takeUnless { status.appBlocked || calendarId in status.groupBlockedCalendarIds } + } /** Create the per-calendar channels before showing the app's channel list, even with reminders off. */ suspend fun syncReminderChannels() { diff --git a/app/src/test/java/de/jeanlucmakiola/calendula/data/reminders/ReminderChannelPlanTest.kt b/app/src/test/java/de/jeanlucmakiola/calendula/data/reminders/ReminderChannelPlanTest.kt index 84d0c21d..4634644b 100644 --- a/app/src/test/java/de/jeanlucmakiola/calendula/data/reminders/ReminderChannelPlanTest.kt +++ b/app/src/test/java/de/jeanlucmakiola/calendula/data/reminders/ReminderChannelPlanTest.kt @@ -135,12 +135,14 @@ class ReminderChannelPlanTest { reminderChannelId(3) to ReminderChannelState(blocked = false, groupId = "g1"), ) val ids = listOf(1L, 2L, 3L, 4L) - assertThat(blockedReminderCalendars(ids, appEnabled = true, channels, blockedGroupIds = setOf("g2"))) - .containsExactly(1L, 2L) - assertThat(blockedReminderCalendars(ids, appEnabled = true, channels, blockedGroupIds = emptySet())) + val groupOff = reminderChannelStatus(ids, appEnabled = true, channels, blockedGroupIds = setOf("g2")) + assertThat(groupOff.blockedCalendarIds).containsExactly(1L, 2L) + assertThat(groupOff.groupBlockedCalendarIds).containsExactly(2L) + assertThat(reminderChannelStatus(ids, appEnabled = true, channels, blockedGroupIds = emptySet()).blockedCalendarIds) .containsExactly(1L) - assertThat(blockedReminderCalendars(ids, appEnabled = false, channels, blockedGroupIds = emptySet())) - .containsExactly(1L, 2L, 3L, 4L) + val appOff = reminderChannelStatus(ids, appEnabled = false, channels, blockedGroupIds = emptySet()) + assertThat(appOff.appBlocked).isTrue() + assertThat(appOff.blockedCalendarIds).containsExactly(1L, 2L, 3L, 4L) } private companion object { From 31ba82a295060ba3b35c7fe77f532e56862a1459 Mon Sep 17 00:00:00 2001 From: Jean-Luc Makiola Date: Sat, 14 Nov 2026 02:50:36 +0100 Subject: [PATCH 4/4] =?UTF-8?q?fix(#145):=20review=20round=20C=20=E2=80=94?= =?UTF-8?q?=20no=20replay=20on=20unmute,=20fallback=20channel=20on=20write?= =?UTF-8?q?=20failure,=20hide=20pending-off=20calendars?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../data/reminders/ReminderChannels.kt | 24 +++++++++++-------- .../data/reminders/ReminderNotifier.kt | 8 +++---- .../ui/settings/SettingsViewModel.kt | 16 +++++++++---- 3 files changed, 30 insertions(+), 18 deletions(-) diff --git a/app/src/main/java/de/jeanlucmakiola/calendula/data/reminders/ReminderChannels.kt b/app/src/main/java/de/jeanlucmakiola/calendula/data/reminders/ReminderChannels.kt index 717292b8..3698ee76 100644 --- a/app/src/main/java/de/jeanlucmakiola/calendula/data/reminders/ReminderChannels.kt +++ b/app/src/main/java/de/jeanlucmakiola/calendula/data/reminders/ReminderChannels.kt @@ -86,19 +86,24 @@ class ReminderChannels @Inject constructor( Log.w(TAG, "Could not look up calendar $calendarId for its channel", e) emptyList() } + val fallback = ReminderChannelSpec(id, calendarId, context.getString(R.string.reminder_channel_name), null) if (calendars.isEmpty()) { - val fallback = ReminderChannelSpec(id, calendarId, context.getString(R.string.reminder_channel_name), null) write(emptyList(), listOf(fallback), existing) return id } val plan = plan(calendars, existing, emptyList()) val spec = plan.channels.firstOrNull { it.calendarId == calendarId } ?: return null - val knownGroups = manager.notificationChannelGroups.mapTo(HashSet()) { it.id } - write( - groups = plan.groups.filter { it.id == spec.groupId && it.id !in knownGroups }, - channels = listOf(spec), - existing = existing, - ) + try { + val knownGroups = manager.notificationChannelGroups.mapTo(HashSet()) { it.id } + write( + groups = plan.groups.filter { it.id == spec.groupId && it.id !in knownGroups }, + channels = listOf(spec), + existing = existing, + ) + } catch (e: RuntimeException) { + Log.w(TAG, "Could not file the channel of calendar $calendarId", e) + write(emptyList(), listOf(fallback), existing) + } return id } @@ -156,8 +161,8 @@ class ReminderChannels @Inject constructor( } /** - * Carry the old single channel's sound, vibration and lock-screen choices - * over to a new per-calendar one, so an upgrade keeps how reminders sounded. + * Carry the old single channel's sound, vibration, lights and badge over to + * a new per-calendar one (the system resets lock-screen visibility itself), so an upgrade keeps how reminders sounded. */ private fun NotificationChannel.inheritFrom(template: NotificationChannel) { setSound(template.sound, template.audioAttributes) @@ -166,7 +171,6 @@ class ReminderChannels @Inject constructor( enableVibration(template.shouldVibrate()) enableLights(template.shouldShowLights()) lightColor = template.lightColor - lockscreenVisibility = template.lockscreenVisibility setShowBadge(template.canShowBadge()) // Only honoured with Do Not Disturb access, so usually left to the user. setBypassDnd(template.canBypassDnd()) diff --git a/app/src/main/java/de/jeanlucmakiola/calendula/data/reminders/ReminderNotifier.kt b/app/src/main/java/de/jeanlucmakiola/calendula/data/reminders/ReminderNotifier.kt index 7f03769c..f7a4fd46 100644 --- a/app/src/main/java/de/jeanlucmakiola/calendula/data/reminders/ReminderNotifier.kt +++ b/app/src/main/java/de/jeanlucmakiola/calendula/data/reminders/ReminderNotifier.kt @@ -66,12 +66,12 @@ class ReminderNotifier @Inject constructor( suspend fun post(alert: ReminderAlert) { if (isSilenced(alert.calendarId)) return val channelId = try { - channels.channelFor(alert.calendarId) + channels.channelFor(alert.calendarId) ?: run { + Log.i(TAG, "Dropped the reminder of event ${alert.eventId}: calendar ${alert.calendarId} is gone") + return + } } catch (e: Exception) { Log.w(TAG, "No channel for the reminder of event ${alert.eventId}", e) - null - } ?: run { - Log.i(TAG, "Dropped the reminder of event ${alert.eventId}: calendar ${alert.calendarId} is gone") return } val title = displayTitle(alert) 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 18d7ed6b..21ff880b 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.floret.reminders.ReminderOverride import de.jeanlucmakiola.floret.reminders.reminderOverrideFor +import de.jeanlucmakiola.calendula.data.prefs.CalendarPrefs import de.jeanlucmakiola.calendula.data.prefs.PastEventDisplay import de.jeanlucmakiola.calendula.data.prefs.SettingsKeys import de.jeanlucmakiola.calendula.data.prefs.SettingsPrefs @@ -67,6 +68,7 @@ import javax.inject.Inject @HiltViewModel class SettingsViewModel @Inject constructor( private val prefs: SettingsPrefs, + calendarPrefs: CalendarPrefs, repository: CalendarRepository, private val specialDatesEngine: SpecialDatesSyncEngine, specialDatesSpec: SpecialDatesCalendarSpec, @@ -83,9 +85,10 @@ class SettingsViewModel @Inject constructor( * Calendars that are switched on — the only ones that plan reminders at * all (#75), so the only ones with notification settings. */ - private val visibleCalendars: Flow> = repository.calendars() - .map { calendars -> calendars.filter { it.isVisibleInSystem } } - .catch { emit(emptyList()) } + private val visibleCalendars: Flow> = + combine(repository.calendars(), calendarPrefs.pendingDisabledCalendarIds) { calendars, pending -> + calendars.filter { it.isVisibleInSystem && it.id !in pending } + }.catch { emit(emptyList()) } val state: StateFlow = combine(prefs.data, visibleCalendars) { stored, calendars -> stored.toUiState(calendars) } @@ -365,9 +368,14 @@ class SettingsViewModel @Inject constructor( } } - /** Re-plans, since a muted calendar armed no wake-up for its next reminder. */ + /** + * Re-plans, since a muted calendar armed no wake-up for its next reminder. + * Unmuting scans once more before the write, so the watermark starts at the + * unmute and nothing that came due while muted is replayed. + */ fun setCalendarRemindersEnabled(calendarId: Long, enabled: Boolean) { viewModelScope.launch { + if (enabled) reminderScanner.scan() prefs.setCalendarRemindersEnabled(calendarId, enabled) reminderScanner.scan() }