From c7e8969b01a54a74f164df747673e37af798f769 Mon Sep 17 00:00:00 2001 From: Jesse Vincent Date: Sat, 9 Jul 2011 00:27:56 -0400 Subject: [PATCH] remove a bunch of listener notification duplication that crept into the code. this caused all attachments to be double-opened, among other things --- .../k9/controller/MessagingController.java | 48 ++++--------------- 1 file changed, 9 insertions(+), 39 deletions(-) diff --git a/src/com/fsck/k9/controller/MessagingController.java b/src/com/fsck/k9/controller/MessagingController.java index 028ebfcd3..32f1486d6 100644 --- a/src/com/fsck/k9/controller/MessagingController.java +++ b/src/com/fsck/k9/controller/MessagingController.java @@ -2742,31 +2742,21 @@ public class MessagingController implements Runnable { */ if (part.getBody() != null) { - for (MessagingListener l : getListeners()) { + for (MessagingListener l : getListeners(listener)) { l.loadAttachmentStarted(account, message, part, tag, false); } - if (listener != null) { - listener.loadAttachmentStarted(account, message, part, tag, false); - } - for (MessagingListener l : getListeners()) { + for (MessagingListener l : getListeners(listener)) { l.loadAttachmentFinished(account, message, part, tag); } - - if (listener != null) { - listener.loadAttachmentFinished(account, message, part, tag); - } return; } - for (MessagingListener l : getListeners()) { + for (MessagingListener l : getListeners(listener)) { l.loadAttachmentStarted(account, message, part, tag, true); } - if (listener != null) { - listener.loadAttachmentStarted(account, message, part, tag, false); - } put("loadAttachment", listener, new Runnable() { @Override @@ -2793,22 +2783,16 @@ public class MessagingController implements Runnable { remoteFolder.fetchPart(remoteMessage, part, null); localFolder.updateMessage((LocalMessage)message); - for (MessagingListener l : getListeners()) { + for (MessagingListener l : getListeners(listener)) { l.loadAttachmentFinished(account, message, part, tag); } - if (listener != null) { - listener.loadAttachmentFinished(account, message, part, tag); - } } catch (MessagingException me) { if (K9.DEBUG) Log.v(K9.LOG_TAG, "Exception loading attachment", me); - for (MessagingListener l : getListeners()) { + for (MessagingListener l : getListeners(listener)) { l.loadAttachmentFailed(account, message, part, tag, me.getMessage()); } - if (listener != null) { - listener.loadAttachmentFailed(account, message, part, tag, me.getMessage()); - } addErrorMessage(account, null, me); } finally { @@ -3371,10 +3355,7 @@ public class MessagingController implements Runnable { //We need to make these callbacks before moving the messages to the trash //as messages get a new UID after being moved for (Message message : messages) { - if (listener != null) { - listener.messageDeleted(account, folder, message); - } - for (MessagingListener l : getListeners()) { + for (MessagingListener l : getListeners(listener)) { l.messageDeleted(account, folder, message); } } @@ -3813,10 +3794,7 @@ public class MessagingController implements Runnable { long oldSize = localStore.getSize(); localStore.compact(); long newSize = localStore.getSize(); - if (ml != null) { - ml.accountSizeChanged(account, oldSize, newSize); - } - for (MessagingListener l : getListeners()) { + for (MessagingListener l : getListeners(ml)) { l.accountSizeChanged(account, oldSize, newSize); } } catch (UnavailableStorageException e) { @@ -3843,11 +3821,7 @@ public class MessagingController implements Runnable { stats.size = newSize; stats.unreadMessageCount = 0; stats.flaggedMessageCount = 0; - if (ml != null) { - ml.accountSizeChanged(account, oldSize, newSize); - ml.accountStatusChanged(account, stats); - } - for (MessagingListener l : getListeners()) { + for (MessagingListener l : getListeners(ml)) { l.accountSizeChanged(account, oldSize, newSize); l.accountStatusChanged(account, stats); } @@ -3875,11 +3849,7 @@ public class MessagingController implements Runnable { stats.size = newSize; stats.unreadMessageCount = 0; stats.flaggedMessageCount = 0; - if (ml != null) { - ml.accountSizeChanged(account, oldSize, newSize); - ml.accountStatusChanged(account, stats); - } - for (MessagingListener l : getListeners()) { + for (MessagingListener l : getListeners(ml)) { l.accountSizeChanged(account, oldSize, newSize); l.accountStatusChanged(account, stats); }