1
0
mirror of https://github.com/moparisthebest/k-9 synced 2024-11-15 14:05:05 -05:00

Fixed "managed" back button behavior in MessageView

This commit is contained in:
cketti 2011-11-26 03:18:52 +01:00
parent 363f22146c
commit 7df4fa18c6
2 changed files with 65 additions and 21 deletions

View File

@ -217,6 +217,7 @@ public class MessageList
private static final String EXTRA_FOLDER_NAMES = "folderNames";
private static final String EXTRA_TITLE = "title";
private static final String EXTRA_LIST_POSITION = "listPosition";
private static final String EXTRA_RETURN_FROM_MESSAGE_VIEW = "returnFromMessageView";
/**
* Maps a {@link SORT_TYPE} to a {@link Comparator} implementation.
@ -546,6 +547,36 @@ public class MessageList
}
}
/**
* Show the message list that was used to open the {@link MessageView} for a message.
*
* <p>
* <strong>Note:</strong>
* The {@link MessageList} instance should still be around and all we do is bring it back to
* the front (see the activity flags).<br>
* Out of sheer paranoia we also set the extras that were used to create the original
* {@code MessageList} instance. Using those, the activity can be recreated in the unlikely
* case of it having been killed by the OS.
* </p>
*
* @param context
* The {@link Context} instance to invoke the {@link Context#startActivity(Intent)}
* method on.
* @param extras
* The extras used to create the original {@code MessageList} instance.
*
* @see MessageView#actionView(Context, MessageReference, ArrayList, Bundle)
*/
public static void actionHandleFolder(Context context, Bundle extras) {
Intent intent = new Intent(context, MessageList.class);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
intent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
intent.putExtras(extras);
intent.putExtra(EXTRA_RETURN_FROM_MESSAGE_VIEW, true);
context.startActivity(intent);
}
public static void actionHandleFolder(Context context, Account account, String folder) {
Intent intent = actionHandleFolderIntent(context, account, folder);
context.startActivity(intent);
@ -632,36 +663,36 @@ public class MessageList
mTouchView = K9.messageListTouchable();
mPreviewLines = K9.messageListPreviewLines();
onNewIntent(getIntent());
initializeMessageList(getIntent(), true);
}
@Override
public void onNewIntent(Intent intent) {
setIntent(intent); // onNewIntent doesn't autoset our "internal" intent
initializeMessageList(intent, false);
}
private void initializeMessageList(Intent intent, boolean create) {
boolean returnFromMessageView = intent.getBooleanExtra(
EXTRA_RETURN_FROM_MESSAGE_VIEW, false);
if (!create && returnFromMessageView) {
// We're returning from the MessageView activity with "Manage back button" enabled.
// So just leave the activity in the state it was left in.
return;
}
String accountUuid = intent.getStringExtra(EXTRA_ACCOUNT);
Account account = Preferences.getPreferences(this).getAccount(accountUuid);
String folderName = intent.getStringExtra(EXTRA_FOLDER);
String queryString = intent.getStringExtra(EXTRA_QUERY);
mAccount = Preferences.getPreferences(this).getAccount(accountUuid);
if (account != null && !account.isAvailable(this)) {
if (mAccount != null && !mAccount.isAvailable(this)) {
Log.i(K9.LOG_TAG, "not opening MessageList of unavailable account");
onAccountUnavailable();
return;
}
if (account != null && account.equals(mAccount) &&
folderName != null && folderName.equals(mFolderName) &&
((queryString != null && queryString.equals(mQueryString)) ||
(queryString == null && mQueryString == null))) {
// We're likely just returning from the MessageView activity with "Manage back button"
// enabled. So just leave the activity in the state it was left in.
return;
}
mAccount = account;
mFolderName = folderName;
mQueryString = queryString;
mFolderName = intent.getStringExtra(EXTRA_FOLDER);
mQueryString = intent.getStringExtra(EXTRA_QUERY);
String queryFlags = intent.getStringExtra(EXTRA_QUERY_FLAGS);
if (queryFlags != null) {
@ -1092,7 +1123,7 @@ public class MessageList
MessageReference ref = message.message.makeMessageReference();
Log.i(K9.LOG_TAG, "MessageList sending message " + ref);
MessageView.actionView(this, ref, messageRefs);
MessageView.actionView(this, ref, messageRefs, getIntent().getExtras());
}
/*

View File

@ -33,6 +33,7 @@ public class MessageView extends K9Activity implements OnClickListener {
private static final String EXTRA_MESSAGE_REFERENCE = "com.fsck.k9.MessageView_messageReference";
private static final String EXTRA_MESSAGE_REFERENCES = "com.fsck.k9.MessageView_messageReferences";
private static final String EXTRA_NEXT = "com.fsck.k9.MessageView_next";
private static final String EXTRA_MESSAGE_LIST_EXTRAS = "com.fsck.k9.MessageView_messageListExtras";
private static final String SHOW_PICTURES = "showPictures";
private static final String STATE_PGP_DATA = "pgpData";
private static final int ACTIVITY_CHOOSE_FOLDER_MOVE = 1;
@ -76,6 +77,14 @@ public class MessageView extends K9Activity implements OnClickListener {
*/
private String mDstFolder;
/**
* The extras used to create the {@link MessageList} instance that created this activity. May
* be {@code null}.
*
* @see MessageList#actionHandleFolder(Context, Bundle)
*/
private Bundle mMessageListExtras;
private final class StorageListenerImplementation implements StorageManager.StorageListener {
@Override
public void onUnmount(String providerId) {
@ -243,8 +252,9 @@ public class MessageView extends K9Activity implements OnClickListener {
// or later, or by the code above on earlier versions of the
// platform.
if (K9.manageBack()) {
String folder = (mMessage != null) ? mMessage.getFolder().getName() : null;
MessageList.actionHandleFolder(this, mAccount, folder);
if (mMessageListExtras != null) {
MessageList.actionHandleFolder(this, mMessageListExtras);
}
finish();
} else {
finish();
@ -303,8 +313,9 @@ public class MessageView extends K9Activity implements OnClickListener {
}
public static void actionView(Context context, MessageReference messRef,
ArrayList<MessageReference> messReferences) {
ArrayList<MessageReference> messReferences, Bundle messageListExtras) {
Intent i = new Intent(context, MessageView.class);
i.putExtra(EXTRA_MESSAGE_LIST_EXTRAS, messageListExtras);
i.putExtra(EXTRA_MESSAGE_REFERENCE, messRef);
i.putParcelableArrayListExtra(EXTRA_MESSAGE_REFERENCES, messReferences);
i.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK);
@ -352,6 +363,8 @@ public class MessageView extends K9Activity implements OnClickListener {
setTitle("");
final Intent intent = getIntent();
mMessageListExtras = intent.getParcelableExtra(EXTRA_MESSAGE_LIST_EXTRAS);
Uri uri = intent.getData();
if (icicle != null) {
mMessageReference = icicle.getParcelable(EXTRA_MESSAGE_REFERENCE);