From 2edf5411ce6a0f036e2e0094a41dd822d9d277fe Mon Sep 17 00:00:00 2001 From: darken Date: Sat, 30 Aug 2025 18:08:38 +0200 Subject: [PATCH] Allow keeping "connected" notification after disconnect This commit introduces a new setting that allows users to keep the "connected" notification visible even after the monitored device disconnects. When this setting is enabled and the "Extra notification" is also active, the `MonitorWorker` will no longer cancel the connected notification upon finishing. This provides users with the option to see the last known battery levels after disconnection. A new preference `keepConnectedNotificationAfterDisconnect` is added to `GeneralSettings` and the UI. --- .../main/java/eu/darken/capod/main/core/GeneralSettings.kt | 4 ++++ .../eu/darken/capod/monitor/core/worker/MonitorWorker.kt | 7 +++++++ app/src/main/res/values/strings.xml | 2 ++ app/src/main/res/xml/preferences_general.xml | 7 +++++++ 4 files changed, 20 insertions(+) diff --git a/app-common/src/main/java/eu/darken/capod/main/core/GeneralSettings.kt b/app-common/src/main/java/eu/darken/capod/main/core/GeneralSettings.kt index a3136f1e..f8c25125 100644 --- a/app-common/src/main/java/eu/darken/capod/main/core/GeneralSettings.kt +++ b/app-common/src/main/java/eu/darken/capod/main/core/GeneralSettings.kt @@ -30,6 +30,9 @@ class GeneralSettings @Inject constructor( val useExtraMonitorNotification = preferences.createFlowPreference("core.monitor.notification.connected", false) + val keepConnectedNotificationAfterDisconnect = + preferences.createFlowPreference("core.monitor.notification.connected.keepafterdisconnected", false) + val scannerMode = preferences.createFlowPreference("core.scanner.mode", ScannerMode.BALANCED, moshi) val showAll = preferences.createFlowPreference("core.showall.enabled", true) @@ -61,6 +64,7 @@ class GeneralSettings @Inject constructor( override val preferenceDataStore: PreferenceDataStore = PreferenceStoreMapper( monitorMode, useExtraMonitorNotification, + keepConnectedNotificationAfterDisconnect, scannerMode, showAll, minimumSignalQuality, diff --git a/app/src/main/java/eu/darken/capod/monitor/core/worker/MonitorWorker.kt b/app/src/main/java/eu/darken/capod/monitor/core/worker/MonitorWorker.kt index 5247f733..d76427d2 100644 --- a/app/src/main/java/eu/darken/capod/monitor/core/worker/MonitorWorker.kt +++ b/app/src/main/java/eu/darken/capod/monitor/core/worker/MonitorWorker.kt @@ -95,6 +95,13 @@ class MonitorWorker @AssistedInject constructor( Result.success() } } finally { + if (generalSettings.useExtraMonitorNotification.value && !generalSettings.keepConnectedNotificationAfterDisconnect.value) { + try { + notificationManager.cancel(MonitorNotifications.NOTIFICATION_ID_CONNECTED) + } catch (e: Exception) { + log(TAG, WARN) { "Failed to cancel connected notification: ${e.message}" } + } + } this.workerScope.cancel("Worker finished (withError?=$finishedWithError).") } diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 668fcf6c..66c7123f 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -20,6 +20,8 @@ Under which circumstances this app monitors Bluetooth data. Extra notification Shows an extra notification when a device is connected. This lets you hide the permanent \"No devices\" notification by disabling the \"Device status\" channel. + Keep notification after disconnect + Continue showing the last known battery levels even after your AirPods disconnect Scanner mode Should the Bluetooth Low Energy data scanner prioritize performance or conserve energy? Auto pause diff --git a/app/src/main/res/xml/preferences_general.xml b/app/src/main/res/xml/preferences_general.xml index e0a3fdd4..33e30f42 100644 --- a/app/src/main/res/xml/preferences_general.xml +++ b/app/src/main/res/xml/preferences_general.xml @@ -90,6 +90,13 @@ android:summary="@string/settings_monitor_connected_notification_description" android:title="@string/settings_monitor_connected_notification_label" /> + +