Transient list of existing notifications

This commit is contained in:
M66B 2019-05-18 21:25:46 +02:00
parent 5b63787742
commit b1d217ed46
2 changed files with 7 additions and 25 deletions

View File

@ -1706,12 +1706,10 @@ class Core {
db.message().setMessageSize(message.id, size);
}
static void notifyMessages(Context context, List<TupleMessageEx> messages) {
static void notifyMessages(Context context, Map<String, List<Long>> groupNotifying, List<TupleMessageEx> 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<String, List<Long>> groupNotifying = new HashMap<>();
Map<String, List<TupleMessageEx>> 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<Long>());
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<Notification> notifications = getNotificationUnseen(context, group, groupMessages.get(group));
List<String> all = new ArrayList<>();
List<Long> all = new ArrayList<>();
List<Long> add = new ArrayList<>();
List<Long> 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<Notification> getNotificationUnseen(Context context, String group, List<TupleMessageEx> messages) {

View File

@ -149,9 +149,11 @@ public class ServiceSynchronize extends LifecycleService {
});
db.message().liveUnseenNotify().observe(cowner, new Observer<List<TupleMessageEx>>() {
private Map<String, List<Long>> notifying = new HashMap<>();
@Override
public void onChanged(List<TupleMessageEx> messages) {
Core.notifyMessages(ServiceSynchronize.this, messages);
Core.notifyMessages(ServiceSynchronize.this, notifying, messages);
}
});