From 6d9adf1ba4afa602926147ec69da01bf6826aefa Mon Sep 17 00:00:00 2001 From: Christian Schneppe Date: Wed, 31 Aug 2016 21:37:19 +0200 Subject: fix multiple notifications and added unread messages as summary --- .../messenger/services/NotificationService.java | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) (limited to 'src/main/java/de/pixart/messenger/services') diff --git a/src/main/java/de/pixart/messenger/services/NotificationService.java b/src/main/java/de/pixart/messenger/services/NotificationService.java index c2e62fbd6..9c5f46282 100644 --- a/src/main/java/de/pixart/messenger/services/NotificationService.java +++ b/src/main/java/de/pixart/messenger/services/NotificationService.java @@ -159,6 +159,7 @@ public class NotificationService { } if (this.mIsInForeground && isScreenOn) { mXmppConnectionService.vibrate(); + return; } synchronized (notifications) { pushToStack(message); @@ -223,20 +224,26 @@ 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); notificationManager.notify(NOTIFICATION_ID, mBuilder.build()); - for(Map.Entry> entry : notifications.entrySet()) { - Builder singleBuilder = buildSingleConversations(entry.getValue()); - singleBuilder.setGroup(CONVERSATIONS_GROUP); - modifyForSoundVibrationAndLight(singleBuilder,notify,preferences); - notificationManager.notify(entry.getKey(), NOTIFICATION_ID ,singleBuilder.build()); - } + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { + for (Map.Entry> entry : notifications.entrySet()) { + Log.d(Config.LOGTAG, "Notification: Received notification for Android N"); + Builder singleBuilder = buildSingleConversations(entry.getValue()); + singleBuilder.setGroup(CONVERSATIONS_GROUP); + modifyForSoundVibrationAndLight(singleBuilder, notify, preferences); + notificationManager.notify(entry.getKey(), NOTIFICATION_ID, singleBuilder.build()); + } + } } + mBuilder.setNumber(mXmppConnectionService.unreadCount()); } } @@ -269,10 +276,13 @@ public class NotificationService { final Builder mBuilder = new NotificationCompat.Builder( mXmppConnectionService); final NotificationCompat.InboxStyle style = new NotificationCompat.InboxStyle(); + Integer Unread = mXmppConnectionService.unreadCount(); + String SummaryText = mXmppConnectionService.getString(R.string.unread_messages) + " " + Unread.toString(); style.setBigContentTitle(notifications.size() + " " + mXmppConnectionService .getString(R.string.unread_conversations)); + style.setSummaryText(SummaryText); final StringBuilder names = new StringBuilder(); Conversation conversation = null; for (final ArrayList messages : notifications.values()) { -- cgit v1.2.3