only alert once on multiple notifications, fix order of notifications
This commit is contained in:
parent
c2c607270a
commit
550235d40b
2 changed files with 10 additions and 7 deletions
|
@ -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<Notification> 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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Reference in a new issue