mirror of
https://github.com/moparisthebest/k-9
synced 2024-12-24 08:38:51 -05:00
Fixed "managed" back button behavior in MessageView
This commit is contained in:
parent
d1778e0303
commit
50058a92db
@ -218,6 +218,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.
|
||||
@ -547,6 +548,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);
|
||||
@ -633,36 +664,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) {
|
||||
@ -1078,7 +1109,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());
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -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 EXTRA_SCROLL_PERCENTAGE = "com.fsck.k9.MessageView_scrollPercentage";
|
||||
private static final String SHOW_PICTURES = "showPictures";
|
||||
private static final String STATE_PGP_DATA = "pgpData";
|
||||
@ -77,6 +78,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) {
|
||||
@ -248,8 +257,9 @@ public class MessageView extends K9Activity implements OnClickListener {
|
||||
@Override
|
||||
public void onBackPressed() {
|
||||
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 {
|
||||
super.onBackPressed();
|
||||
@ -308,8 +318,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);
|
||||
@ -362,6 +373,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) {
|
||||
// TODO This code seems unnecessary since the icicle should already be thawed in onRestoreInstanceState().
|
||||
|
Loading…
Reference in New Issue
Block a user