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
This commit is contained in:
Todd Kennedy 2011-05-13 08:41:48 -07:00
parent 76061eba14
commit f437892348
2 changed files with 11 additions and 7 deletions

View File

@ -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(

View File

@ -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);