fix(#145): review round B — fresh status for the sound deep-link, one tested status function, no hint flash

This commit is contained in:
makiolaj committed 2026-11-14 02:42:22 +01:00
1 parent 2e71e4dc5f
commit 99a584a82d
7 files changed
+56 -50

No files matched your search

@@ -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<Long> = emptySet(),
/** The blocked ones whose whole account group is off, which only the app's own screen can undo. */
val groupBlockedCalendarIds: Set<Long> = 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<Long>,
appEnabled: Boolean,
channels: Map<String, ReminderChannelState>,
blockedGroupIds: Set<String>,
): Set<Long> {
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)
}
@@ -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<Long> = emptySet(),
/** The blocked ones whose whole account group is off, which only the app's own screen can undo. */
val groupBlockedCalendarIds: Set<Long> = emptySet(),
)
@@ -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))
@@ -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(
@@ -96,14 +96,14 @@ data class SettingsUiState(
val perCalendarReminderOverride: Map<Long, List<Int>> = emptyMap(),
/** Per-calendar overrides of [defaultAllDayReminderMinutes] for all-day events. */
val perCalendarAllDayReminderOverride: Map<Long, List<Int>> = 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<CalendarSource> = emptyList(),
/** Switched-on calendars, each with its own notification switch and channel (#145, #272). */
val reminderCalendars: List<CalendarSource> = emptyList(),
/** Calendars whose reminders Calendula doesn't post (#272). */
val mutedReminderCalendarIds: Set<Long> = 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).
@@ -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() {
@@ -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 {