Cancel notifiation on action

pull/156/head
M66B 6 years ago
parent bc42de39ed
commit 008520bbbf

@ -1964,7 +1964,9 @@ class Core {
mbuilder.setGroup(group).setGroupSummary(false); mbuilder.setGroup(group).setGroupSummary(false);
if (notify_trash) { 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); PendingIntent piTrash = PendingIntent.getService(context, ServiceUI.PI_TRASH, trash, PendingIntent.FLAG_UPDATE_CURRENT);
NotificationCompat.Action.Builder actionTrash = new NotificationCompat.Action.Builder( NotificationCompat.Action.Builder actionTrash = new NotificationCompat.Action.Builder(
R.drawable.baseline_delete_24, R.drawable.baseline_delete_24,
@ -1974,7 +1976,9 @@ class Core {
} }
if (notify_archive) { 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); PendingIntent piArchive = PendingIntent.getService(context, ServiceUI.PI_ARCHIVE, archive, PendingIntent.FLAG_UPDATE_CURRENT);
NotificationCompat.Action.Builder actionArchive = new NotificationCompat.Action.Builder( NotificationCompat.Action.Builder actionArchive = new NotificationCompat.Action.Builder(
R.drawable.baseline_archive_24, R.drawable.baseline_archive_24,
@ -1997,7 +2001,9 @@ class Core {
} }
if (notify_flag && flags) { 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); PendingIntent piFlag = PendingIntent.getService(context, ServiceUI.PI_FLAG, flag, PendingIntent.FLAG_UPDATE_CURRENT);
NotificationCompat.Action.Builder actionFlag = new NotificationCompat.Action.Builder( NotificationCompat.Action.Builder actionFlag = new NotificationCompat.Action.Builder(
R.drawable.baseline_star_24, R.drawable.baseline_star_24,
@ -2007,7 +2013,9 @@ class Core {
} }
if (notify_seen) { 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); PendingIntent piSeen = PendingIntent.getService(context, ServiceUI.PI_SEEN, seen, PendingIntent.FLAG_UPDATE_CURRENT);
NotificationCompat.Action.Builder actionSeen = new NotificationCompat.Action.Builder( NotificationCompat.Action.Builder actionSeen = new NotificationCompat.Action.Builder(
R.drawable.baseline_visibility_24, R.drawable.baseline_visibility_24,

@ -20,6 +20,8 @@ package eu.faircode.email;
*/ */
import android.app.IntentService; import android.app.IntentService;
import android.app.NotificationManager;
import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.content.SharedPreferences; import android.content.SharedPreferences;
@ -78,21 +80,31 @@ public class ServiceUI extends IntentService {
case "clear": case "clear":
onClear(); onClear();
break; break;
case "trash": case "trash":
cancel(intent.getStringExtra("group"), id);
onTrash(id); onTrash(id);
break; break;
case "archive": case "archive":
cancel(intent.getStringExtra("group"), id);
onArchive(id); onArchive(id);
break; break;
case "flag": case "flag":
cancel(intent.getStringExtra("group"), id);
onFlag(id); onFlag(id);
break; break;
case "seen": case "seen":
cancel(intent.getStringExtra("group"), id);
onSeen(id); onSeen(id);
break; break;
case "ignore": case "ignore":
onIgnore(id); onIgnore(id);
break; break;
case "snooze": case "snooze":
// AlarmManager.RTC_WAKEUP // AlarmManager.RTC_WAKEUP
// When the alarm is dispatched, the app will also be added to the system's temporary whitelist // 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(); 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) { private void onTrash(long id) {
DB db = DB.getInstance(this); DB db = DB.getInstance(this);
try { try {

Loading…
Cancel
Save