From b1d217ed469f6215f99c5280bfaddf538f8b5446 Mon Sep 17 00:00:00 2001 From: M66B Date: Sat, 18 May 2019 21:25:46 +0200 Subject: [PATCH] Transient list of existing notifications --- app/src/main/java/eu/faircode/email/Core.java | 28 +++---------------- .../eu/faircode/email/ServiceSynchronize.java | 4 ++- 2 files changed, 7 insertions(+), 25 deletions(-) diff --git a/app/src/main/java/eu/faircode/email/Core.java b/app/src/main/java/eu/faircode/email/Core.java index 5f4187e950..ddf516f701 100644 --- a/app/src/main/java/eu/faircode/email/Core.java +++ b/app/src/main/java/eu/faircode/email/Core.java @@ -1706,12 +1706,10 @@ class Core { db.message().setMessageSize(message.id, size); } - static void notifyMessages(Context context, List messages) { + static void notifyMessages(Context context, Map> groupNotifying, List messages) { Log.i("Notify messages=" + messages.size()); SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context); - SharedPreferences.Editor editor = prefs.edit(); - boolean badge = prefs.getBoolean("badge", true); Widget.update(context, messages.size()); @@ -1723,23 +1721,8 @@ class Core { NotificationManager nm = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); - Map> groupNotifying = new HashMap<>(); Map> groupMessages = new HashMap<>(); - // Previous - for (String key : prefs.getAll().keySet()) - if (key.startsWith("notifying:")) { - String group = key.substring(key.indexOf(":") + 1); - groupNotifying.put(group, new ArrayList()); - - for (String id : prefs.getString(key, null).split(",")) - groupNotifying.get(group).add(Long.parseLong(id)); - - Log.i("Notifying " + group + "=" + TextUtils.join(",", groupNotifying.get(group))); - - editor.remove(key); - } - // Current for (TupleMessageEx message : messages) { // Check if notification channel enabled @@ -1765,13 +1748,13 @@ class Core { for (String group : groupNotifying.keySet()) { List notifications = getNotificationUnseen(context, group, groupMessages.get(group)); - List all = new ArrayList<>(); + List all = new ArrayList<>(); List add = new ArrayList<>(); List remove = groupNotifying.get(group); for (Notification notification : notifications) { Long id = notification.extras.getLong("id", 0); if (id != 0) { - all.add(Long.toString(id)); + all.add(id); if (remove.contains(id)) { remove.remove(id); Log.i("Notify existing=" + id); @@ -1815,11 +1798,8 @@ class Core { } } - if (all.size() > 0) - editor.putString("notifying:" + group, TextUtils.join(",", all)); + groupNotifying.put(group, all); } - - editor.apply(); } private static List getNotificationUnseen(Context context, String group, List messages) { diff --git a/app/src/main/java/eu/faircode/email/ServiceSynchronize.java b/app/src/main/java/eu/faircode/email/ServiceSynchronize.java index 7b4a58592c..6ca36d031f 100644 --- a/app/src/main/java/eu/faircode/email/ServiceSynchronize.java +++ b/app/src/main/java/eu/faircode/email/ServiceSynchronize.java @@ -149,9 +149,11 @@ public class ServiceSynchronize extends LifecycleService { }); db.message().liveUnseenNotify().observe(cowner, new Observer>() { + private Map> notifying = new HashMap<>(); + @Override public void onChanged(List messages) { - Core.notifyMessages(ServiceSynchronize.this, messages); + Core.notifyMessages(ServiceSynchronize.this, notifying, messages); } });