Include a full activity back stack when building notification intents.

This commit is contained in:
Danny Baumann 2013-03-10 12:29:06 +01:00
parent d523caa61b
commit 3ff522c9c4
5 changed files with 60 additions and 81 deletions

View File

@ -7,7 +7,6 @@ import java.util.List;
import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.os.Handler;
import android.os.PowerManager;
@ -72,8 +71,6 @@ import de.cketti.library.changelog.ChangeLog;
public class FolderList extends K9ListActivity {
private static final String EXTRA_ACCOUNT = "account";
private static final String EXTRA_INITIAL_FOLDER = "initialFolder";
private static final String EXTRA_FROM_NOTIFICATION = "fromNotification";
private static final String EXTRA_FROM_SHORTCUT = "fromShortcut";
private static final boolean REFRESH_REMOTE = true;
@ -233,15 +230,11 @@ public class FolderList extends K9ListActivity {
sendMail(mAccount);
}
public static Intent actionHandleAccountIntent(Context context, Account account, String initialFolder, boolean fromShortcut) {
public static Intent actionHandleAccountIntent(Context context, Account account, boolean fromShortcut) {
Intent intent = new Intent(context, FolderList.class);
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
intent.putExtra(EXTRA_ACCOUNT, account.getUuid());
if (initialFolder != null) {
intent.putExtra(EXTRA_INITIAL_FOLDER, initialFolder);
}
if (fromShortcut) {
intent.putExtra(EXTRA_FROM_SHORTCUT, true);
}
@ -250,26 +243,10 @@ public class FolderList extends K9ListActivity {
}
public static void actionHandleAccount(Context context, Account account) {
Intent intent = actionHandleAccountIntent(context, account, null, false);
Intent intent = actionHandleAccountIntent(context, account, false);
context.startActivity(intent);
}
public static Intent actionHandleNotification(Context context, Account account, String initialFolder) {
Intent intent = new Intent(
Intent.ACTION_VIEW,
Uri.parse("email://accounts/" + account.getAccountNumber()),
context,
FolderList.class);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP);
intent.putExtra(EXTRA_ACCOUNT, account.getUuid());
intent.putExtra(EXTRA_FROM_NOTIFICATION, true);
if (initialFolder != null) {
intent.putExtra(EXTRA_INITIAL_FOLDER, initialFolder);
}
return intent;
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
@ -325,8 +302,6 @@ public class FolderList extends K9ListActivity {
public void onNewIntent(Intent intent) {
setIntent(intent); // onNewIntent doesn't autoset our "internal" intent
String initialFolder;
mUnreadMessageCount = 0;
String accountUuid = intent.getStringExtra(EXTRA_ACCOUNT);
mAccount = Preferences.getPreferences(this).getAccount(accountUuid);
@ -337,16 +312,7 @@ public class FolderList extends K9ListActivity {
return;
}
initialFolder = intent.getStringExtra(EXTRA_INITIAL_FOLDER);
boolean fromNotification = intent.getBooleanExtra(EXTRA_FROM_NOTIFICATION, false);
if (fromNotification && mAccount.goToUnreadMessageSearch()) {
MessagingController.getInstance(getApplication()).notifyAccountCancel(this, mAccount);
openUnreadSearch(this, mAccount);
finish();
} else if (initialFolder != null && !K9.FOLDER_NONE.equals(initialFolder)) {
onOpenFolder(initialFolder);
finish();
} else if (intent.getBooleanExtra(EXTRA_FROM_SHORTCUT, false) &&
if (intent.getBooleanExtra(EXTRA_FROM_SHORTCUT, false) &&
!K9.FOLDER_NONE.equals(mAccount.getAutoExpandFolderName())) {
onOpenFolder(mAccount.getAutoExpandFolderName());
finish();
@ -1261,14 +1227,4 @@ public class FolderList extends K9ListActivity {
MessageList.actionDisplaySearch(FolderList.this, search, true, false);
}
}
private void openUnreadSearch(Context context, final Account account) {
String description = getString(R.string.search_title, mAccount.getDescription(), getString(R.string.unread_modifier));
LocalSearch search = new LocalSearch(description);
search.addAccountUuid(account.getUuid());
search.and(Searchfield.READ, "1", Attribute.NOT_EQUALS);
MessageList.actionDisplaySearch(context, search, true, false);
}
}

View File

@ -34,8 +34,7 @@ public class LauncherShortcuts extends AccountList {
SearchAccount searchAccount = (SearchAccount) account;
shortcutIntent = MessageList.shortcutIntent(this, searchAccount.getId());
} else {
shortcutIntent = FolderList.actionHandleAccountIntent(this, (Account) account, null,
true);
shortcutIntent = FolderList.actionHandleAccountIntent(this, (Account) account, true);
}
Intent intent = new Intent();

View File

@ -132,13 +132,6 @@ public class MessageList extends K9FragmentActivity implements MessageListFragme
return intent;
}
public static Intent actionHandleNotificationIntent(Context context,
MessageReference messageReference) {
Intent intent = actionDisplayMessageIntent(context, messageReference);
intent.setFlags(intent.getFlags() | Intent.FLAG_ACTIVITY_NEW_TASK);
return intent;
}
private enum DisplayMode {
MESSAGE_LIST,

View File

@ -33,6 +33,7 @@ import android.os.Build;
import android.os.PowerManager;
import android.os.Process;
import android.support.v4.app.NotificationCompat;
import android.support.v4.app.TaskStackBuilder;
import android.text.SpannableStringBuilder;
import android.text.TextUtils;
import android.text.style.TextAppearanceSpan;
@ -47,6 +48,7 @@ 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.Accounts;
import com.fsck.k9.activity.FolderList;
import com.fsck.k9.activity.MessageList;
import com.fsck.k9.activity.MessageReference;
@ -89,6 +91,8 @@ import com.fsck.k9.search.ConditionsTreeNode;
import com.fsck.k9.search.LocalSearch;
import com.fsck.k9.search.SearchAccount;
import com.fsck.k9.search.SearchSpecification;
import com.fsck.k9.search.SearchSpecification.Attribute;
import com.fsck.k9.search.SearchSpecification.Searchfield;
import com.fsck.k9.search.SqlQueryBuilder;
import com.fsck.k9.service.NotificationActionService;
@ -3344,13 +3348,9 @@ public class MessagingController implements Runnable {
builder.setContentTitle(mApplication.getString(R.string.notification_bg_send_title));
builder.setContentText(account.getDescription());
LocalSearch search = new LocalSearch(account.getInboxFolderName());
search.addAllowedFolder(account.getInboxFolderName());
search.addAccountUuid(account.getUuid());
Intent intent = MessageList.intentDisplaySearch(mApplication, search, false, true, true);
PendingIntent pi = PendingIntent.getActivity(mApplication, 0, intent, 0);
builder.setContentIntent(pi);
TaskStackBuilder stack = buildMessageListBackStack(mApplication, account,
account.getInboxFolderName());
builder.setContentIntent(stack.getPendingIntent(0, 0));
if (K9.NOTIFICATION_LED_WHILE_SYNCING) {
configureNotification(builder, null, null,
@ -3392,9 +3392,8 @@ public class MessagingController implements Runnable {
builder.setContentTitle(mApplication.getString(R.string.send_failure_subject));
builder.setContentText(getRootCauseMessage(lastFailure));
Intent i = FolderList.actionHandleNotification(mApplication, account, openFolder);
PendingIntent pi = PendingIntent.getActivity(mApplication, 0, i, 0);
builder.setContentIntent(pi);
TaskStackBuilder stack = buildFolderListBackStack(mApplication, account);
builder.setContentIntent(stack.getPendingIntent(0, 0));
configureNotification(builder, null, null, K9.NOTIFICATION_LED_FAILURE_COLOR,
K9.NOTIFICATION_LED_BLINK_FAST, true);
@ -3430,13 +3429,9 @@ public class MessagingController implements Runnable {
mApplication.getString(R.string.notification_bg_title_separator) +
folder.getName());
LocalSearch search = new LocalSearch(account.getInboxFolderName());
search.addAllowedFolder(account.getInboxFolderName());
search.addAccountUuid(account.getUuid());
Intent intent = MessageList.intentDisplaySearch(mApplication, search, false, true, true);
PendingIntent pi = PendingIntent.getActivity(mApplication, 0, intent, 0);
builder.setContentIntent(pi);
TaskStackBuilder stack = buildMessageListBackStack(mApplication, account,
account.getInboxFolderName());
builder.setContentIntent(stack.getPendingIntent(0, 0));
if (K9.NOTIFICATION_LED_WHILE_SYNCING) {
configureNotification(builder, null, null,
@ -4914,7 +4909,7 @@ public class MessagingController implements Runnable {
}
}
Intent targetIntent;
TaskStackBuilder stack;
boolean treatAsSingleMessageNotification;
if (platformSupportsExtendedNotifications()) {
@ -4927,8 +4922,9 @@ public class MessagingController implements Runnable {
}
if (treatAsSingleMessageNotification) {
targetIntent = MessageList.actionHandleNotificationIntent(
context, message.makeMessageReference());
stack = buildMessageViewBackStack(context, message.makeMessageReference());
} else if (account.goToUnreadMessageSearch()) {
stack = buildUnreadBackStack(context, account);
} else {
String initialFolder = message.getFolder().getName();
/* only go to folder if all messages are in the same folder, else go to folder list */
@ -4939,11 +4935,11 @@ public class MessagingController implements Runnable {
}
}
targetIntent = FolderList.actionHandleNotification(context, account, initialFolder);
stack = buildMessageListBackStack(context, account, initialFolder);
}
builder.setContentIntent(PendingIntent.getActivity(context,
account.getAccountNumber(), targetIntent, PendingIntent.FLAG_UPDATE_CURRENT));
builder.setContentIntent(stack.getPendingIntent(
account.getAccountNumber(), PendingIntent.FLAG_UPDATE_CURRENT));
builder.setDeleteIntent(NotificationActionService.getAcknowledgeIntent(context, account));
// Only ring or vibrate if we have not done so already on this account and fetch
@ -4966,6 +4962,42 @@ public class MessagingController implements Runnable {
notifMgr.notify(account.getAccountNumber(), builder.build());
}
private TaskStackBuilder buildFolderListBackStack(Context context, Account account) {
TaskStackBuilder stack = TaskStackBuilder.create(context);
stack.addNextIntent(new Intent(context, Accounts.class).putExtra(Accounts.EXTRA_STARTUP, false));
stack.addNextIntent(FolderList.actionHandleAccountIntent(context, account, false));
return stack;
}
private TaskStackBuilder buildUnreadBackStack(Context context, final Account account) {
TaskStackBuilder stack = buildFolderListBackStack(context, account);
String description = context.getString(R.string.search_title,
account.getDescription(), context.getString(R.string.unread_modifier));
LocalSearch search = new LocalSearch(description);
search.addAccountUuid(account.getUuid());
search.and(Searchfield.READ, "1", Attribute.NOT_EQUALS);
stack.addNextIntent(MessageList.intentDisplaySearch(context, search, true, false, false));
return stack;
}
private TaskStackBuilder buildMessageListBackStack(Context context, Account account, String folder) {
TaskStackBuilder stack = buildFolderListBackStack(context, account);
if (folder != null) {
LocalSearch search = new LocalSearch(folder);
search.addAllowedFolder(folder);
search.addAccountUuid(account.getUuid());
stack.addNextIntent(MessageList.intentDisplaySearch(context, search, false, true, true));
}
return stack;
}
private TaskStackBuilder buildMessageViewBackStack(Context context, MessageReference message) {
Account account = Preferences.getPreferences(context).getAccount(message.accountUuid);
TaskStackBuilder stack = buildMessageListBackStack(context, account, message.folderName);
stack.addNextIntent(MessageList.actionDisplayMessageIntent(context, message));
return stack;
}
/**
* Configure the notification sound and LED
*

View File

@ -79,8 +79,7 @@ public class UnreadWidgetProvider extends AppWidgetProvider {
stats = realAccount.getStats(context);
if (K9.FOLDER_NONE.equals(realAccount.getAutoExpandFolderName())) {
clickIntent = FolderList.actionHandleAccountIntent(context, realAccount,
null, false);
clickIntent = FolderList.actionHandleAccountIntent(context, realAccount, false);
} else {
LocalSearch search = new LocalSearch(realAccount.getAutoExpandFolderName());
search.addAllowedFolder(realAccount.getAutoExpandFolderName());