fix(#459): post-merge review — summary channel under #145's blocked status, deep-link and Samsung hint
This commit is contained in:
1 parent
05ac15f63c
commit
d1880d04b2
6 files changed
+34
-11
No files matched your search
@@ -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() {
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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<Boolean> = _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()
|
||||
|
||||
@@ -735,6 +735,7 @@
|
||||
<string name="settings_calendar_notifications">Notifications</string>
|
||||
<string name="settings_calendar_notifications_hint">Notify at this calendar\'s reminder times</string>
|
||||
<string name="settings_calendar_notifications_off">Notifications off</string>
|
||||
<string name="settings_calendar_reminders_off">Reminders off</string>
|
||||
<string name="settings_notification_sound">Notification sound</string>
|
||||
<string name="settings_notification_sound_hint">Sound, vibration and pop-ups for each calendar, in system settings</string>
|
||||
<string name="settings_notifications_blocked">Blocked in system settings</string>
|
||||
|
||||
@@ -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.
|
||||
|
||||
Reference in new issue
Block a user