fix #650 notifications alerting multiple times
This commit is contained in:
parent
3c569c6ac9
commit
3c685800d8
2 changed files with 9 additions and 2 deletions
|
@ -114,6 +114,7 @@ public final class NotificationPullJobCreator implements JobCreator {
|
||||||
Collections.reverse(notificationList);
|
Collections.reverse(notificationList);
|
||||||
BigInteger newId = new BigInteger(account.getLastNotificationId());
|
BigInteger newId = new BigInteger(account.getLastNotificationId());
|
||||||
BigInteger newestId = BigInteger.ZERO;
|
BigInteger newestId = BigInteger.ZERO;
|
||||||
|
boolean isFirstOfBatch = true;
|
||||||
|
|
||||||
for (Notification notification : notificationList) {
|
for (Notification notification : notificationList) {
|
||||||
BigInteger currentId = new BigInteger(notification.getId());
|
BigInteger currentId = new BigInteger(notification.getId());
|
||||||
|
@ -122,7 +123,8 @@ public final class NotificationPullJobCreator implements JobCreator {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isBiggerThan(currentId, newId)) {
|
if (isBiggerThan(currentId, newId)) {
|
||||||
NotificationHelper.make(context, notification, account);
|
NotificationHelper.make(context, notification, account, isFirstOfBatch);
|
||||||
|
isFirstOfBatch = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -112,7 +112,7 @@ public class NotificationHelper {
|
||||||
* @param account the account for which the notification should be shown
|
* @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)) {
|
if (!filterNotification(account, body, context)) {
|
||||||
return;
|
return;
|
||||||
|
@ -203,6 +203,11 @@ public class NotificationHelper {
|
||||||
builder.setCategory(NotificationCompat.CATEGORY_SOCIAL);
|
builder.setCategory(NotificationCompat.CATEGORY_SOCIAL);
|
||||||
builder.setOnlyAlertOnce(true);
|
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
|
// Summary
|
||||||
// =======
|
// =======
|
||||||
final NotificationCompat.Builder summaryBuilder = newNotification(context, body, account, true);
|
final NotificationCompat.Builder summaryBuilder = newNotification(context, body, account, true);
|
||||||
|
|
Loading…
Reference in a new issue