From 3c685800d8dc26ab634168dcb3a14fa174c42c48 Mon Sep 17 00:00:00 2001 From: Conny Duck Date: Mon, 25 Jun 2018 14:08:36 +0200 Subject: [PATCH] fix #650 notifications alerting multiple times --- .../keylesspalace/tusky/NotificationPullJobCreator.java | 4 +++- .../com/keylesspalace/tusky/util/NotificationHelper.java | 7 ++++++- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/com/keylesspalace/tusky/NotificationPullJobCreator.java b/app/src/main/java/com/keylesspalace/tusky/NotificationPullJobCreator.java index 77ea5274..0174d27c 100644 --- a/app/src/main/java/com/keylesspalace/tusky/NotificationPullJobCreator.java +++ b/app/src/main/java/com/keylesspalace/tusky/NotificationPullJobCreator.java @@ -114,6 +114,7 @@ public final class NotificationPullJobCreator implements JobCreator { Collections.reverse(notificationList); BigInteger newId = new BigInteger(account.getLastNotificationId()); BigInteger newestId = BigInteger.ZERO; + boolean isFirstOfBatch = true; for (Notification notification : notificationList) { BigInteger currentId = new BigInteger(notification.getId()); @@ -122,7 +123,8 @@ public final class NotificationPullJobCreator implements JobCreator { } if (isBiggerThan(currentId, newId)) { - NotificationHelper.make(context, notification, account); + NotificationHelper.make(context, notification, account, isFirstOfBatch); + isFirstOfBatch = false; } } diff --git a/app/src/main/java/com/keylesspalace/tusky/util/NotificationHelper.java b/app/src/main/java/com/keylesspalace/tusky/util/NotificationHelper.java index ae986192..4875eedd 100644 --- a/app/src/main/java/com/keylesspalace/tusky/util/NotificationHelper.java +++ b/app/src/main/java/com/keylesspalace/tusky/util/NotificationHelper.java @@ -112,7 +112,7 @@ public class NotificationHelper { * @param account the account for which the notification should be shown */ - public static void make(final Context context, Notification body, AccountEntity account) { + public static void make(final Context context, Notification body, AccountEntity account, boolean isFirstOfBatch) { if (!filterNotification(account, body, context)) { return; @@ -203,6 +203,11 @@ public class NotificationHelper { builder.setCategory(NotificationCompat.CATEGORY_SOCIAL); builder.setOnlyAlertOnce(true); + // only alert for the first notification of a batch to avoid multiple alerts at once + if(!isFirstOfBatch) { + builder.setGroupAlertBehavior(NotificationCompat.GROUP_ALERT_SUMMARY); + } + // Summary // ======= final NotificationCompat.Builder summaryBuilder = newNotification(context, body, account, true);