diff options
author | Christian Schneppe <christian@pix-art.de> | 2018-01-27 21:34:29 +0100 |
---|---|---|
committer | Christian Schneppe <christian@pix-art.de> | 2018-01-27 21:34:29 +0100 |
commit | 2c739c5f96e613fc49aa202fa7037e07912d74b1 (patch) | |
tree | da7eb4a97f8897f2aba4c43860a212f09be4af58 /src/main/java/de | |
parent | 824ec7efe93b33fd825c67715b02ee16515b17cb (diff) |
avoid some unnecessary notification updates
Diffstat (limited to 'src/main/java/de')
-rw-r--r-- | src/main/java/de/pixart/messenger/services/NotificationService.java | 27 |
1 files changed, 16 insertions, 11 deletions
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<String, ArrayList<Message>> 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<String, ArrayList<Message>> 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()); } |