Skip to content

Commit

Permalink
Revert "thunderbird#619 "Add android wear support""
Browse files Browse the repository at this point in the history
This reverts commit 509573e.
  • Loading branch information
vt0r committed Jun 10, 2015
1 parent 3d2cf08 commit 8116f9c
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 123 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,38 +22,16 @@
public class NotificationDeleteConfirmation extends Activity {
private final static String EXTRA_ACCOUNT = "account";
private final static String EXTRA_MESSAGE_LIST = "messages";
private final static String EXTRA_NOTIFICATION_ID = NotificationActionService.EXTRA_NOTIFICATION_ID;

private final static int DIALOG_CONFIRM = 1;

/**
* The account to delete the messages on.
*/
private Account mAccount;
/**
* The messages to delete.
*/
private ArrayList<MessageReference> mMessageRefs;
/**
* ID of the notification that triggered this Activity.
* To make sure we close the correte notification afterwards because
* there may be multiple of them due to Android Wear stacked notifications.
*/
private int mNotificationID;

/**
*
* @param context context to create the PendingIntent.
* @param account The account to delete the messages on.
* @param refs The messages to delete.
* @param notificationID ID of the notification that triggered this Activity.
* @return PendingIntent that either deletes directly or shows a confirm-dialog on the phone (not on the wear device) first.
*/
public static PendingIntent getIntent(final Context context, final Account account, final Serializable refs, final int notificationID) {

public static PendingIntent getIntent(Context context, final Account account, final Serializable refs) {
Intent i = new Intent(context, NotificationDeleteConfirmation.class);
i.putExtra(EXTRA_ACCOUNT, account.getUuid());
i.putExtra(EXTRA_MESSAGE_LIST, refs);
i.putExtra(EXTRA_NOTIFICATION_ID, notificationID);
i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP);

return PendingIntent.getActivity(context, account.getAccountNumber(), i, PendingIntent.FLAG_UPDATE_CURRENT);
Expand All @@ -71,12 +49,11 @@ public void onCreate(Bundle icicle) {

mAccount = preferences.getAccount(intent.getStringExtra(EXTRA_ACCOUNT));
mMessageRefs = intent.getParcelableArrayListExtra(EXTRA_MESSAGE_LIST);
mNotificationID = intent.getIntExtra(EXTRA_NOTIFICATION_ID, mAccount.getAccountNumber());

if (mAccount == null || mMessageRefs == null || mMessageRefs.isEmpty()) {
finish();
} else if (!K9.confirmDeleteFromNotification()) {
triggerDelete(mNotificationID);
triggerDelete();
finish();
} else {
showDialog(DIALOG_CONFIRM);
Expand All @@ -94,7 +71,7 @@ public Dialog onCreateDialog(int id) {
new Runnable() {
@Override
public void run() {
triggerDelete(mNotificationID);
triggerDelete();
finish();
}
},
Expand Down Expand Up @@ -123,8 +100,8 @@ public void onPrepareDialog(int id, Dialog d) {
super.onPrepareDialog(id, d);
}

private void triggerDelete(final int notificationID) {
Intent i = NotificationActionService.getDeleteAllMessagesIntent(this, mAccount, mMessageRefs, notificationID);
private void triggerDelete() {
Intent i = NotificationActionService.getDeleteAllMessagesIntent(this, mAccount, mMessageRefs);
startService(i);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4758,19 +4758,19 @@ private void notifyAccount(Context context, Account account,
* Build the specific notification actions for a single message on Android Wear.
* @param totalMsgCount if this is a stacked notification, how many other messages are there?
*/
private void addWearActions(final NotificationCompat.Builder builder, final int totalMsgCount, final Account account, final Message message, final int notificationID) {
private void addWearActions(final NotificationCompat.Builder builder, final int totalMsgCount, final Account account, final Message message) {
ArrayList<MessageReference> subAllRefs = new ArrayList<MessageReference>();
subAllRefs.add(new MessageReference(account.getUuid(), message.getFolder().getName(), message.getUid(), message.getFlags().size()==0?null:message.getFlags().iterator().next()));
LinkedList<Message> msgList = new LinkedList<Message>();
msgList.add(message);
addWearActions(builder, totalMsgCount, 1, account, subAllRefs, msgList, notificationID);
addWearActions(builder, totalMsgCount, 1, account, subAllRefs, msgList);
}
/**
* Build the specific notification actions for a single or multiple message on Android Wear.
* @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
*/
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) {
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) {
// we need a new wearableExtender for each notification
final NotificationCompat.WearableExtender wearableExtender = new NotificationCompat.WearableExtender();

Expand All @@ -4790,7 +4790,7 @@ private void addWearActions(final NotificationCompat.Builder builder, final int
new NotificationCompat.Action.Builder(
R.drawable.ic_action_delete_dark,
context.getString(R.string.notification_action_delete),
NotificationDeleteConfirmation.getIntent(context, account, allRefs, notificationID))
NotificationDeleteConfirmation.getIntent(context, account, allRefs))
.build();
builder.extend(wearableExtender.addAction(wearActionDelete));
}
Expand All @@ -4802,7 +4802,7 @@ private void addWearActions(final NotificationCompat.Builder builder, final int
new NotificationCompat.Action.Builder(
R.drawable.ic_action_delete_dark,
context.getString(R.string.notification_action_archive),
NotificationActionService.getArchiveAllMessagesIntent(context, account, allRefs, totalMsgCount > msgCount, notificationID))
NotificationActionService.getArchiveAllMessagesIntent(context, account, allRefs, totalMsgCount > msgCount))
.build();
builder.extend(wearableExtender.addAction(wearActionArchive));
}
Expand All @@ -4813,7 +4813,7 @@ private void addWearActions(final NotificationCompat.Builder builder, final int
new NotificationCompat.Action.Builder(
R.drawable.ic_action_delete_dark,
context.getString(R.string.notification_action_spam),
NotificationActionService.getSpamAllMessagesIntent(context, account, allRefs, totalMsgCount > msgCount, notificationID))
NotificationActionService.getSpamAllMessagesIntent(context, account, allRefs, totalMsgCount > msgCount))
.build();
builder.extend(wearableExtender.addAction(wearActionSpam));
}
Expand Down Expand Up @@ -4875,6 +4875,7 @@ private void notifyAccountWithDataLocked(Context context, final Account account,

// Stacked notifications for Android Wear
// https://developer.android.com/training/wearables/notifications/stacks.html
// TODO: Bug! Stacked notification are shown on phone too, together with summary

// multiple messages pending, show inbox style
NotificationCompat.InboxStyle style = new NotificationCompat.InboxStyle(builder);
Expand All @@ -4893,20 +4894,12 @@ private void notifyAccountWithDataLocked(Context context, final Account account,
subBuilder.setGroup(NOTIFICATION_GROUP_KEY); // same group as summary
subBuilder.setAutoCancel(true); // summary closes all, stacked only itself

nID = 1000 + nID;
// reuse existing notification IDs if some of the stacked messages
// are already shown on the wear device.
Integer realnID = data.getStackedChildNotification(m);
if (realnID == null) {
realnID = nID;
}

// set content
setNotificationContent(context, m, getMessageSender(context, account, m), getMessageSubject(context, m), subBuilder, accountDescr);


// set actions
addWearActions(subBuilder, newMessages, account, m, realnID);
addWearActions(subBuilder, newMessages, account, m);
if (m.isSet(Flag.FLAGGED)) {
subBuilder.setPriority(NotificationCompat.PRIORITY_HIGH);
}
Expand All @@ -4915,6 +4908,11 @@ private void notifyAccountWithDataLocked(Context context, final Account account,
// and depend on quiet time and user settings

// this must be done before the summary notification
nID = 1000 + nID;
Integer realnID = data.getStackedChildNotification(m);
if (realnID == null) {
realnID = nID;
}
notifMgr.notify(realnID, subBuilder.build());
data.addStackedChildNotification(m, realnID);
}
Expand Down Expand Up @@ -4948,12 +4946,12 @@ private void notifyAccountWithDataLocked(Context context, final Account account,
? R.drawable.ic_action_single_message_options_dark_vector
: R.drawable.ic_action_single_message_options_dark,
context.getString(R.string.notification_action_reply),
NotificationActionService.getReplyIntent(context, account, message.makeMessageReference(), account.getAccountNumber()));
NotificationActionService.getReplyIntent(context, account, message.makeMessageReference()));

// add /different) actions to show on connected Android Wear devices
// do not add these to the a summary notification or they will affect all stacked
// notifications
addWearActions(builder, newMessages, newMessages, account, allRefs, data.messages, account.getAccountNumber());
addWearActions(builder, newMessages, newMessages, account, allRefs, data.messages);
}

// Mark Read on phone
Expand All @@ -4962,7 +4960,7 @@ private void notifyAccountWithDataLocked(Context context, final Account account,
? R.drawable.ic_action_mark_as_read_dark_vector
: R.drawable.ic_action_mark_as_read_dark,
context.getString(R.string.notification_action_mark_as_read),
NotificationActionService.getReadAllMessagesIntent(context, account, allRefs, account.getAccountNumber()));
NotificationActionService.getReadAllMessagesIntent(context, account, allRefs));

NotificationQuickDelete deleteOption = K9.getNotificationQuickDeleteBehaviour();
boolean showDeleteAction = deleteOption == NotificationQuickDelete.ALWAYS ||
Expand All @@ -4979,7 +4977,7 @@ private void notifyAccountWithDataLocked(Context context, final Account account,
? R.drawable.ic_action_delete_dark_vector
: R.drawable.ic_action_delete_dark,
context.getString(R.string.notification_action_delete),
NotificationDeleteConfirmation.getIntent(context, account, allRefs, account.getAccountNumber()));
NotificationDeleteConfirmation.getIntent(context, account, allRefs));
}

} else { // no extended notifications supported
Expand All @@ -5001,7 +4999,7 @@ private void notifyAccountWithDataLocked(Context context, final Account account,
builder.setContentIntent(stack.getPendingIntent(
account.getAccountNumber(),
PendingIntent.FLAG_CANCEL_CURRENT | PendingIntent.FLAG_ONE_SHOT));
builder.setDeleteIntent(NotificationActionService.getAcknowledgeIntent(context, account, account.getAccountNumber()));
builder.setDeleteIntent(NotificationActionService.getAcknowledgeIntent(context, account));

// Only ring or vibrate if we have not done so already on this account and fetch
boolean ringAndVibrate = false;
Expand Down Expand Up @@ -5277,15 +5275,15 @@ public void notifyAccountCancel(final Context context, final Account account) {
notificationManager.cancel(-1000 - account.getAccountNumber());

// cancel stacked notifications on Android Wear that share this as a summary notification
//NotificationData data = notificationData.get(account.getAccountNumber());
//if (data != null) {
// Collection<Integer> stackedChildNotifications = data.getStackedChildNotifications();
// if (stackedChildNotifications != null) {
// for (Integer stackedNotificationId : stackedChildNotifications) {
// notificationManager.cancel(stackedNotificationId);
// }
// }
//}
NotificationData data = notificationData.get(account.getAccountNumber());
if (data != null) {
Collection<Integer> stackedChildNotifications = data.getStackedChildNotifications();
if (stackedChildNotifications != null) {
for (Integer stackedNotificationId : stackedChildNotifications) {
notificationManager.cancel(stackedNotificationId);
}
}
}

notificationData.remove(account.getAccountNumber());
}
Expand Down
Loading

0 comments on commit 8116f9c

Please sign in to comment.