From 7e1e38189d4f0895abb8c626231cfa0c774c838b Mon Sep 17 00:00:00 2001 From: Danny Baumann Date: Mon, 7 Jan 2013 09:12:07 +0100 Subject: [PATCH] Reset list of unseen messages when the user clears the notification. --- .../k9/controller/MessagingController.java | 1 + .../k9/service/NotificationActionService.java | 19 ++++++++++++++++--- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/src/com/fsck/k9/controller/MessagingController.java b/src/com/fsck/k9/controller/MessagingController.java index 00a6e84c2..f02f674c5 100644 --- a/src/com/fsck/k9/controller/MessagingController.java +++ b/src/com/fsck/k9/controller/MessagingController.java @@ -4730,6 +4730,7 @@ public class MessagingController implements Runnable { PendingIntent pi = PendingIntent.getActivity(context, 0, targetIntent, PendingIntent.FLAG_UPDATE_CURRENT); builder.setContentIntent(pi); + builder.setDeleteIntent(NotificationActionService.getAcknowledgeIntent(context, account)); // Only ring or vibrate if we have not done so already on this account and fetch boolean ringAndVibrate = false; diff --git a/src/com/fsck/k9/service/NotificationActionService.java b/src/com/fsck/k9/service/NotificationActionService.java index 95971f36f..698ff53b2 100644 --- a/src/com/fsck/k9/service/NotificationActionService.java +++ b/src/com/fsck/k9/service/NotificationActionService.java @@ -22,6 +22,7 @@ public class NotificationActionService extends CoreService { private final static String REPLY_ACTION = "com.fsck.k9.service.NotificationActionService.REPLY_ACTION"; private final static String READ_ALL_ACTION = "com.fsck.k9.service.NotificationActionService.READ_ALL_ACTION"; private final static String DELETE_ALL_ACTION = "com.fsck.k9.service.NotificationActionService.DELETE_ALL_ACTION"; + private final static String ACKNOWLEDGE_ACTION = "com.fsck.k9.service.NotificationActionService.ACKNOWLEDGE_ACTION"; private final static String EXTRA_ACCOUNT = "account"; private final static String EXTRA_MESSAGE = "message"; @@ -46,6 +47,14 @@ public class NotificationActionService extends CoreService { return PendingIntent.getService(context, account.getAccountNumber(), i, PendingIntent.FLAG_UPDATE_CURRENT); } + public static PendingIntent getAcknowledgeIntent(Context context, final Account account) { + Intent i = new Intent(context, NotificationActionService.class); + i.putExtra(EXTRA_ACCOUNT, account.getUuid()); + i.setAction(ACKNOWLEDGE_ACTION); + + return PendingIntent.getService(context, account.getAccountNumber(), i, PendingIntent.FLAG_UPDATE_CURRENT); + } + public static Intent getDeleteAllMessagesIntent(Context context, final Account account, final ArrayList refs) { Intent i = new Intent(context, NotificationActionService.class); @@ -63,9 +72,10 @@ public class NotificationActionService extends CoreService { final Preferences preferences = Preferences.getPreferences(this); final MessagingController controller = MessagingController.getInstance(getApplication()); final Account account = preferences.getAccount(intent.getStringExtra(EXTRA_ACCOUNT)); + final String action = intent.getAction(); if (account != null) { - if (READ_ALL_ACTION.equals(intent.getAction())) { + if (READ_ALL_ACTION.equals(action)) { if (K9.DEBUG) Log.i(K9.LOG_TAG, "NotificationActionService marking messages as read"); @@ -74,7 +84,7 @@ public class NotificationActionService extends CoreService { for (MessageReference ref : refs) { controller.setFlag(account, ref.folderName, ref.uid, Flag.SEEN, true); } - } else if (DELETE_ALL_ACTION.equals(intent.getAction())) { + } else if (DELETE_ALL_ACTION.equals(action)) { if (K9.DEBUG) Log.i(K9.LOG_TAG, "NotificationActionService deleting messages"); @@ -90,7 +100,7 @@ public class NotificationActionService extends CoreService { } controller.deleteMessages(messages, null); - } else if (REPLY_ACTION.equals(intent.getAction())) { + } else if (REPLY_ACTION.equals(action)) { if (K9.DEBUG) Log.i(K9.LOG_TAG, "NotificationActionService initiating reply"); @@ -103,6 +113,9 @@ public class NotificationActionService extends CoreService { } else { Log.i(K9.LOG_TAG, "Could not execute reply action."); } + } else if (ACKNOWLEDGE_ACTION.equals(action)) { + // nothing to do here, we just want to cancel the notification so the list + // of unseen messages is reset } /* there's no point in keeping the notification after the user clicked on it */