1
0
mirror of https://github.com/moparisthebest/k-9 synced 2024-11-14 21:45:14 -05:00

Some fixes to notification behaviour.

- Make notification high priority if any previewed message is flagged
- Fix message ordering
- Go to folder list instead of folder of newest message if there are
  multiple messages in the notification
This commit is contained in:
Danny Baumann 2013-01-04 16:11:39 +01:00
parent be38d9eb17
commit b334960355

View File

@ -205,8 +205,8 @@ public class MessagingController implements Runnable {
private static class NotificationData { private static class NotificationData {
int unreadBeforeNotification; int unreadBeforeNotification;
LinkedList<Message> messages; LinkedList<Message> messages; // newest one first
LinkedList<MessageReference> droppedMessages; LinkedList<MessageReference> droppedMessages; // newest one first
// There's no point in storing more than 5 messages for the notification, as a single notification // There's no point in storing more than 5 messages for the notification, as a single notification
// can't display more than that anyway. // can't display more than that anyway.
@ -221,9 +221,9 @@ public class MessagingController implements Runnable {
public boolean add(Message m) { public boolean add(Message m) {
while (size() >= MAX_MESSAGES) { while (size() >= MAX_MESSAGES) {
Message dropped = super.remove(); Message dropped = super.remove();
droppedMessages.add(dropped.makeMessageReference()); droppedMessages.add(0, dropped.makeMessageReference());
} }
super.add(m); super.add(0, m);
return true; return true;
} }
}; };
@ -231,10 +231,10 @@ public class MessagingController implements Runnable {
public ArrayList<MessageReference> getAllMessageRefs() { public ArrayList<MessageReference> getAllMessageRefs() {
ArrayList<MessageReference> refs = new ArrayList<MessageReference>(); ArrayList<MessageReference> refs = new ArrayList<MessageReference>();
refs.addAll(droppedMessages);
for (Message m : messages) { for (Message m : messages) {
refs.add(m.makeMessageReference()); refs.add(m.makeMessageReference());
} }
refs.addAll(droppedMessages);
return refs; return refs;
} }
@ -4588,14 +4588,12 @@ public class MessagingController implements Runnable {
} }
private Message findNewestMessageForNotificationLocked(Account account, NotificationData data) { private Message findNewestMessageForNotificationLocked(Account account, NotificationData data) {
int count = data.messages.size(); if (data.messages.size() > 0) {
if (count > 0) { return data.messages.get(0);
return data.messages.get(count - 1);
} }
count = data.droppedMessages.size(); if (data.droppedMessages.size() > 0) {
if (count > 0) { MessageReference ref = data.droppedMessages.get(0);
MessageReference ref = data.droppedMessages.get(count - 1);
try { try {
return account.getLocalStore().getFolder(ref.folderName).getMessage(ref.uid); return account.getLocalStore().getFolder(ref.folderName).getMessage(ref.uid);
} catch (MessagingException e) { } catch (MessagingException e) {
@ -4667,6 +4665,7 @@ public class MessagingController implements Runnable {
String accountDescr = (account.getDescription() != null) ? String accountDescr = (account.getDescription() != null) ?
account.getDescription() : account.getEmail(); account.getDescription() : account.getEmail();
final ArrayList<MessageReference> allRefs = data.getAllMessageRefs();
if (platformSupportsExtendedNotifications()) { if (platformSupportsExtendedNotifications()) {
if (newMessages > 1) { if (newMessages > 1) {
@ -4703,8 +4702,6 @@ public class MessagingController implements Runnable {
NotificationActionService.getReplyIntent(context, account, message.makeMessageReference())); NotificationActionService.getReplyIntent(context, account, message.makeMessageReference()));
} }
final ArrayList<MessageReference> allRefs = data.getAllMessageRefs();
builder.addAction(R.drawable.ic_action_mark_as_read_dark, builder.addAction(R.drawable.ic_action_mark_as_read_dark,
context.getString(R.string.notification_action_read), context.getString(R.string.notification_action_read),
NotificationActionService.getReadAllMessagesIntent(context, account, allRefs)); NotificationActionService.getReadAllMessagesIntent(context, account, allRefs));
@ -4727,9 +4724,23 @@ public class MessagingController implements Runnable {
builder.setContentText(summary); builder.setContentText(summary);
} }
Intent i = FolderList.actionHandleNotification(context, account, String initialFolder = message.getFolder().getName();
message.getFolder().getName()); /* only go to folder if all messages are in the same folder, else go to folder list */
PendingIntent pi = PendingIntent.getActivity(context, 0, i, 0); 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);
break;
}
}
Intent i = FolderList.actionHandleNotification(context, account, initialFolder);
PendingIntent pi = PendingIntent.getActivity(context, 0, i, PendingIntent.FLAG_UPDATE_CURRENT);
builder.setContentIntent(pi); builder.setContentIntent(pi);
// Only ring or vibrate if we have not done so already on this account and fetch // Only ring or vibrate if we have not done so already on this account and fetch