Leave fresh reminders ungrouped, silent re-posts in a shared group (#100)

This commit is contained in:
makiolaj committed 2026-11-20 11:32:46 +01:00
1 parent e4bb254512
commit 3b94af47a8
1 file changed
+14 -5
@@ -147,8 +147,7 @@ class TaskNotifier @Inject constructor(
.setWhen(shownAt)
.setAutoCancel(!persistent)
.setSilent(!alert)
// Grouped alike either way: silent without a group lands in NotificationCompat's own "silent" group.
.setGroup(groupOf(task.taskId))
.apply { groupFor(task.taskId, persistent, alert)?.let(::setGroup) }
.setDeleteIntent(if (persistent) dismissedIntent(task.taskId, occurrence) else null)
.setContentIntent(tapIntent)
.addExtras(
@@ -239,7 +238,7 @@ class TaskNotifier @Inject constructor(
val notification = Notification.Builder.recoverBuilder(context, posted.notification)
.setAutoCancel(!persistent)
.setOnlyAlertOnce(true)
.setGroup(groupOf(posted.taskId))
.setGroup(groupFor(posted.taskId, persistent, alert = true))
.setDeleteIntent(if (persistent) dismissedIntent(posted.taskId, occurrence) else null)
.build()
manager.notify(posted.taskId.toString(), NOTIFICATION_ID, notification)
@@ -317,7 +316,16 @@ class TaskNotifier @Inject constructor(
}
}
private fun groupOf(taskId: Long) = "$REMINDER_GROUP_PREFIX$taskId"
/**
* A persistent reminder keeps a group of its own; a fresh one goes ungrouped so
* Android may bundle it, and a silent re-post shares [SILENT_GROUP] rather than
* NotificationCompat's implicit "silent" group.
*/
private fun groupFor(taskId: Long, persistent: Boolean, alert: Boolean): String? = when {
persistent -> "$PERSISTENT_GROUP_PREFIX$taskId"
alert -> null
else -> SILENT_GROUP
}
private fun dismissedIntent(taskId: Long, occurrence: Long): PendingIntent =
broadcast(taskId, ReminderActionReceiver.dismissedIntent(context, taskId, occurrence, currentStore))
@@ -406,7 +414,8 @@ class TaskNotifier @Inject constructor(
private const val KEY_LEGACY_IMPORTANCE = "legacy_importance"
private const val EXTRA_DUE = "de.jeanlucmakiola.agendula.extra.DUE"
private const val NO_DUE = Long.MIN_VALUE
private const val REMINDER_GROUP_PREFIX = "reminder_"
private const val PERSISTENT_GROUP_PREFIX = "reminder_"
private const val SILENT_GROUP = "reminders"
/**
* Whether a reminder can sound anywhere: the group is not blocked and at