From ef93f0af6c5a809917d0a39f7380fbbbe9af7c1d Mon Sep 17 00:00:00 2001 From: Danny Baumann Date: Sat, 5 Jan 2013 14:10:07 +0100 Subject: [PATCH] Directly go to message when clicking on a single-message notification. --- src/com/fsck/k9/activity/MessageList.java | 3 +- src/com/fsck/k9/activity/MessageView.java | 16 +++++++---- .../k9/controller/MessagingController.java | 28 ++++++++++++------- 3 files changed, 30 insertions(+), 17 deletions(-) diff --git a/src/com/fsck/k9/activity/MessageList.java b/src/com/fsck/k9/activity/MessageList.java index 54d65d6f9..c3cf7d20c 100644 --- a/src/com/fsck/k9/activity/MessageList.java +++ b/src/com/fsck/k9/activity/MessageList.java @@ -586,7 +586,8 @@ public class MessageList extends K9FragmentActivity implements MessageListFragme Log.i(K9.LOG_TAG, "MessageList sending message " + messageReference); - MessageView.actionView(this, messageReference, messageRefs, getIntent().getExtras()); + Intent i = MessageView.actionView(this, messageReference, messageRefs); + startActivity(i); } /* diff --git a/src/com/fsck/k9/activity/MessageView.java b/src/com/fsck/k9/activity/MessageView.java index 760e37fac..240ab0378 100644 --- a/src/com/fsck/k9/activity/MessageView.java +++ b/src/com/fsck/k9/activity/MessageView.java @@ -41,7 +41,6 @@ public class MessageView extends K9FragmentActivity implements MessageViewFragme private static final String EXTRA_MESSAGE_REFERENCE = "com.fsck.k9.MessageView_messageReference"; private static final String EXTRA_MESSAGE_REFERENCES = "com.fsck.k9.MessageView_messageReferences"; - private static final String EXTRA_MESSAGE_LIST_EXTRAS = "com.fsck.k9.MessageView_messageListExtras"; /** * @see #mLastDirection @@ -50,14 +49,13 @@ public class MessageView extends K9FragmentActivity implements MessageViewFragme private static final int NEXT = 2; - public static void actionView(Context context, MessageReference messRef, - ArrayList messReferences, Bundle messageListExtras) { + public static Intent actionView(Context context, MessageReference messRef, + ArrayList messReferences) { Intent i = new Intent(context, MessageView.class); i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); - i.putExtra(EXTRA_MESSAGE_LIST_EXTRAS, messageListExtras); i.putExtra(EXTRA_MESSAGE_REFERENCE, messRef); i.putParcelableArrayListExtra(EXTRA_MESSAGE_REFERENCES, messReferences); - context.startActivity(i); + return i; } @@ -438,7 +436,9 @@ public class MessageView extends K9FragmentActivity implements MessageViewFragme private void showNextMessage() { findSurroundingMessagesUid(); - mMessageReferences.remove(mMessageReference); + if (mMessageReferences == null) { + mMessageReferences.remove(mMessageReference); + } if (mLastDirection == NEXT && mNextMessage != null) { onNext(); } else if (mLastDirection == PREVIOUS && mPreviousMessage != null) { @@ -491,6 +491,10 @@ public class MessageView extends K9FragmentActivity implements MessageViewFragme private void findSurroundingMessagesUid() { mNextMessage = mPreviousMessage = null; + if (mMessageReferences == null) { + return; + } + int i = mMessageReferences.indexOf(mMessageReference); if (i < 0) { return; diff --git a/src/com/fsck/k9/controller/MessagingController.java b/src/com/fsck/k9/controller/MessagingController.java index 907571309..47a1a8f4e 100644 --- a/src/com/fsck/k9/controller/MessagingController.java +++ b/src/com/fsck/k9/controller/MessagingController.java @@ -50,6 +50,7 @@ import com.fsck.k9.R; import com.fsck.k9.activity.FolderList; import com.fsck.k9.activity.MessageList; import com.fsck.k9.activity.MessageReference; +import com.fsck.k9.activity.MessageView; import com.fsck.k9.activity.NotificationDeleteConfirmation; import com.fsck.k9.helper.Contacts; import com.fsck.k9.helper.HtmlConverter; @@ -4692,14 +4693,6 @@ public class MessagingController implements Runnable { builder.setContentText(summary); } - String initialFolder = message.getFolder().getName(); - /* only go to folder if all messages are in the same folder, else go to folder list */ - for (MessageReference ref : allRefs) { - if (!TextUtils.equals(initialFolder, ref.folderName)) { - initialFolder = null; - break; - } - } for (Message m : data.messages) { if (m.isSet(Flag.FLAGGED)) { builder.setPriority(NotificationCompat.PRIORITY_HIGH); @@ -4707,8 +4700,23 @@ public class MessagingController implements Runnable { } } - Intent i = FolderList.actionHandleNotification(context, account, initialFolder); - PendingIntent pi = PendingIntent.getActivity(context, 0, i, PendingIntent.FLAG_UPDATE_CURRENT); + Intent targetIntent; + + if (unreadCount == 1) { + targetIntent = MessageView.actionView(context, message.makeMessageReference(), null); + } else { + String initialFolder = message.getFolder().getName(); + /* only go to folder if all messages are in the same folder, else go to folder list */ + for (MessageReference ref : allRefs) { + if (!TextUtils.equals(initialFolder, ref.folderName)) { + initialFolder = null; + break; + } + } + + targetIntent = FolderList.actionHandleNotification(context, account, initialFolder); + } + PendingIntent pi = PendingIntent.getActivity(context, 0, targetIntent, PendingIntent.FLAG_UPDATE_CURRENT); builder.setContentIntent(pi); // Only ring or vibrate if we have not done so already on this account and fetch