From 008520bbbf87ff519890599000bf86aa91dbc77f Mon Sep 17 00:00:00 2001 From: M66B Date: Tue, 21 May 2019 15:55:10 +0200 Subject: [PATCH] Cancel notifiation on action --- app/src/main/java/eu/faircode/email/Core.java | 16 ++++++++++++---- .../java/eu/faircode/email/ServiceUI.java | 19 +++++++++++++++++++ 2 files changed, 31 insertions(+), 4 deletions(-) diff --git a/app/src/main/java/eu/faircode/email/Core.java b/app/src/main/java/eu/faircode/email/Core.java index 0cc98b5835..e5bb6e1241 100644 --- a/app/src/main/java/eu/faircode/email/Core.java +++ b/app/src/main/java/eu/faircode/email/Core.java @@ -1964,7 +1964,9 @@ class Core { mbuilder.setGroup(group).setGroupSummary(false); if (notify_trash) { - Intent trash = new Intent(context, ServiceUI.class).setAction("trash:" + message.id); + Intent trash = new Intent(context, ServiceUI.class) + .setAction("trash:" + message.id) + .putExtra("group", group); PendingIntent piTrash = PendingIntent.getService(context, ServiceUI.PI_TRASH, trash, PendingIntent.FLAG_UPDATE_CURRENT); NotificationCompat.Action.Builder actionTrash = new NotificationCompat.Action.Builder( R.drawable.baseline_delete_24, @@ -1974,7 +1976,9 @@ class Core { } if (notify_archive) { - Intent archive = new Intent(context, ServiceUI.class).setAction("archive:" + message.id); + Intent archive = new Intent(context, ServiceUI.class) + .setAction("archive:" + message.id) + .putExtra("group", group); PendingIntent piArchive = PendingIntent.getService(context, ServiceUI.PI_ARCHIVE, archive, PendingIntent.FLAG_UPDATE_CURRENT); NotificationCompat.Action.Builder actionArchive = new NotificationCompat.Action.Builder( R.drawable.baseline_archive_24, @@ -1997,7 +2001,9 @@ class Core { } if (notify_flag && flags) { - Intent flag = new Intent(context, ServiceUI.class).setAction("flag:" + message.id); + Intent flag = new Intent(context, ServiceUI.class) + .setAction("flag:" + message.id) + .putExtra("group", group); PendingIntent piFlag = PendingIntent.getService(context, ServiceUI.PI_FLAG, flag, PendingIntent.FLAG_UPDATE_CURRENT); NotificationCompat.Action.Builder actionFlag = new NotificationCompat.Action.Builder( R.drawable.baseline_star_24, @@ -2007,7 +2013,9 @@ class Core { } if (notify_seen) { - Intent seen = new Intent(context, ServiceUI.class).setAction("seen:" + message.id); + Intent seen = new Intent(context, ServiceUI.class) + .setAction("seen:" + message.id) + .putExtra("group", group); PendingIntent piSeen = PendingIntent.getService(context, ServiceUI.PI_SEEN, seen, PendingIntent.FLAG_UPDATE_CURRENT); NotificationCompat.Action.Builder actionSeen = new NotificationCompat.Action.Builder( R.drawable.baseline_visibility_24, diff --git a/app/src/main/java/eu/faircode/email/ServiceUI.java b/app/src/main/java/eu/faircode/email/ServiceUI.java index 62df01aa21..346995cb36 100644 --- a/app/src/main/java/eu/faircode/email/ServiceUI.java +++ b/app/src/main/java/eu/faircode/email/ServiceUI.java @@ -20,6 +20,8 @@ package eu.faircode.email; */ import android.app.IntentService; +import android.app.NotificationManager; +import android.content.Context; import android.content.Intent; import android.content.SharedPreferences; @@ -78,21 +80,31 @@ public class ServiceUI extends IntentService { case "clear": onClear(); break; + case "trash": + cancel(intent.getStringExtra("group"), id); onTrash(id); break; + case "archive": + cancel(intent.getStringExtra("group"), id); onArchive(id); break; + case "flag": + cancel(intent.getStringExtra("group"), id); onFlag(id); break; + case "seen": + cancel(intent.getStringExtra("group"), id); onSeen(id); break; + case "ignore": onIgnore(id); break; + case "snooze": // AlarmManager.RTC_WAKEUP // When the alarm is dispatched, the app will also be added to the system's temporary whitelist @@ -109,6 +121,13 @@ public class ServiceUI extends IntentService { DB.getInstance(this).message().ignoreAll(); } + private void cancel(String group, long id) { + String tag = "unseen." + group + ":" + id; + + NotificationManager nm = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); + nm.cancel(tag, 1); + } + private void onTrash(long id) { DB db = DB.getInstance(this); try {