avoid some unnecessary notification updates

This commit is contained in:
Daniel Gultsch 2018-01-22 12:24:10 +01:00
parent 78c5c508b3
commit 1e0f288e6a

View file

@ -225,12 +225,11 @@ public class NotificationService {
} }
synchronized (notifications) { synchronized (notifications) {
markAsReadIfHasDirectReply(conversation); markAsReadIfHasDirectReply(conversation);
//TODO: only update if something actually got removed? if (notifications.remove(conversation.getUuid()) != null) {
notifications.remove(conversation.getUuid()); final NotificationManagerCompat notificationManager = NotificationManagerCompat.from(mXmppConnectionService);
final NotificationManagerCompat notificationManager = NotificationManagerCompat.from(mXmppConnectionService); notificationManager.cancel(conversation.getUuid(), NOTIFICATION_ID);
//TODO on later androids (that have multiple Conversations) maybe canceling is enough + update summary notification updateNotification(false, true);
notificationManager.cancel(conversation.getUuid(), NOTIFICATION_ID); }
updateNotification(false);
} }
} }
@ -254,6 +253,10 @@ public class NotificationService {
} }
public void updateNotification(final boolean notify) { public void updateNotification(final boolean notify) {
updateNotification(notify, false);
}
public void updateNotification(final boolean notify, boolean summaryOnly) {
final NotificationManagerCompat notificationManager = NotificationManagerCompat.from(mXmppConnectionService); final NotificationManagerCompat notificationManager = NotificationManagerCompat.from(mXmppConnectionService);
final SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(mXmppConnectionService); final SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(mXmppConnectionService);
@ -271,11 +274,13 @@ public class NotificationService {
} else { } else {
mBuilder = buildMultipleConversation(); mBuilder = buildMultipleConversation();
modifyForSoundVibrationAndLight(mBuilder, notify, preferences); modifyForSoundVibrationAndLight(mBuilder, notify, preferences);
for(Map.Entry<String,ArrayList<Message>> entry : notifications.entrySet()) { if (!summaryOnly) {
Builder singleBuilder = buildSingleConversations(entry.getValue()); for (Map.Entry<String, ArrayList<Message>> entry : notifications.entrySet()) {
singleBuilder.setGroup(CONVERSATIONS_GROUP); Builder singleBuilder = buildSingleConversations(entry.getValue());
setNotificationColor(singleBuilder); singleBuilder.setGroup(CONVERSATIONS_GROUP);
notificationManager.notify(entry.getKey(), NOTIFICATION_ID ,singleBuilder.build()); setNotificationColor(singleBuilder);
notificationManager.notify(entry.getKey(), NOTIFICATION_ID, singleBuilder.build());
}
} }
notificationManager.notify(NOTIFICATION_ID, mBuilder.build()); notificationManager.notify(NOTIFICATION_ID, mBuilder.build());
} }