From fe8b47f64431064d611c5e7a132faaf512355e4a Mon Sep 17 00:00:00 2001 From: Marcus Wolschon Date: Sat, 2 May 2015 08:11:27 +0200 Subject: [PATCH] fixed NPE identified issue with entire stack of notifications when action on a single child-notification is used --- .../k9/controller/MessagingController.java | 34 ++++++++----------- .../k9/service/NotificationActionService.java | 2 ++ 2 files changed, 16 insertions(+), 20 deletions(-) diff --git a/k9mail/src/main/java/com/fsck/k9/controller/MessagingController.java b/k9mail/src/main/java/com/fsck/k9/controller/MessagingController.java index de4738213..c90a3d5af 100644 --- a/k9mail/src/main/java/com/fsck/k9/controller/MessagingController.java +++ b/k9mail/src/main/java/com/fsck/k9/controller/MessagingController.java @@ -222,7 +222,7 @@ public class MessagingController implements Runnable { /** * Stacked notifications that share this notification as ther summary-notification. */ - Map stackdNotifications; + Map stackedNotifications = new HashMap(); /** * List of references for messages that the user is still to be notified of, * but which don't fit into the inbox style anymore. It's sorted from newest @@ -267,47 +267,41 @@ public class MessagingController implements Runnable { /** * Add a stacked notification that this is a summary notification for. - * @param ref - * @param notificationId + * @param ref the message to add a stacked notification for + * @param notificationId the id of the stacked notification */ public void addStackedChildNotification(final MessageReference ref, final int notificationId) { - if (stackdNotifications == null) { - stackdNotifications = new HashMap(); - } - stackdNotifications.put(ref.getUid(), new Integer(notificationId)); + stackedNotifications.put(ref.getUid(), new Integer(notificationId)); } /** * Add a stacked notification that this is a summary notification for. - * @param msg - * @param notificationId + * @param msg the message to add a stacked notification for + * @param notificationId the id of the stacked notification */ public void addStackedChildNotification(final Message msg, final int notificationId) { - if (stackdNotifications == null) { - stackdNotifications = new HashMap(); - } - stackdNotifications.put(msg.getUid(), new Integer(notificationId)); + stackedNotifications.put(msg.getUid(), new Integer(notificationId)); } /** * @return the IDs of all stacked notifications this is a summary notification for. */ public Collection getStackedChildNotifications() { - return stackdNotifications.values(); + return stackedNotifications.values(); } /** - * @param ref + * @param ref the message to check for * @return null or the notification ID of a stacked notification for the given message */ public Integer getStackedChildNotification(final MessageReference ref) { - return stackdNotifications.get(ref.getUid()); + return stackedNotifications.get(ref.getUid()); } /** - * @param msg + * @param msg the message to check for * @return null or the notification ID of a stacked notification for the given message */ public Integer getStackedChildNotification(final Message msg) { - return stackdNotifications.get(msg.getUid()); + return stackedNotifications.get(msg.getUid()); } /** @@ -361,7 +355,7 @@ public class MessagingController implements Runnable { public int getNewMessageCount() { return messages.size() + droppedMessages.size(); } - }; + } // Key is accountNumber private final ConcurrentMap notificationData = new ConcurrentHashMap(); @@ -5139,7 +5133,7 @@ public class MessagingController implements Runnable { * @param builder * @param accountDescr */ - private NotificationCompat.Builder setNotificationContent(Context context, /*Local*/Message message, CharSequence sender, CharSequence subject, NotificationCompat.Builder builder, String accountDescr) { + private NotificationCompat.Builder setNotificationContent(final Context context, final Message message, final CharSequence sender, final CharSequence subject, final NotificationCompat.Builder builder, final String accountDescr) { NotificationCompat.BigTextStyle style = new NotificationCompat.BigTextStyle(builder); CharSequence preview = getMessagePreview(context, message); if (preview != null) { diff --git a/k9mail/src/main/java/com/fsck/k9/service/NotificationActionService.java b/k9mail/src/main/java/com/fsck/k9/service/NotificationActionService.java index 8dfbbbe6e..86bef2add 100644 --- a/k9mail/src/main/java/com/fsck/k9/service/NotificationActionService.java +++ b/k9mail/src/main/java/com/fsck/k9/service/NotificationActionService.java @@ -241,6 +241,8 @@ public class NotificationActionService extends CoreService { } /* there's no point in keeping the notification after the user clicked on it */ + //TODO: if this was a stacked notification on Android Wear, update the summary + // notification and keep the other stacked notifications controller.notifyAccountCancel(this, account); } else { Log.w(K9.LOG_TAG, "Could not find account for notification action.");