From 2c739c5f96e613fc49aa202fa7037e07912d74b1 Mon Sep 17 00:00:00 2001 From: Christian Schneppe Date: Sat, 27 Jan 2018 21:34:29 +0100 Subject: avoid some unnecessary notification updates --- .../messenger/services/NotificationService.java | 27 +++++++++++++--------- 1 file changed, 16 insertions(+), 11 deletions(-) (limited to 'src') diff --git a/src/main/java/de/pixart/messenger/services/NotificationService.java b/src/main/java/de/pixart/messenger/services/NotificationService.java index 5d33e2b27..985af31c2 100644 --- a/src/main/java/de/pixart/messenger/services/NotificationService.java +++ b/src/main/java/de/pixart/messenger/services/NotificationService.java @@ -235,10 +235,11 @@ public class NotificationService { } synchronized (notifications) { markAsReadIfHasDirectReply(conversation); - notifications.remove(conversation.getUuid()); - final NotificationManagerCompat notificationManager = NotificationManagerCompat.from(mXmppConnectionService); - notificationManager.cancel(conversation.getUuid(), NOTIFICATION_ID); - updateNotification(false); + if (notifications.remove(conversation.getUuid()) != null) { + final NotificationManagerCompat notificationManager = NotificationManagerCompat.from(mXmppConnectionService); + notificationManager.cancel(conversation.getUuid(), NOTIFICATION_ID); + updateNotification(false, true); + } } } @@ -262,6 +263,10 @@ public class NotificationService { } public void updateNotification(final boolean notify) { + updateNotification(notify, false); + } + + public void updateNotification(final boolean notify, boolean summaryOnly) { final NotificationManagerCompat notificationManager = NotificationManagerCompat.from(mXmppConnectionService); final SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(mXmppConnectionService); @@ -273,19 +278,19 @@ public class NotificationService { } final Builder mBuilder; if (notifications.size() == 1 && Build.VERSION.SDK_INT < Build.VERSION_CODES.N) { - Log.d(Config.LOGTAG, "Notification: Received 1 single notification and using device < Android N"); mBuilder = buildSingleConversations(notifications.values().iterator().next()); modifyForSoundVibrationAndLight(mBuilder, notify, preferences); notificationManager.notify(NOTIFICATION_ID, mBuilder.build()); } else { - Log.d(Config.LOGTAG, "Notification: Received multiple notification or using Android N"); mBuilder = buildMultipleConversation(); modifyForSoundVibrationAndLight(mBuilder, notify, preferences); - for (Map.Entry> entry : notifications.entrySet()) { - Builder singleBuilder = buildSingleConversations(entry.getValue()); - singleBuilder.setGroup(CONVERSATIONS_GROUP); - setNotificationColor(singleBuilder); - notificationManager.notify(entry.getKey(), NOTIFICATION_ID, singleBuilder.build()); + if (!summaryOnly) { + for (Map.Entry> entry : notifications.entrySet()) { + Builder singleBuilder = buildSingleConversations(entry.getValue()); + singleBuilder.setGroup(CONVERSATIONS_GROUP); + setNotificationColor(singleBuilder); + notificationManager.notify(entry.getKey(), NOTIFICATION_ID, singleBuilder.build()); + } } notificationManager.notify(NOTIFICATION_ID, mBuilder.build()); } -- cgit v1.2.3