From d28cff478cf9056b1d5bb21909c246422a558bd7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Rebelo?= Date: Sun, 10 Dec 2023 17:28:15 +0000 Subject: [PATCH] Delete notifications from connected devices only --- .../externalevents/NotificationListener.java | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/externalevents/NotificationListener.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/externalevents/NotificationListener.java index e9fbfb2f4..191dba293 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/externalevents/NotificationListener.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/externalevents/NotificationListener.java @@ -774,17 +774,18 @@ public class NotificationListener extends NotificationListenerService { // Clean up removed notifications from internal list notificationsActive.removeAll(notificationsToRemove); - // TODO prevent this from being called multiple times for the same ID - // TODO prevent this from being called form notifications removed from the device - // Send notification remove request to device - List devices = GBApplication.app().getDeviceManager().getDevices(); + List devices = GBApplication.app().getDeviceManager().getSelectedDevices(); for (GBDevice device : devices) { + if (!device.isInitialized()) { + continue; + } + Prefs devicePrefs = new Prefs(GBApplication.getDeviceSpecificSharedPrefs(device.getAddress())); if (devicePrefs.getBoolean("autoremove_notifications", true)) { for (int id : notificationsToRemove) { - LOG.info("Notification " + id + " removed, will ask device to delete it"); - GBApplication.deviceService().onDeleteNotification(id); + LOG.info("Notification {} removed, deleting from {}", id, device.getAliasOrName()); + GBApplication.deviceService(device).onDeleteNotification(id); } } }