Clear group

This commit is contained in:
M66B 2019-09-01 11:32:18 +02:00
parent d11684c5aa
commit 8d426f747b
4 changed files with 20 additions and 17 deletions

View File

@ -1922,7 +1922,7 @@ class Core {
}
}
static void notifyMessages(Context context, List<TupleMessageEx> messages, Map<String, List<Long>> groupNotifying) {
static void notifyMessages(Context context, List<TupleMessageEx> messages, Map<Long, List<Long>> groupNotifying) {
if (messages == null)
messages = new ArrayList<>();
Log.i("Notify messages=" + messages.size());
@ -1937,8 +1937,8 @@ class Core {
boolean pro = ActivityBilling.isPro(context);
int unseen = 0;
Map<String, List<TupleMessageEx>> groupMessages = new HashMap<>();
for (String group : groupNotifying.keySet())
Map<Long, List<TupleMessageEx>> groupMessages = new HashMap<>();
for (long group : groupNotifying.keySet())
groupMessages.put(group, new ArrayList<>());
// Current
@ -1955,7 +1955,7 @@ class Core {
continue;
}
String group = Long.toString(pro && message.accountNotify ? message.account : 0);
long group = (pro && message.accountNotify ? message.account : 0);
if (!groupMessages.containsKey(group)) {
groupNotifying.put(group, new ArrayList<Long>());
groupMessages.put(group, new ArrayList<TupleMessageEx>());
@ -1986,7 +1986,7 @@ class Core {
}
// Difference
for (String group : groupMessages.keySet()) {
for (long group : groupMessages.keySet()) {
// Difference
final List<Long> add = new ArrayList<>();
final List<Long> remove = new ArrayList<>(groupNotifying.get(group));
@ -2051,7 +2051,7 @@ class Core {
groupNotifying.clear();
}
private static List<Notification> getNotificationUnseen(Context context, String group, List<TupleMessageEx> messages) {
private static List<Notification> getNotificationUnseen(Context context, long group, List<TupleMessageEx> messages) {
List<Notification> notifications = new ArrayList<>();
// Android 7+ N https://developer.android.com/training/notify-user/group
@ -2088,7 +2088,7 @@ class Core {
Intent summary = new Intent(context, ActivityView.class).setAction("unified");
PendingIntent piSummary = PendingIntent.getActivity(context, ActivityView.REQUEST_UNIFIED, summary, PendingIntent.FLAG_UPDATE_CURRENT);
Intent clear = new Intent(context, ServiceUI.class).setAction("clear");
Intent clear = new Intent(context, ServiceUI.class).setAction("clear:" + group);
PendingIntent piClear = PendingIntent.getService(context, ServiceUI.PI_CLEAR, clear, PendingIntent.FLAG_UPDATE_CURRENT);
// Build title
@ -2107,7 +2107,7 @@ class Core {
.setPriority(NotificationCompat.PRIORITY_DEFAULT)
.setCategory(NotificationCompat.CATEGORY_STATUS)
.setVisibility(NotificationCompat.VISIBILITY_PUBLIC)
.setGroup(group)
.setGroup(Long.toString(group))
.setGroupSummary(true)
.setGroupAlertBehavior(NotificationCompat.GROUP_ALERT_CHILDREN);
@ -2192,7 +2192,7 @@ class Core {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N)
mbuilder
.setGroup(group)
.setGroup(Long.toString(group))
.setGroupSummary(false)
.setGroupAlertBehavior(NotificationCompat.GROUP_ALERT_CHILDREN);

View File

@ -427,9 +427,10 @@ public interface DaoMessage {
int setMessageLastAttempt(long id, long last_attempt);
@Query("UPDATE message SET ui_ignored = 1" +
" WHERE NOT ui_ignored" +
" AND folder IN (SELECT id FROM folder WHERE type = '" + EntityFolder.INBOX + "')")
int ignoreAll();
" WHERE (:account IS NULL OR account = :account)" +
" AND NOT ui_ignored" +
" AND folder IN (SELECT id FROM folder WHERE folder.unified)")
int ignoreAll(Long account);
@Query("UPDATE message SET ui_found = 1" +
" WHERE account = :account" +

View File

@ -165,7 +165,7 @@ public class ServiceSynchronize extends ServiceBase {
}
});
Map<String, List<Long>> groupNotifying = new HashMap<>();
Map<Long, List<Long>> groupNotifying = new HashMap<>();
// Get existing notifications
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
@ -174,7 +174,7 @@ public class ServiceSynchronize extends ServiceBase {
String tag = sbn.getTag();
if (tag != null && tag.startsWith("unseen.")) {
String[] p = tag.split(("\\."));
String group = p[1];
long group = Long.parseLong(p[1]);
long id = Long.parseLong(p[2]);
if (!groupNotifying.containsKey(group))

View File

@ -91,7 +91,7 @@ public class ServiceUI extends IntentService {
switch (parts[0]) {
case "clear":
onClear();
onClear(id);
break;
case "trash":
@ -139,8 +139,10 @@ public class ServiceUI extends IntentService {
}
}
private void onClear() {
DB.getInstance(this).message().ignoreAll();
private void onClear(long group) {
DB db = DB.getInstance(this);
int cleared = db.message().ignoreAll(group == 0 ? null : group);
Log.i("Cleared=" + cleared);
}
private void cancel(String group, long id) {