From 937ec6c50e743555e3007efe4f6f29f5bcb69851 Mon Sep 17 00:00:00 2001 From: Marcus Wolschon Date: Tue, 12 May 2015 22:45:21 +0200 Subject: [PATCH] #619 "Add android wear support" cleanup, comments and 1 missing intent-extra. --- .../k9/controller/MessagingController.java | 23 +++++++-- .../k9/service/NotificationActionService.java | 51 ++++++++++--------- 2 files changed, 45 insertions(+), 29 deletions(-) diff --git a/k9mail/src/main/java/com/fsck/k9/controller/MessagingController.java b/k9mail/src/main/java/com/fsck/k9/controller/MessagingController.java index c295bf29b0e..338a491211f 100644 --- a/k9mail/src/main/java/com/fsck/k9/controller/MessagingController.java +++ b/k9mail/src/main/java/com/fsck/k9/controller/MessagingController.java @@ -4669,11 +4669,8 @@ private boolean shouldNotifyForMessage(Account account, LocalFolder localFolder, // Don't notify if the sender address matches one of our identities and the user chose not // to be notified for such messages. - if (account.isAnIdentity(message.getFrom()) && !account.isNotifySelfNewMail()) { - return false; - } + return !(account.isAnIdentity(message.getFrom()) && !account.isNotifySelfNewMail()); - return true; } /** @@ -4824,7 +4821,11 @@ private void notifyAccount(Context context, Account account, /** * Build the specific notification actions for a single message on Android Wear. + * @param builder NotificationBuilder to add actions to * @param totalMsgCount if this is a stacked notification, how many other messages are there? + * @param account the account we intent to act on + * @param message the single message we intent to act on (in a stacked notification or a summary notification about a single message) + * @param notificationID the id of the future notification. Will be used in the intents, so afterwards the correct notification gets closed. */ private void addWearActions(final NotificationCompat.Builder builder, final int totalMsgCount, final Account account, final Message message, final int notificationID) { ArrayList subAllRefs = new ArrayList(); @@ -4835,8 +4836,13 @@ private void addWearActions(final NotificationCompat.Builder builder, final int } /** * Build the specific notification actions for a single or multiple message on Android Wear. + * @param builder NotificationBuilder to add actions to * @param totalMsgCount total message count (may be different from msgCount if this is a stacked notification) * @param msgCount message count to be handled in this (stacked or summary) notification + * @param account the account we intent to act on + * @param allRefs the messages we intent to act on + * @param messages the messages we intent to act on + * @param notificationID the id of the future notification. Will be used in the intents, so afterwards the correct notification gets closed. */ private void addWearActions(final NotificationCompat.Builder builder, final int totalMsgCount, final int msgCount, final Account account, final ArrayList allRefs, final List messages, final int notificationID) { // we need a new wearableExtender for each notification @@ -4886,6 +4892,15 @@ private void addWearActions(final NotificationCompat.Builder builder, final int builder.extend(wearableExtender.addAction(wearActionSpam)); } } + + /** + * Create/Upate and show notifications about new messages + * or that there suddenly are no longer any new messages on an account + * @param context used to create the notification and it's intents + * @param account the account that has new messages + * @param message the message (if it's just one) + * @param data all the details + */ private void notifyAccountWithDataLocked(Context context, final Account account, LocalMessage message, NotificationData data) { boolean updateSilently = false; diff --git a/k9mail/src/main/java/com/fsck/k9/service/NotificationActionService.java b/k9mail/src/main/java/com/fsck/k9/service/NotificationActionService.java index f7e8d2539ff..966c5121e24 100644 --- a/k9mail/src/main/java/com/fsck/k9/service/NotificationActionService.java +++ b/k9mail/src/main/java/com/fsck/k9/service/NotificationActionService.java @@ -2,7 +2,6 @@ import java.io.Serializable; import java.util.ArrayList; -import java.util.LinkedList; import java.util.List; import com.fsck.k9.Account; @@ -46,17 +45,18 @@ public class NotificationActionService extends CoreService { /** * - * @param context - * @param account - * @param ref + * @param context context to use for creating the {@link Intent} + * @param account the account we intent to act on + * @param ref the message we intent to act on * @param notificationID ID of the notification, this intent is for. * @see #EXTRA_NOTIFICATION_ID - * @return + * @return the requested intent. To be used in a Notification. */ public static PendingIntent getReplyIntent(Context context, final Account account, final MessageReference ref, final int notificationID) { Intent i = new Intent(context, NotificationActionService.class); i.putExtra(EXTRA_ACCOUNT, account.getUuid()); i.putExtra(EXTRA_MESSAGE, ref); + i.putExtra(EXTRA_NOTIFICATION_ID, notificationID); i.setAction(REPLY_ACTION); return PendingIntent.getService(context, account.getAccountNumber(), i, PendingIntent.FLAG_UPDATE_CURRENT); @@ -64,11 +64,11 @@ public static PendingIntent getReplyIntent(Context context, final Account accoun /** * - * @param context - * @param account - * @param refs + * @param context context to use for creating the {@link Intent} + * @param account the account we intent to act on + * @param refs the messages we intent to act on * @param notificationID ID of the notification, this intent is for. - * @return + * @return the requested intent. To be used in a Notification. * @see #EXTRA_NOTIFICATION_ID */ public static PendingIntent getReadAllMessagesIntent(Context context, final Account account, final Serializable refs, final int notificationID) { @@ -83,10 +83,10 @@ public static PendingIntent getReadAllMessagesIntent(Context context, final Acco /** * - * @param context - * @param account + * @param context context to use for creating the {@link Intent} + * @param account the account for the intent to act on * @param notificationID ID of the notification, this intent is for. - * @return + * @return the requested intent. To be used in a Notification. * @see #EXTRA_NOTIFICATION_ID */ public static PendingIntent getAcknowledgeIntent(Context context, final Account account, final int notificationID) { @@ -100,11 +100,11 @@ public static PendingIntent getAcknowledgeIntent(Context context, final Account /** * - * @param context - * @param account - * @param refs + * @param context context to use for creating the {@link Intent} + * @param account the account we intent to act on + * @param refs the messages we intent to act on * @param notificationID ID of the notification, this intent is for. - * @return + * @return the requested intent. To be used in a Notification. * @see #EXTRA_NOTIFICATION_ID */ public static Intent getDeleteAllMessagesIntent(Context context, final Account account, final Serializable refs, final int notificationID) { @@ -121,7 +121,7 @@ public static Intent getDeleteAllMessagesIntent(Context context, final Account a * Check if for the given parameters the ArchiveAllMessages intent is possible for Android Wear. * (No confirmation on the phone required and moving these messages to the spam-folder possible)
* Since we can not show a toast like on the phone screen, we must not offer actions that can not be performed. - * @see #getArchiveAllMessagesIntent(android.content.Context, com.fsck.k9.Account, java.io.Serializable, boolean) + * @see #getArchiveAllMessagesIntent(android.content.Context, com.fsck.k9.Account, java.io.Serializable, boolean, int) * @param context the context to get a {@link MessagingController} * @param account the account (must allow moving messages to allow true as a result) * @param messages the messages to move to the spam folder (must be synchronized to allow true as a result) @@ -134,12 +134,12 @@ public static boolean isArchiveAllMessagesWearAvaliable(Context context, final A /** * - * @param context - * @param account - * @param refs + * @param context context to use for creating the {@link Intent} + * @param account the account we intent to act on + * @param refs the messages we intent to act on * @param dontCancel if true, after executing the intent, not all notifications for this account are canceled automatically * @param notificationID ID of the notification, this intent is for. - * @return + * @return the requested intent. To be used in a Notification. * @see #EXTRA_NOTIFICATION_ID */ public static PendingIntent getArchiveAllMessagesIntent(Context context, final Account account, final Serializable refs, final boolean dontCancel, final int notificationID) { @@ -173,12 +173,12 @@ public static boolean isSpamAllMessagesWearAvaliable(Context context, final Acco /** * - * @param context - * @param account - * @param refs + * @param context context to use for creating the {@link Intent} + * @param account the account we intent to act on + * @param refs the messages we intent to act on * @param dontCancel if true, after executing the intent, not all notifications for this account are canceled automatically * @param notificationID ID of the notification, this intent is for. - * @return + * @return the requested intent. To be used in a Notification. * @see #EXTRA_NOTIFICATION_ID */ public static PendingIntent getSpamAllMessagesIntent(Context context, final Account account, final Serializable refs, final boolean dontCancel, final int notificationID) { @@ -312,6 +312,7 @@ && isMovePossible(controller, account, dstFolder, messages)) { } else if (ACKNOWLEDGE_ACTION.equals(action)) { // nothing to do here, we just want to cancel the notification so the list // of unseen messages is reset + Log.i(K9.LOG_TAG, "notification acknowledged"); } // if this was a stacked notification on Android Wear, update the summary