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:
parent
76061eba14
commit
f437892348
@ -369,7 +369,7 @@ public class NotificationController {
|
|||||||
* NOTE: DO NOT CALL THIS METHOD FROM THE UI THREAD (DATABASE ACCESS)
|
* NOTE: DO NOT CALL THIS METHOD FROM THE UI THREAD (DATABASE ACCESS)
|
||||||
*/
|
*/
|
||||||
@VisibleForTesting
|
@VisibleForTesting
|
||||||
Notification createNewMessageNotification(long accountId, long messageId,
|
Notification createNewMessageNotification(long accountId, long mailboxId, long messageId,
|
||||||
int unseenMessageCount, boolean enableAudio) {
|
int unseenMessageCount, boolean enableAudio) {
|
||||||
final Account account = Account.restoreAccountWithId(mContext, accountId);
|
final Account account = Account.restoreAccountWithId(mContext, accountId);
|
||||||
if (account == null) {
|
if (account == null) {
|
||||||
@ -388,10 +388,14 @@ public class NotificationController {
|
|||||||
final String subject = message.mSubject;
|
final String subject = message.mSubject;
|
||||||
final Bitmap senderPhoto = getSenderPhoto(message);
|
final Bitmap senderPhoto = getSenderPhoto(message);
|
||||||
final SpannableString title = getNewMessageTitle(senderName, account.mDisplayName);
|
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 Bitmap largeIcon = senderPhoto != null ? senderPhoto : mGenericSenderIcon;
|
||||||
final Integer number = unseenMessageCount > 1 ? unseenMessageCount : null;
|
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,
|
Notification notification = createAccountNotification(account, null, title, subject,
|
||||||
intent, largeIcon, number, enableAudio);
|
intent, largeIcon, number, enableAudio);
|
||||||
@ -634,7 +638,7 @@ public class NotificationController {
|
|||||||
// Either the count or last message has changed; update the notification
|
// Either the count or last message has changed; update the notification
|
||||||
boolean playAudio = (oldMessageCount == 0); // play audio on first notification
|
boolean playAudio = (oldMessageCount == 0); // play audio on first notification
|
||||||
Notification n = sInstance.createNewMessageNotification(
|
Notification n = sInstance.createNewMessageNotification(
|
||||||
mAccountId, newMessageId, newMessageCount, playAudio);
|
mAccountId, mMailboxId, newMessageId, newMessageCount, playAudio);
|
||||||
if (n != null) {
|
if (n != null) {
|
||||||
// Make the notification visible
|
// Make the notification visible
|
||||||
sInstance.mNotificationManager.notify(
|
sInstance.mNotificationManager.notify(
|
||||||
|
@ -213,7 +213,7 @@ public class NotificationControllerTest extends AndroidTestCase {
|
|||||||
Mailbox b1 = ProviderTestUtils.setupMailbox("inbox", a1.mId, true, c, Mailbox.TYPE_INBOX);
|
Mailbox b1 = ProviderTestUtils.setupMailbox("inbox", a1.mId, true, c, Mailbox.TYPE_INBOX);
|
||||||
Message m1 = ProviderTestUtils.setupMessage("message", a1.mId, b1.mId, true, true, c);
|
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(R.drawable.stat_notify_email_generic, n.icon);
|
||||||
assertEquals(mMockClock.mTime, n.when);
|
assertEquals(mMockClock.mTime, n.when);
|
||||||
@ -223,7 +223,7 @@ public class NotificationControllerTest extends AndroidTestCase {
|
|||||||
// TODO Check content -- how?
|
// TODO Check content -- how?
|
||||||
|
|
||||||
// Case 2: 1 account, 2 unseen message
|
// 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(R.drawable.stat_notify_email_generic, n.icon);
|
||||||
assertEquals(mMockClock.mTime, n.when);
|
assertEquals(mMockClock.mTime, n.when);
|
||||||
@ -247,7 +247,7 @@ public class NotificationControllerTest extends AndroidTestCase {
|
|||||||
m1.save(c);
|
m1.save(c);
|
||||||
|
|
||||||
// This shouldn't crash.
|
// 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
|
// Minimum test for the result
|
||||||
assertEquals(R.drawable.stat_notify_email_generic, n.icon);
|
assertEquals(R.drawable.stat_notify_email_generic, n.icon);
|
||||||
|
Loading…
Reference in New Issue
Block a user