Skip to content

Commit

Permalink
#619 "Add android wear support"
Browse files Browse the repository at this point in the history
cleanup, comments and 1 missing intent-extra.
  • Loading branch information
MarcusWolschon committed May 12, 2015
1 parent 509573e commit 937ec6c
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 29 deletions.
Expand Up @@ -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;
}

/**
Expand Down Expand Up @@ -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<MessageReference> subAllRefs = new ArrayList<MessageReference>();
Expand All @@ -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<MessageReference> allRefs, final List<? extends Message> messages, final int notificationID) {
// we need a new wearableExtender for each notification
Expand Down Expand Up @@ -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;
Expand Down
Expand Up @@ -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;
Expand Down Expand Up @@ -46,29 +45,30 @@ 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);
}

/**
*
* @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) {
Expand All @@ -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) {
Expand All @@ -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) {
Expand All @@ -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)<br/>
* 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)
Expand All @@ -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) {
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 937ec6c

Please sign in to comment.