From f0ce05e06e50f2d76b1fae91f1c3c0f0056ec721 Mon Sep 17 00:00:00 2001 From: "Alinson S. Xavier" Date: Sat, 25 Nov 2023 15:41:39 -0600 Subject: [PATCH] API 34: Implement workaround to keep sticky notifications non-dismissible --- .../org/isoron/uhabits/receivers/ReminderController.kt | 8 +++++++- .../java/org/isoron/uhabits/core/ui/NotificationTray.kt | 6 ++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/uhabits-android/src/main/java/org/isoron/uhabits/receivers/ReminderController.kt b/uhabits-android/src/main/java/org/isoron/uhabits/receivers/ReminderController.kt index 38ba3a1b4..4937dbc74 100644 --- a/uhabits-android/src/main/java/org/isoron/uhabits/receivers/ReminderController.kt +++ b/uhabits-android/src/main/java/org/isoron/uhabits/receivers/ReminderController.kt @@ -66,7 +66,13 @@ class ReminderController @Inject constructor( } fun onDismiss(habit: Habit) { - notificationTray.cancel(habit) + if (preferences.shouldMakeNotificationsSticky()) { + // This is a workaround to keep sticky notifications non-dismissible in Android 14+. + // If the notification is dismissed, we immediately reshow it. + notificationTray.reshow(habit) + } else { + notificationTray.cancel(habit) + } } private fun showSnoozeDelayPicker(habit: Habit, context: Context) { diff --git a/uhabits-core/src/jvmMain/java/org/isoron/uhabits/core/ui/NotificationTray.kt b/uhabits-core/src/jvmMain/java/org/isoron/uhabits/core/ui/NotificationTray.kt index 5239ed44b..da5bb018a 100644 --- a/uhabits-core/src/jvmMain/java/org/isoron/uhabits/core/ui/NotificationTray.kt +++ b/uhabits-core/src/jvmMain/java/org/isoron/uhabits/core/ui/NotificationTray.kt @@ -89,6 +89,12 @@ class NotificationTray @Inject constructor( } } + fun reshow(habit: Habit) { + active[habit]?.let { + taskRunner.execute(ShowNotificationTask(habit, it)) + } + } + interface SystemTray { fun removeNotification(notificationId: Int) fun showNotification(