From 03d8ec3a7a59b8a7a9f09d4581d3dc24ba4f620e Mon Sep 17 00:00:00 2001 From: Conny Duck Date: Thu, 1 Mar 2018 19:05:47 +0100 Subject: [PATCH] only alert once on multiple notifications, fix order of notifications --- .../tusky/NotificationPullJobCreator.java | 5 +++-- .../keylesspalace/tusky/util/NotificationHelper.java | 12 +++++++----- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/app/src/main/java/com/keylesspalace/tusky/NotificationPullJobCreator.java b/app/src/main/java/com/keylesspalace/tusky/NotificationPullJobCreator.java index 0561fda1..6056ce58 100644 --- a/app/src/main/java/com/keylesspalace/tusky/NotificationPullJobCreator.java +++ b/app/src/main/java/com/keylesspalace/tusky/NotificationPullJobCreator.java @@ -36,6 +36,7 @@ import com.keylesspalace.tusky.util.OkHttpUtils; import java.io.IOException; import java.math.BigInteger; import java.util.ArrayList; +import java.util.Collections; import java.util.List; import okhttp3.OkHttpClient; @@ -129,6 +130,8 @@ public final class NotificationPullJobCreator implements JobCreator { private void onNotificationsReceived(AccountEntity account, List notificationList) { + Collections.reverse(notificationList); + BigInteger newId = new BigInteger(account.getLastNotificationId()); BigInteger newestId = BigInteger.ZERO; @@ -142,8 +145,6 @@ public final class NotificationPullJobCreator implements JobCreator { } if (isBiggerThan(currentId, newId)) { - account.setLastNotificationId(notification.id); - NotificationHelper.make(context, notification, account); } } 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 ef0cda87..24209ab0 100644 --- a/app/src/main/java/com/keylesspalace/tusky/util/NotificationHelper.java +++ b/app/src/main/java/com/keylesspalace/tusky/util/NotificationHelper.java @@ -152,8 +152,7 @@ public class NotificationHelper { } else { try { - String format = context.getString(R.string.notification_title_summary); - String title = String.format(format, currentNotifications.length()); + String title = context.getString(R.string.notification_title_summary, currentNotifications.length()); String text = joinNames(context, currentNotifications); builder.setContentTitle(title) .setContentText(text); @@ -167,6 +166,8 @@ public class NotificationHelper { builder.setVisibility(NotificationCompat.VISIBILITY_PRIVATE); builder.setCategory(NotificationCompat.CATEGORY_SOCIAL); + builder.setOnlyAlertOnce(true); + NotificationManager notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); //noinspection ConstantConditions @@ -351,14 +352,15 @@ public class NotificationHelper { @Nullable private static String joinNames(Context context, JSONArray array) throws JSONException { if (array.length() > 3) { + int length = array.length(); return String.format(context.getString(R.string.notification_summary_large), - array.get(0), array.get(1), array.get(2), array.length() - 3); + array.get(length-1), array.get(length-2), array.get(length-3), length - 3); } else if (array.length() == 3) { return String.format(context.getString(R.string.notification_summary_medium), - array.get(0), array.get(1), array.get(2)); + array.get(2), array.get(1), array.get(0)); } else if (array.length() == 2) { return String.format(context.getString(R.string.notification_summary_small), - array.get(0), array.get(1)); + array.get(1), array.get(0)); } return null;