Fix multi message notifications

When multiple messages are received, now the View intent
will take the user to to contents of the mailbox, instead of
the viewing the last message

I have filed bug 7216375 to track the issue about receiving
multiple messages in different syncs

Bug: 7129870

Change-Id: I3fdf4680c62565615fcbefc75d72c2a721942604
This commit is contained in:
Paul Westbrook 2012-09-23 12:13:48 -07:00
parent 35177585a2
commit 986881efe6
1 changed files with 56 additions and 2 deletions

View File

@ -403,6 +403,18 @@ public class NotificationController {
return intent;
}
private Intent createViewMailboxIntent(com.android.mail.providers.Account account,
Folder folder) {
final Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
intent.putExtra(EXTRA_ACCOUNT, account.serialize());
if (folder != null) {
intent.setDataAndType(folder.uri, account.mimeType);
intent.putExtra(EXTRA_FOLDER, Folder.toString(folder));
}
return intent;
}
private Cursor getUiCursor(Uri uri, String[] projection) {
Cursor c = mContext.getContentResolver().query(uri, projection, null, null, null);
if (c == null) return null;
@ -442,7 +454,44 @@ public class NotificationController {
c.close();
return createViewConversationIntent(conv, folder, acct);
}
private Intent createViewMailboxIntentForMessage(Message message) {
Cursor c = null;
com.android.mail.providers.Account acct = null;
try {
c = getUiCursor(EmailProvider.uiUri("uiaccount", message.mAccountKey),
UIProvider.ACCOUNTS_PROJECTION);
if (c == null) {
Log.w(TAG, "Can't find account for message " + message.mId);
return null;
}
acct = new com.android.mail.providers.Account(c);
} finally {
if (c != null) {
c.close();
c = null;
}
}
Folder folder = null;
try {
c = getUiCursor(EmailProvider.uiUri("uifolder", message.mMailboxKey),
UIProvider.FOLDERS_PROJECTION);
if (c == null) {
Log.w(TAG, "Can't find folder for message " + message.mId + ", folder " +
message.mMailboxKey);
return null;
}
folder = new Folder(c);
} finally {
if (c != null) {
c.close();
c = null;
}
}
return createViewMailboxIntent(acct, folder);
}
/**
* Returns a "new message" notification for the given account.
*
@ -483,7 +532,12 @@ public class NotificationController {
: message.mSubject;
final Bitmap largeIcon = senderPhoto != null ? senderPhoto : mGenericSenderIcon;
final Integer number = unreadCount > 1 ? unreadCount : null;
Intent intent = createViewConversationIntent(message);
final Intent intent;
if (multipleUnseen) {
intent = createViewMailboxIntentForMessage(message);
} else {
intent = createViewConversationIntent(message);
}
if (intent == null) {
return null;
}