From f4378923488abcb4422253cf2e7a9c9d244d1b96 Mon Sep 17 00:00:00 2001 From: Todd Kennedy Date: Fri, 13 May 2011 08:41:48 -0700 Subject: [PATCH] Open message if only one message in notification If there is only one unread&unseen message in the notification, clicking the notification will automatically open the message view fragment. Otherwise, the message list fragment will be opened. Change-Id: I22778258836a36f289d71b99a6214ec82778f385 --- src/com/android/email/NotificationController.java | 12 ++++++++---- .../android/email/NotificationControllerTest.java | 6 +++--- 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/src/com/android/email/NotificationController.java b/src/com/android/email/NotificationController.java index 178b3d3b6..7c6dad272 100644 --- a/src/com/android/email/NotificationController.java +++ b/src/com/android/email/NotificationController.java @@ -369,7 +369,7 @@ public class NotificationController { * NOTE: DO NOT CALL THIS METHOD FROM THE UI THREAD (DATABASE ACCESS) */ @VisibleForTesting - Notification createNewMessageNotification(long accountId, long messageId, + Notification createNewMessageNotification(long accountId, long mailboxId, long messageId, int unseenMessageCount, boolean enableAudio) { final Account account = Account.restoreAccountWithId(mContext, accountId); if (account == null) { @@ -388,10 +388,14 @@ public class NotificationController { final String subject = message.mSubject; final Bitmap senderPhoto = getSenderPhoto(message); final SpannableString title = getNewMessageTitle(senderName, account.mDisplayName); - // TODO Set the intent according to number of unseen messages - final Intent intent = Welcome.createOpenAccountInboxIntent(mContext, accountId); final Bitmap largeIcon = senderPhoto != null ? senderPhoto : mGenericSenderIcon; final Integer number = unseenMessageCount > 1 ? unseenMessageCount : null; + final Intent intent; + if (unseenMessageCount >= 1) { + intent = Welcome.createOpenMessageIntent(mContext, accountId, mailboxId, messageId); + } else { + intent = Welcome.createOpenAccountInboxIntent(mContext, accountId); + } Notification notification = createAccountNotification(account, null, title, subject, intent, largeIcon, number, enableAudio); @@ -634,7 +638,7 @@ public class NotificationController { // Either the count or last message has changed; update the notification boolean playAudio = (oldMessageCount == 0); // play audio on first notification Notification n = sInstance.createNewMessageNotification( - mAccountId, newMessageId, newMessageCount, playAudio); + mAccountId, mMailboxId, newMessageId, newMessageCount, playAudio); if (n != null) { // Make the notification visible sInstance.mNotificationManager.notify( diff --git a/tests/src/com/android/email/NotificationControllerTest.java b/tests/src/com/android/email/NotificationControllerTest.java index c6f25fbfe..e67c47001 100644 --- a/tests/src/com/android/email/NotificationControllerTest.java +++ b/tests/src/com/android/email/NotificationControllerTest.java @@ -213,7 +213,7 @@ public class NotificationControllerTest extends AndroidTestCase { Mailbox b1 = ProviderTestUtils.setupMailbox("inbox", a1.mId, true, c, Mailbox.TYPE_INBOX); Message m1 = ProviderTestUtils.setupMessage("message", a1.mId, b1.mId, true, true, c); - n = mTarget.createNewMessageNotification(a1.mId, m1.mId, 1, true); + n = mTarget.createNewMessageNotification(a1.mId, b1.mId, m1.mId, 1, true); assertEquals(R.drawable.stat_notify_email_generic, n.icon); assertEquals(mMockClock.mTime, n.when); @@ -223,7 +223,7 @@ public class NotificationControllerTest extends AndroidTestCase { // TODO Check content -- how? // Case 2: 1 account, 2 unseen message - n = mTarget.createNewMessageNotification(a1.mId, m1.mId, 2, true); + n = mTarget.createNewMessageNotification(a1.mId, b1.mId, m1.mId, 2, true); assertEquals(R.drawable.stat_notify_email_generic, n.icon); assertEquals(mMockClock.mTime, n.when); @@ -247,7 +247,7 @@ public class NotificationControllerTest extends AndroidTestCase { m1.save(c); // This shouldn't crash. - n = mTarget.createNewMessageNotification(a1.mId, m1.mId, 1, true); + n = mTarget.createNewMessageNotification(a1.mId, b1.mId, m1.mId, 1, true); // Minimum test for the result assertEquals(R.drawable.stat_notify_email_generic, n.icon);