Add delete action to notification.

This commit is contained in:
Danny Baumann 2013-01-04 08:24:03 +01:00
parent 220a2da195
commit 0bf3dddafc
10 changed files with 332 additions and 46 deletions

View File

@ -172,6 +172,14 @@
android:configChanges="locale"
>
</activity>
<activity
android:name=".activity.NotificationDeleteConfirmation"
android:theme="@android:style/Theme.Translucent.NoTitleBar"
android:launchMode="singleTop"
android:taskAffinity=""
android:excludeFromRecents="true"
>
</activity>
<!-- XXX Note: this activity is hacked to ignore config changes,
since it doesn't currently handle them correctly in code. -->
<activity

View File

@ -701,4 +701,16 @@
<item name="3">ALWAYS</item>
</string-array>
<string-array name="global_settings_notification_quick_delete_entries">
<item name="1">@string/global_settings_notification_quick_delete_never</item>
<item name="2">@string/global_settings_notification_quick_delete_when_single_msg</item>
<item name="3">@string/global_settings_notification_quick_delete_always</item>
</string-array>
<string-array name="global_settings_notification_quick_delete_values">
<item name="1">NEVER</item>
<item name="2">FOR_SINGLE_MSG</item>
<item name="3">ALWAYS</item>
</string-array>
</resources>

View File

@ -220,6 +220,7 @@ Please submit bug reports, contribute new features and ask questions at
<string name="notification_action_reply">Reply</string>
<string name="notification_action_read">Read</string>
<string name="notification_action_delete">Delete</string>
<string name="notification_bg_sync_ticker">Checking mail: <xliff:g id="account">%s</xliff:g>:<xliff:g id="folder">%s</xliff:g></string>
<string name="notification_bg_sync_title">Checking mail</string>
@ -334,12 +335,19 @@ Please submit bug reports, contribute new features and ask questions at
<string name="global_settings_confirm_action_delete">Delete (in message view)</string>
<string name="global_settings_confirm_action_delete_starred">Delete Starred (in message view)</string>
<string name="global_settings_confirm_action_spam">Spam</string>
<string name="global_settings_confirm_action_delete_notif">Delete (from notification)</string>
<string name="global_settings_notification_hide_subject_title">Hide subject in notifications</string>
<string name="global_settings_notification_hide_subject_never">Never</string>
<string name="global_settings_notification_hide_subject_when_locked">When device is locked</string>
<string name="global_settings_notification_hide_subject_always">Always</string>
<string name="global_settings_notification_quick_delete_title">Show \'Delete\' button</string>
<string name="global_settings_notification_quick_delete_never">Never</string>
<string name="global_settings_notification_quick_delete_when_single_msg">For single message notification</string>
<string name="global_settings_notification_quick_delete_always">Always</string>
<string name="global_settings_notification_quick_delete_description">Show a button in the notification that allows quick message deletion</string>
<string name="global_settings_batch_buttons">Batch buttons</string>
<string name="global_settings_batch_buttons_summary">Configure message list batch buttons</string>
<string name="global_settings_mark_read">Mark read/unread</string>
@ -962,6 +970,10 @@ Please submit bug reports, contribute new features and ask questions at
<string name="dialog_confirm_delete_title">Confirm deletion</string>
<string name="dialog_confirm_delete_message">Do you want to delete this message?</string>
<plurals name="dialog_confirm_delete_message">
<item quantity="one">Do you really want to delete this message?</item>
<item quantity="other">Do you really want to delete <xliff:g id="message_count">%1$d</xliff:g> messages?</item>
</plurals>
<string name="dialog_confirm_delete_confirm_button">Yes</string>
<string name="dialog_confirm_delete_cancel_button">No</string>

View File

@ -113,4 +113,21 @@
<!-- Prior to Honeycomb we always use the light theme for dialogs -->
<style name="Theme.K9.Dialog.Dark" parent="Theme.K9.Dialog.Light" />
<style name="Theme.K9.Dialog.Translucent.Dark" parent="Theme.Sherlock.Dialog">
<item name="android:windowBackground">@android:color/transparent</item>
<item name="android:colorBackgroundCacheHint">@null</item>
<item name="android:windowIsTranslucent">true</item>
<item name="android:windowNoTitle">true</item>
<item name="android:windowContentOverlay">@null</item>
<item name="android:windowAnimationStyle">@android:style/Animation.Translucent</item>
</style>
<style name="Theme.K9.Dialog.Translucent.Light" parent="Theme.Sherlock.Light.Dialog">
<item name="android:windowBackground">@android:color/transparent</item>
<item name="android:colorBackgroundCacheHint">@null</item>
<item name="android:windowIsTranslucent">true</item>
<item name="android:windowNoTitle">true</item>
<item name="android:windowContentOverlay">@null</item>
<item name="android:windowAnimationStyle">@android:style/Animation.Translucent</item>
</style>
</resources>

View File

@ -294,6 +294,17 @@
android:dialogTitle="@string/quiet_time_ends"
android:title="@string/quiet_time_ends"
/>
<ListPreference
android:key="notification_quick_delete"
android:persistent="false"
android:title="@string/global_settings_notification_quick_delete_title"
android:entries="@array/global_settings_notification_quick_delete_entries"
android:entryValues="@array/global_settings_notification_quick_delete_values"
android:dialogTitle="@string/global_settings_notification_quick_delete_title"
android:summary="@string/global_settings_notification_quick_delete_description"
/>
</PreferenceScreen>
<PreferenceScreen

View File

@ -186,6 +186,7 @@ public class K9 extends Application {
private static boolean mConfirmDelete = false;
private static boolean mConfirmDeleteStarred = false;
private static boolean mConfirmSpam = false;
private static boolean mConfirmDeleteFromNotification = true;
private static NotificationHideSubject sNotificationHideSubject = NotificationHideSubject.NEVER;
@ -198,6 +199,17 @@ public class K9 extends Application {
NEVER
}
private static NotificationQuickDelete sNotificationQuickDelete = NotificationQuickDelete.NEVER;
/**
* Controls behaviour of delete button in notifications.
*/
public enum NotificationQuickDelete {
ALWAYS,
FOR_SINGLE_MSG,
NEVER
}
private static boolean mMessageListCheckboxes = false;
private static int mMessageListPreviewLines = 2;
@ -503,11 +515,13 @@ public class K9 extends Application {
editor.putBoolean("confirmDelete", mConfirmDelete);
editor.putBoolean("confirmDeleteStarred", mConfirmDeleteStarred);
editor.putBoolean("confirmSpam", mConfirmSpam);
editor.putBoolean("confirmDeleteFromNotification", mConfirmDeleteFromNotification);
editor.putString("sortTypeEnum", mSortType.name());
editor.putBoolean("sortAscending", mSortAscending.get(mSortType));
editor.putString("notificationHideSubject", sNotificationHideSubject.toString());
editor.putString("notificationQuickDelete", sNotificationQuickDelete.toString());
editor.putString("attachmentdefaultpath", mAttachmentDefaultPath);
editor.putBoolean("useBackgroundAsUnreadIndicator", sUseBackgroundAsUnreadIndicator);
@ -691,6 +705,7 @@ public class K9 extends Application {
mConfirmDelete = sprefs.getBoolean("confirmDelete", false);
mConfirmDeleteStarred = sprefs.getBoolean("confirmDeleteStarred", false);
mConfirmSpam = sprefs.getBoolean("confirmSpam", false);
mConfirmDeleteFromNotification = sprefs.getBoolean("confirmDeleteFromNotification", true);
try {
String value = sprefs.getString("sortTypeEnum", Account.DEFAULT_SORT_TYPE.name());
@ -712,6 +727,11 @@ public class K9 extends Application {
sNotificationHideSubject = NotificationHideSubject.valueOf(notificationHideSubject);
}
String notificationQuickDelete = sprefs.getString("notificationQuickDelete", null);
if (notificationQuickDelete != null) {
sNotificationQuickDelete = NotificationQuickDelete.valueOf(notificationQuickDelete);
}
mAttachmentDefaultPath = sprefs.getString("attachmentdefaultpath", Environment.getExternalStorageDirectory().toString());
sUseBackgroundAsUnreadIndicator = sprefs.getBoolean("useBackgroundAsUnreadIndicator", true);
sThreadedViewEnabled = sprefs.getBoolean("threadedView", true);
@ -1107,6 +1127,14 @@ public class K9 extends Application {
mConfirmSpam = confirm;
}
public static boolean confirmDeleteFromNotification() {
return mConfirmDeleteFromNotification;
}
public static void setConfirmDeleteFromNotification(final boolean confirm) {
mConfirmDeleteFromNotification = confirm;
}
public static NotificationHideSubject getNotificationHideSubject() {
return sNotificationHideSubject;
}
@ -1115,6 +1143,14 @@ public class K9 extends Application {
sNotificationHideSubject = mode;
}
public static NotificationQuickDelete getNotificationQuickDeleteBehaviour() {
return sNotificationQuickDelete;
}
public static void setNotificationQuickDeleteBehaviour(final NotificationQuickDelete mode) {
sNotificationQuickDelete = mode;
}
public static boolean batchButtonsMarkRead() {
return mBatchButtonsMarkRead;
}

View File

@ -0,0 +1,103 @@
package com.fsck.k9.activity;
import java.util.ArrayList;
import android.app.Activity;
import android.app.AlertDialog;
import android.app.Dialog;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import com.fsck.k9.Account;
import com.fsck.k9.K9;
import com.fsck.k9.Preferences;
import com.fsck.k9.R;
import com.fsck.k9.service.NotificationActionService;
public class NotificationDeleteConfirmation extends Activity {
private final static String EXTRA_ACCOUNT = "account";
private final static String EXTRA_MESSAGE_LIST = "messages";
private final static int DIALOG_CONFIRM = 1;
private Account mAccount;
private ArrayList<MessageReference> mMessageRefs;
public static PendingIntent getIntent(Context context, final Account account, final ArrayList<MessageReference> refs) {
Intent i = new Intent(context, NotificationDeleteConfirmation.class);
i.putExtra(EXTRA_ACCOUNT, account.getUuid());
i.putExtra(EXTRA_MESSAGE_LIST, refs);
i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP);
return PendingIntent.getActivity(context, account.getAccountNumber(), i, PendingIntent.FLAG_UPDATE_CURRENT);
}
@Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
setTheme(K9.getK9Theme() == K9.THEME_LIGHT ?
R.style.Theme_K9_Dialog_Translucent_Light : R.style.Theme_K9_Dialog_Translucent_Dark);
final Preferences preferences = Preferences.getPreferences(this);
final Intent intent = getIntent();
mAccount = preferences.getAccount(intent.getStringExtra(EXTRA_ACCOUNT));
mMessageRefs = (ArrayList<MessageReference>) intent.getSerializableExtra(EXTRA_MESSAGE_LIST);
if (mAccount == null || mMessageRefs == null || mMessageRefs.isEmpty()) {
finish();
} else if (!K9.confirmDeleteFromNotification()) {
triggerDelete();
finish();
} else {
showDialog(DIALOG_CONFIRM);
}
}
@Override
public Dialog onCreateDialog(int id) {
switch (id) {
case DIALOG_CONFIRM:
return ConfirmationDialog.create(this, id,
R.string.dialog_confirm_delete_title, "",
R.string.dialog_confirm_delete_confirm_button,
R.string.dialog_confirm_delete_cancel_button,
new Runnable() {
@Override
public void run() {
triggerDelete();
finish();
}
},
new Runnable() {
@Override
public void run() {
finish();
}
});
}
return super.onCreateDialog(id);
}
@Override
public void onPrepareDialog(int id, Dialog d) {
AlertDialog alert = (AlertDialog) d;
switch (id) {
case DIALOG_CONFIRM:
alert.setMessage(getResources().getQuantityString(
R.plurals.dialog_confirm_delete_message, mMessageRefs.size()));
break;
}
super.onPrepareDialog(id, d);
}
private void triggerDelete() {
Intent i = NotificationActionService.getDeleteAllMessagesIntent(this, mAccount, mMessageRefs);
startService(i);
}
}

View File

@ -17,15 +17,18 @@ import android.preference.CheckBoxPreference;
import android.preference.ListPreference;
import android.preference.Preference;
import android.preference.Preference.OnPreferenceClickListener;
import android.preference.PreferenceScreen;
import android.widget.Toast;
import com.fsck.k9.Account;
import com.fsck.k9.K9;
import com.fsck.k9.K9.NotificationHideSubject;
import com.fsck.k9.K9.NotificationQuickDelete;
import com.fsck.k9.Preferences;
import com.fsck.k9.R;
import com.fsck.k9.activity.ColorPickerDialog;
import com.fsck.k9.activity.K9PreferenceActivity;
import com.fsck.k9.controller.MessagingController;
import com.fsck.k9.helper.DateFormatter;
import com.fsck.k9.helper.FileBrowserHelper;
import com.fsck.k9.helper.FileBrowserHelper.FileBrowserFailOverCallback;
@ -72,6 +75,7 @@ public class Prefs extends K9PreferenceActivity {
private static final String PREFERENCE_QUIET_TIME_ENABLED = "quiet_time_enabled";
private static final String PREFERENCE_QUIET_TIME_STARTS = "quiet_time_starts";
private static final String PREFERENCE_QUIET_TIME_ENDS = "quiet_time_ends";
private static final String PREFERENCE_NOTIF_QUICK_DELETE = "notification_quick_delete";
private static final String PREFERENCE_BATCH_BUTTONS_MARK_READ = "batch_buttons_mark_read";
private static final String PREFERENCE_BATCH_BUTTONS_DELETE = "batch_buttons_delete";
private static final String PREFERENCE_BATCH_BUTTONS_ARCHIVE = "batch_buttons_archive";
@ -122,6 +126,7 @@ public class Prefs extends K9PreferenceActivity {
private CheckBoxPreference mQuietTimeEnabled;
private com.fsck.k9.preferences.TimePickerPreference mQuietTimeStarts;
private com.fsck.k9.preferences.TimePickerPreference mQuietTimeEnds;
private ListPreference mNotificationQuickDelete;
private Preference mAttachmentPathPreference;
private CheckBoxPreference mBatchButtonsMarkRead;
@ -196,16 +201,25 @@ public class Prefs extends K9PreferenceActivity {
mStartIntegratedInbox.setChecked(K9.startIntegratedInbox());
mConfirmActions = (CheckBoxListPreference) findPreference(PREFERENCE_CONFIRM_ACTIONS);
mConfirmActions.setItems(new CharSequence[] {
getString(R.string.global_settings_confirm_action_delete),
getString(R.string.global_settings_confirm_action_delete_starred),
getString(R.string.global_settings_confirm_action_spam),
});
mConfirmActions.setCheckedItems(new boolean[] {
K9.confirmDelete(),
K9.confirmDeleteStarred(),
K9.confirmSpam(),
});
boolean canDeleteFromNotification = MessagingController.platformSupportsExtendedNotifications();
CharSequence[] confirmActionEntries = new CharSequence[canDeleteFromNotification ? 4 : 3];
boolean[] confirmActionValues = new boolean[canDeleteFromNotification ? 4 : 3];
int index = 0;
confirmActionEntries[index] = getString(R.string.global_settings_confirm_action_delete);
confirmActionValues[index++] = K9.confirmDelete();
confirmActionEntries[index] = getString(R.string.global_settings_confirm_action_delete_starred);
confirmActionValues[index++] = K9.confirmDeleteStarred();
if (canDeleteFromNotification) {
confirmActionEntries[index] = getString(R.string.global_settings_confirm_action_delete_notif);
confirmActionValues[index++] = K9.confirmDeleteFromNotification();
}
confirmActionEntries[index] = getString(R.string.global_settings_confirm_action_spam);
confirmActionValues[index++] = K9.confirmSpam();
mConfirmActions.setItems(confirmActionEntries);
mConfirmActions.setCheckedItems(confirmActionValues);
mNotificationHideSubject = setupListPreference(PREFERENCE_NOTIFICATION_HIDE_SUBJECT,
K9.getNotificationHideSubject().toString());
@ -305,8 +319,13 @@ public class Prefs extends K9PreferenceActivity {
}
});
mNotificationQuickDelete = setupListPreference(PREFERENCE_NOTIF_QUICK_DELETE,
K9.getNotificationQuickDeleteBehaviour().toString());
if (!MessagingController.platformSupportsExtendedNotifications()) {
PreferenceScreen prefs = (PreferenceScreen) findPreference("notification_preferences");
prefs.removePreference(mNotificationQuickDelete);
mNotificationQuickDelete = null;
}
mBackgroundOps = setupListPreference(PREFERENCE_BACKGROUND_OPS, K9.getBackgroundOps().toString());
// In ICS+ there is no 'background data' setting that apps can chose to ignore anymore. So
@ -420,11 +439,16 @@ public class Prefs extends K9PreferenceActivity {
K9.setUseVolumeKeysForNavigation(mVolumeNavigation.getCheckedItems()[0]);
K9.setUseVolumeKeysForListNavigation(mVolumeNavigation.getCheckedItems()[1]);
K9.setStartIntegratedInbox(!mHideSpecialAccounts.isChecked() && mStartIntegratedInbox.isChecked());
K9.setConfirmDelete(mConfirmActions.getCheckedItems()[0]);
K9.setConfirmDeleteStarred(mConfirmActions.getCheckedItems()[1]);
K9.setConfirmSpam(mConfirmActions.getCheckedItems()[2]);
K9.setNotificationHideSubject(NotificationHideSubject.valueOf(mNotificationHideSubject.getValue()));
int index = 0;
K9.setConfirmDelete(mConfirmActions.getCheckedItems()[index++]);
K9.setConfirmDeleteStarred(mConfirmActions.getCheckedItems()[index++]);
if (MessagingController.platformSupportsExtendedNotifications()) {
K9.setConfirmDeleteFromNotification(mConfirmActions.getCheckedItems()[index++]);
}
K9.setConfirmSpam(mConfirmActions.getCheckedItems()[index++]);
K9.setMeasureAccounts(mMeasureAccounts.isChecked());
K9.setCountSearchMessages(mCountSearch.isChecked());
K9.setHideSpecialAccounts(mHideSpecialAccounts.isChecked());
@ -445,6 +469,11 @@ public class Prefs extends K9PreferenceActivity {
K9.setQuietTimeStarts(mQuietTimeStarts.getTime());
K9.setQuietTimeEnds(mQuietTimeEnds.getTime());
if (mNotificationQuickDelete != null) {
K9.setNotificationQuickDeleteBehaviour(
NotificationQuickDelete.valueOf(mNotificationQuickDelete.getValue()));
}
K9.setBatchButtonsMarkRead(mBatchButtonsMarkRead.isChecked());
K9.setBatchButtonsDelete(mBatchButtonsDelete.isChecked());
K9.setBatchButtonsArchive(mBatchButtonsArchive.isChecked());

View File

@ -43,12 +43,14 @@ import com.fsck.k9.AccountStats;
import com.fsck.k9.K9;
import com.fsck.k9.K9.NotificationHideSubject;
import com.fsck.k9.K9.Intents;
import com.fsck.k9.K9.NotificationQuickDelete;
import com.fsck.k9.NotificationSetting;
import com.fsck.k9.Preferences;
import com.fsck.k9.R;
import com.fsck.k9.activity.FolderList;
import com.fsck.k9.activity.MessageList;
import com.fsck.k9.activity.MessageReference;
import com.fsck.k9.activity.NotificationDeleteConfirmation;
import com.fsck.k9.helper.Contacts;
import com.fsck.k9.helper.HtmlConverter;
import com.fsck.k9.helper.power.TracingPowerManager;
@ -227,6 +229,15 @@ public class MessagingController implements Runnable {
};
}
public ArrayList<MessageReference> getAllMessageRefs() {
ArrayList<MessageReference> refs = new ArrayList<MessageReference>();
refs.addAll(droppedMessages);
for (Message m : messages) {
refs.add(m.makeMessageReference());
}
return refs;
}
public int getNewMessageCount() {
return messages.size() + droppedMessages.size();
}
@ -4564,13 +4575,13 @@ public class MessagingController implements Runnable {
return summary;
}
private static boolean platformShowsNumberInNotification() {
private static final boolean platformShowsNumberInNotification() {
// Honeycomb and newer don't show the number as overlay on the notification icon.
// However, the number will appear in the detailed notification view.
return Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB;
}
private static boolean platformSupportsExtendedNotifications() {
public static final boolean platformSupportsExtendedNotifications() {
// supported in Jellybean
// TODO: use constant once target SDK is set to >= 16
return Build.VERSION.SDK_INT >= 16;
@ -4689,11 +4700,26 @@ public class MessagingController implements Runnable {
builder.addAction(R.drawable.ic_action_single_message_options_dark,
context.getString(R.string.notification_action_reply),
NotificationActionService.getReplyIntent(context, account, message));
NotificationActionService.getReplyIntent(context, account, message.makeMessageReference()));
}
final ArrayList<MessageReference> allRefs = data.getAllMessageRefs();
builder.addAction(R.drawable.ic_action_mark_as_read_dark,
context.getString(R.string.notification_action_read),
NotificationActionService.getReadAllMessagesIntent(context, account, data.messages));
NotificationActionService.getReadAllMessagesIntent(context, account, allRefs));
NotificationQuickDelete deleteOption = K9.getNotificationQuickDeleteBehaviour();
boolean showDeleteAction = deleteOption == NotificationQuickDelete.ALWAYS ||
(deleteOption == NotificationQuickDelete.FOR_SINGLE_MSG && newMessages == 1);
if (showDeleteAction) {
// we need to pass the action directly to the activity, otherwise the
// status bar won't be pulled up and we won't see the confirmation (if used)
builder.addAction(R.drawable.ic_action_delete_dark,
context.getString(R.string.notification_action_delete),
NotificationDeleteConfirmation.getIntent(context, account, allRefs));
}
} else {
String accountNotice = context.getString(R.string.notification_new_one_account_fmt,
unreadCount, accountDescr);

View File

@ -1,7 +1,6 @@
package com.fsck.k9.service;
import java.util.ArrayList;
import java.util.Collection;
import com.fsck.k9.Account;
import com.fsck.k9.K9;
@ -22,27 +21,23 @@ import android.util.Log;
public class NotificationActionService extends CoreService {
private final static String REPLY_ACTION = "com.fsck.k9.service.NotificationActionService.REPLY_ACTION";
private final static String READ_ALL_ACTION = "com.fsck.k9.service.NotificationActionService.READ_ALL_ACTION";
private final static String DELETE_ALL_ACTION = "com.fsck.k9.service.NotificationActionService.DELETE_ALL_ACTION";
private final static String EXTRA_ACCOUNT = "account";
private final static String EXTRA_MESSAGE = "message";
private final static String EXTRA_MESSAGE_LIST = "messages";
public static PendingIntent getReplyIntent(Context context, final Account account, final Message message) {
public static PendingIntent getReplyIntent(Context context, final Account account, final MessageReference ref) {
Intent i = new Intent(context, NotificationActionService.class);
i.putExtra(EXTRA_ACCOUNT, account.getUuid());
i.putExtra(EXTRA_MESSAGE, message.makeMessageReference());
i.putExtra(EXTRA_MESSAGE, ref);
i.setAction(REPLY_ACTION);
return PendingIntent.getService(context, account.getAccountNumber(), i, PendingIntent.FLAG_UPDATE_CURRENT);
}
public static PendingIntent getReadAllMessagesIntent(Context context, final Account account, final Collection<Message> messages) {
ArrayList<MessageReference> refs = new ArrayList<MessageReference>();
for (Message m : messages) {
refs.add(m.makeMessageReference());
}
public static PendingIntent getReadAllMessagesIntent(Context context, final Account account,
final ArrayList<MessageReference> refs) {
Intent i = new Intent(context, NotificationActionService.class);
i.putExtra(EXTRA_ACCOUNT, account.getUuid());
i.putExtra(EXTRA_MESSAGE_LIST, refs);
@ -51,6 +46,36 @@ public class NotificationActionService extends CoreService {
return PendingIntent.getService(context, account.getAccountNumber(), i, PendingIntent.FLAG_UPDATE_CURRENT);
}
public static Intent getDeleteAllMessagesIntent(Context context, final Account account,
final ArrayList<MessageReference> refs) {
Intent i = new Intent(context, NotificationActionService.class);
i.putExtra(EXTRA_ACCOUNT, account.getUuid());
i.putExtra(EXTRA_MESSAGE_LIST, refs);
i.setAction(DELETE_ALL_ACTION);
return i;
}
private static Message getMessageFromRef(final Account account, MessageReference ref) {
try {
Folder folder = account.getLocalStore().getFolder(ref.folderName);
if (folder != null) {
Message message = folder.getMessage(ref.uid);
if (message != null) {
return message;
} else {
Log.w(K9.LOG_TAG, "Could not find message for notification action.");
}
} else {
Log.w(K9.LOG_TAG, "Could not find folder for notification action.");
}
} catch (MessagingException e) {
Log.w(K9.LOG_TAG, "Could not retrieve message for reference.", e);
}
return null;
}
@Override
public int startService(Intent intent, int startId) {
if (K9.DEBUG)
@ -69,27 +94,34 @@ public class NotificationActionService extends CoreService {
for (MessageReference ref : refs) {
controller.setFlag(account, ref.folderName, ref.uid, Flag.SEEN, true);
}
} else if (DELETE_ALL_ACTION.equals(intent.getAction())) {
if (K9.DEBUG)
Log.i(K9.LOG_TAG, "NotificationActionService deleting messages");
ArrayList<MessageReference> refs = (ArrayList<MessageReference>)
intent.getSerializableExtra(EXTRA_MESSAGE_LIST);
ArrayList<Message> messages = new ArrayList<Message>();
for (MessageReference ref : refs) {
Message m = getMessageFromRef(account, ref);
if (m != null) {
messages.add(m);
}
}
controller.deleteMessages(messages, null);
} else if (REPLY_ACTION.equals(intent.getAction())) {
if (K9.DEBUG)
Log.i(K9.LOG_TAG, "NotificationActionService initiating reply");
try {
MessageReference ref = (MessageReference) intent.getParcelableExtra(EXTRA_MESSAGE);
Folder folder = account.getLocalStore().getFolder(ref.folderName);
if (folder != null) {
Message message = folder.getMessage(ref.uid);
if (message != null) {
Intent i = MessageCompose.getActionReplyIntent(this, account, message, false, null);
i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(i);
} else {
Log.w(K9.LOG_TAG, "Could not find message for notification action.");
}
} else {
Log.w(K9.LOG_TAG, "Could not find folder for notification action.");
}
} catch (MessagingException e) {
Log.w(K9.LOG_TAG, "Could not execute reply action.", e);
MessageReference ref = (MessageReference) intent.getParcelableExtra(EXTRA_MESSAGE);
Message message = getMessageFromRef(account, ref);
if (message != null) {
Intent i = MessageCompose.getActionReplyIntent(this, account, message, false, null);
i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(i);
} else {
Log.i(K9.LOG_TAG, "Could not execute reply action.");
}
}