1
0
mirror of https://github.com/moparisthebest/k-9 synced 2025-01-09 04:38:10 -05:00

#619 "Add android wear support"

* updating notifications after acting on one of many messages fixed.

* still debugging stacked notifications (deleting second of 2 messages) . CONTAINS DEBUGGING CODE
This commit is contained in:
Marcus Wolschon 2015-07-07 21:05:49 +02:00
parent 99115130ad
commit 0065004067
4 changed files with 123 additions and 80 deletions

View File

@ -56,7 +56,9 @@ public class NotificationDeleteConfirmation extends Activity {
i.putExtra(EXTRA_NOTIFICATION_ID, notificationID); i.putExtra(EXTRA_NOTIFICATION_ID, notificationID);
i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP); i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP);
return PendingIntent.getActivity(context, account.getAccountNumber(), i, PendingIntent.FLAG_UPDATE_CURRENT); // we can not use FLAG_UPDATE_CURRENT here because with Android Wear we may have
// PendingIntents for all new messages and for each individual new message at the same time.
return PendingIntent.getActivity(context, account.getAccountNumber(), i, PendingIntent.FLAG_ONE_SHOT);
} }
@Override @Override

View File

@ -356,6 +356,25 @@ public class MessagingController implements Runnable {
public int getNewMessageCount() { public int getNewMessageCount() {
return messages.size() + droppedMessages.size(); return messages.size() + droppedMessages.size();
} }
/**
*
* @param messagingController
* @param context
*/
public void checkSupressedMessaged(MessagingController messagingController, Context context) {
for (LocalMessage m : messages) {
if (messagingController.isMessageSuppressed(m)) {
//TODO: NotificationData needs to be updated when taking action on a single message
// from a notification. Bus that's a major rewrite of the entire notification system
// and should happen in it's own github issue.
// so we temporarily work around this shortcoming by checking.
removeMatchingMessage(context, m.makeMessageReference());
continue;
}
}
}
} }
// Key is accountNumber // Key is accountNumber
@ -4627,6 +4646,9 @@ public class MessagingController implements Runnable {
data = new NotificationData(previousUnreadMessageCount); data = new NotificationData(previousUnreadMessageCount);
notificationData.put(account.getAccountNumber(), data); notificationData.put(account.getAccountNumber(), data);
} }
if (data != null) {
data.checkSupressedMessaged(this, context);
}
} }
return data; return data;
@ -4741,11 +4763,17 @@ public class MessagingController implements Runnable {
/** /**
* Creates a notification of a newly received message. * Creates a notification of a newly received message.
* @param acknowledgedMessages the user has acted on these messages, we may remove them from the notifications
*/ */
public void updateAccountNotification(final Context context, final Account account) { public void updateAccountNotification(final Context context, final Account account, final @Nullable List<MessageReference> acknowledgedMessages) {
final NotificationData data = getNotificationData(account, null); final NotificationData data = getNotificationData(account, null);
//noinspection SynchronizationOnLocalVariableOrMethodParameter //noinspection SynchronizationOnLocalVariableOrMethodParameter
synchronized (data) { synchronized (data) {
if (acknowledgedMessages != null) {
for (MessageReference ref : acknowledgedMessages) {
data.removeMatchingMessage(context, ref);
}
}
notifyAccountWithDataLocked(context, account, null, data); notifyAccountWithDataLocked(context, account, null, data);
} }
} }
@ -4805,10 +4833,16 @@ public class MessagingController implements Runnable {
// Delete on wear only if no confirmation is required // Delete on wear only if no confirmation is required
// because they would have to be confirmed on the phone, not the wear device // because they would have to be confirmed on the phone, not the wear device
if (!K9.confirmDeleteFromNotification()) { if (!K9.confirmDeleteFromNotification()) {
String label = null; //TODO: temporary debugging code
if (allRefs.size()>1) {
label = context.getString(R.string.notification_action_delete_all);
} else {
label = context.getString(R.string.notification_action_delete) + " " + allRefs.get(0).restoreToLocalMessage(context).getSubject();
}//TODO: DANGEROUS CODE! In case of 2 new messages, this one deletes the wrong one! No idea why yet.
NotificationCompat.Action wearActionDelete = NotificationCompat.Action wearActionDelete =
new NotificationCompat.Action.Builder( new NotificationCompat.Action.Builder(
R.drawable.ic_action_delete_dark, R.drawable.ic_action_delete_dark,
context.getString(R.string.notification_action_delete), label, //context.getString(allRefs.size()>1?R.string.notification_action_delete_all:R.string.notification_action_delete),
NotificationDeleteConfirmation.getIntent(context, account, allRefs, notificationID)) NotificationDeleteConfirmation.getIntent(context, account, allRefs, notificationID))
.build(); .build();
builder.extend(wearableExtender.addAction(wearActionDelete)); builder.extend(wearableExtender.addAction(wearActionDelete));
@ -4888,7 +4922,7 @@ public class MessagingController implements Runnable {
builder.setTicker(summary); builder.setTicker(summary);
} }
final int newMessages = data.getNewMessageCount(); int newMessages = data.getNewMessageCount();
final int unreadCount = data.unreadBeforeNotification + newMessages; final int unreadCount = data.unreadBeforeNotification + newMessages;
builder.setNumber(unreadCount); builder.setNumber(unreadCount);
@ -4898,6 +4932,10 @@ public class MessagingController implements Runnable {
final ArrayList<MessageReference> allRefs = new ArrayList<MessageReference>(); final ArrayList<MessageReference> allRefs = new ArrayList<MessageReference>();
data.supplyAllMessageRefs(allRefs); data.supplyAllMessageRefs(allRefs);
if (newMessages == 0) {
notifyAccountCancel(context, account);
}
if (platformSupportsExtendedNotifications() && !privacyModeEnabled) { if (platformSupportsExtendedNotifications() && !privacyModeEnabled) {
if (newMessages > 1) { if (newMessages > 1) {
@ -4907,6 +4945,7 @@ public class MessagingController implements Runnable {
// multiple messages pending, show inbox style // multiple messages pending, show inbox style
NotificationCompat.InboxStyle style = new NotificationCompat.InboxStyle(builder); NotificationCompat.InboxStyle style = new NotificationCompat.InboxStyle(builder);
int nID = account.getAccountNumber(); int nID = account.getAccountNumber();
int realnID = 1000 + nID;
for (LocalMessage m : data.messages) { for (LocalMessage m : data.messages) {
style.addLine(buildMessageSummary(context, style.addLine(buildMessageSummary(context,
getMessageSender(context, account, m), getMessageSender(context, account, m),
@ -4921,13 +4960,14 @@ public class MessagingController implements Runnable {
subBuilder.setGroup(NOTIFICATION_GROUP_KEY); // same group as summary subBuilder.setGroup(NOTIFICATION_GROUP_KEY); // same group as summary
subBuilder.setAutoCancel(true); // summary closes all, stacked only itself subBuilder.setAutoCancel(true); // summary closes all, stacked only itself
nID = 1000 + nID; realnID++;//TODO: test code
// nID = 1000 + nID;
// reuse existing notification IDs if some of the stacked messages // reuse existing notification IDs if some of the stacked messages
// are already shown on the wear device. // are already shown on the wear device.
Integer realnID = data.getStackedChildNotification(m); //Integer realnID = data.getStackedChildNotification(m);
if (realnID == null) { //if (realnID == null) {
realnID = nID; // realnID = nID;
} //}
// set content // set content
setNotificationContent(context, m, getMessageSender(context, account, m), getMessageSubject(context, m), subBuilder, accountDescr); setNotificationContent(context, m, getMessageSender(context, account, m), getMessageSubject(context, m), subBuilder, accountDescr);
@ -5006,7 +5046,7 @@ public class MessagingController implements Runnable {
platformSupportsLockScreenNotifications() platformSupportsLockScreenNotifications()
? R.drawable.ic_action_delete_dark_vector ? R.drawable.ic_action_delete_dark_vector
: R.drawable.ic_action_delete_dark, : R.drawable.ic_action_delete_dark,
context.getString(R.string.notification_action_delete), "test " + context.getString(R.string.notification_action_delete),
NotificationDeleteConfirmation.getIntent(context, account, allRefs, account.getAccountNumber())); NotificationDeleteConfirmation.getIntent(context, account, allRefs, account.getAccountNumber()));
} }
} else { } else {

View File

@ -2,6 +2,7 @@ package com.fsck.k9.service;
import java.io.Serializable; import java.io.Serializable;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections;
import java.util.LinkedList; import java.util.LinkedList;
import java.util.List; import java.util.List;
@ -208,14 +209,14 @@ public class NotificationActionService extends CoreService {
final MessagingController controller = MessagingController.getInstance(getApplication()); final MessagingController controller = MessagingController.getInstance(getApplication());
final Account account = preferences.getAccount(intent.getStringExtra(EXTRA_ACCOUNT)); final Account account = preferences.getAccount(intent.getStringExtra(EXTRA_ACCOUNT));
final String action = intent.getAction(); final String action = intent.getAction();
List<MessageReference> refs = null;
if (account != null) { if (account != null) {
if (READ_ALL_ACTION.equals(action)) { if (READ_ALL_ACTION.equals(action)) {
if (K9.DEBUG) if (K9.DEBUG)
Log.i(K9.LOG_TAG, "NotificationActionService marking messages as read"); Log.i(K9.LOG_TAG, "NotificationActionService marking messages as read");
List<MessageReference> refs = refs = intent.getParcelableArrayListExtra(EXTRA_MESSAGE_LIST);
intent.getParcelableArrayListExtra(EXTRA_MESSAGE_LIST);
for (MessageReference ref : refs) { for (MessageReference ref : refs) {
controller.setFlag(account, ref.getFolderName(), ref.getUid(), Flag.SEEN, true); controller.setFlag(account, ref.getFolderName(), ref.getUid(), Flag.SEEN, true);
} }
@ -223,8 +224,7 @@ public class NotificationActionService extends CoreService {
if (K9.DEBUG) if (K9.DEBUG)
Log.i(K9.LOG_TAG, "NotificationActionService deleting messages"); Log.i(K9.LOG_TAG, "NotificationActionService deleting messages");
List<MessageReference> refs = refs = intent.getParcelableArrayListExtra(EXTRA_MESSAGE_LIST);
intent.getParcelableArrayListExtra(EXTRA_MESSAGE_LIST);
List<LocalMessage> messages = new ArrayList<LocalMessage>(); List<LocalMessage> messages = new ArrayList<LocalMessage>();
for (MessageReference ref : refs) { for (MessageReference ref : refs) {
@ -239,8 +239,7 @@ public class NotificationActionService extends CoreService {
if (K9.DEBUG) if (K9.DEBUG)
Log.i(K9.LOG_TAG, "NotificationActionService archiving messages"); Log.i(K9.LOG_TAG, "NotificationActionService archiving messages");
List<MessageReference> refs = refs = intent.getParcelableArrayListExtra(EXTRA_MESSAGE_LIST);
intent.getParcelableArrayListExtra(EXTRA_MESSAGE_LIST);
List<LocalMessage> messages = new ArrayList<LocalMessage>(); List<LocalMessage> messages = new ArrayList<LocalMessage>();
for (MessageReference ref : refs) { for (MessageReference ref : refs) {
@ -268,8 +267,7 @@ public class NotificationActionService extends CoreService {
if (K9.DEBUG) if (K9.DEBUG)
Log.i(K9.LOG_TAG, "NotificationActionService moving messages to spam"); Log.i(K9.LOG_TAG, "NotificationActionService moving messages to spam");
List<MessageReference> refs = refs = intent.getParcelableArrayListExtra(EXTRA_MESSAGE_LIST);
intent.getParcelableArrayListExtra(EXTRA_MESSAGE_LIST);
List<LocalMessage> messages = new ArrayList<LocalMessage>(); List<LocalMessage> messages = new ArrayList<LocalMessage>();
for (MessageReference ref : refs) { for (MessageReference ref : refs) {
@ -293,6 +291,8 @@ public class NotificationActionService extends CoreService {
Log.i(K9.LOG_TAG, "NotificationActionService initiating reply"); Log.i(K9.LOG_TAG, "NotificationActionService initiating reply");
MessageReference ref = intent.getParcelableExtra(EXTRA_MESSAGE); MessageReference ref = intent.getParcelableExtra(EXTRA_MESSAGE);
refs = Collections.singletonList(ref);
LocalMessage message = ref.restoreToLocalMessage(this); LocalMessage message = ref.restoreToLocalMessage(this);
if (message != null) { if (message != null) {
Intent i = MessageCompose.getActionReplyIntent(this, message, false, null); Intent i = MessageCompose.getActionReplyIntent(this, message, false, null);
@ -316,7 +316,7 @@ public class NotificationActionService extends CoreService {
notificationManager.cancel(intent.getIntExtra(EXTRA_NOTIFICATION_ID, account.getAccountNumber())); notificationManager.cancel(intent.getIntExtra(EXTRA_NOTIFICATION_ID, account.getAccountNumber()));
// update the summary notification // update the summary notification
MessagingController.getInstance(this).updateAccountNotification(this, account); MessagingController.getInstance(this).updateAccountNotification(this, account, refs);
} else { } else {
controller.notifyAccountCancel(this, account); controller.notifyAccountCancel(this, account);
} }

View File

@ -210,6 +210,7 @@ Please submit bug reports, contribute new features and ask questions at
<string name="notification_action_reply">Reply</string> <string name="notification_action_reply">Reply</string>
<string name="notification_action_mark_as_read">Mark Read</string> <string name="notification_action_mark_as_read">Mark Read</string>
<string name="notification_action_delete">Delete</string> <string name="notification_action_delete">Delete</string>
<string name="notification_action_delete_all">Delete All</string>
<string name="notification_action_archive">Archive</string> <string name="notification_action_archive">Archive</string>
<string name="notification_action_spam">Spam</string> <string name="notification_action_spam">Spam</string>
<string name="notification_certificate_error_title">Certificate error for <xliff:g id="account">%s</xliff:g></string> <string name="notification_certificate_error_title">Certificate error for <xliff:g id="account">%s</xliff:g></string>