Save/restore message list context
This fixes opening messages after rotations. Oops. Bug: 4905495 Change-Id: Ibb9984245f7a040b65d472ad4103da587c28c83b
This commit is contained in:
parent
ed839dce77
commit
53300963ff
|
@ -20,6 +20,7 @@ import android.os.Parcel;
|
|||
import android.os.Parcelable;
|
||||
|
||||
import com.android.emailcommon.provider.Mailbox;
|
||||
import com.google.common.base.Objects;
|
||||
|
||||
public class SearchParams implements Parcelable {
|
||||
public static final long ALL_MAILBOXES = Mailbox.NO_MAILBOX;
|
||||
|
@ -53,6 +54,33 @@ public class SearchParams implements Parcelable {
|
|||
mFilter = filter;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (o == this) {
|
||||
return true;
|
||||
}
|
||||
if ((o == null) || !(o instanceof SearchParams)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
SearchParams os = (SearchParams) o;
|
||||
return mMailboxId == os.mMailboxId
|
||||
&& mIncludeChildren == os.mIncludeChildren
|
||||
&& mFilter.equals(os.mFilter)
|
||||
&& mLimit == os.mLimit
|
||||
&& mOffset == os.mOffset;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hashCode(mMailboxId, mFilter, mOffset);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "[SearchParams " + mMailboxId + ":" + mFilter + " (" + mOffset + ", " + mLimit + "]";
|
||||
}
|
||||
|
||||
@Override
|
||||
public int describeContents() {
|
||||
return 0;
|
||||
|
|
|
@ -18,11 +18,14 @@ package com.android.email;
|
|||
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.os.Parcel;
|
||||
import android.os.Parcelable;
|
||||
|
||||
import com.android.email.activity.EmailActivity;
|
||||
import com.android.emailcommon.provider.Account;
|
||||
import com.android.emailcommon.provider.Mailbox;
|
||||
import com.android.emailcommon.service.SearchParams;
|
||||
import com.google.common.base.Objects;
|
||||
import com.google.common.base.Preconditions;
|
||||
|
||||
/**
|
||||
|
@ -30,7 +33,7 @@ import com.google.common.base.Preconditions;
|
|||
* This encapsulates the meta-data about the list of messages, which can either be the
|
||||
* {@link Mailbox} ID, or {@link SearchParams}.
|
||||
*/
|
||||
public class MessageListContext {
|
||||
public class MessageListContext implements Parcelable {
|
||||
|
||||
/**
|
||||
* The active account. Changing an account is a destructive enough operation that it warrants
|
||||
|
@ -121,4 +124,61 @@ public class MessageListContext {
|
|||
public long getMailboxId() {
|
||||
return mMailboxId;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (o == this) {
|
||||
return true;
|
||||
}
|
||||
if ((o == null) || !(o instanceof MessageListContext)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
MessageListContext om = (MessageListContext) o;
|
||||
return mAccountId == om.mAccountId
|
||||
&& mMailboxId == om.mMailboxId
|
||||
&& Objects.equal(mSearchParams, om.mSearchParams);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hashCode(mAccountId, mMailboxId, mSearchParams);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "[MessageListContext " + mAccountId + ":" + mMailboxId + ":" + mSearchParams + "]";
|
||||
}
|
||||
|
||||
|
||||
private MessageListContext(Parcel in) {
|
||||
mAccountId = in.readLong();
|
||||
mMailboxId = in.readLong();
|
||||
mSearchParams = in.readParcelable(SearchParams.class.getClassLoader());
|
||||
}
|
||||
|
||||
@Override
|
||||
public int describeContents() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeToParcel(Parcel dest, int flags) {
|
||||
dest.writeLong(mAccountId);
|
||||
dest.writeLong(mMailboxId);
|
||||
dest.writeParcelable(mSearchParams, flags);
|
||||
}
|
||||
|
||||
public static Parcelable.Creator<MessageListContext> CREATOR =
|
||||
new Parcelable.Creator<MessageListContext>() {
|
||||
@Override
|
||||
public MessageListContext createFromParcel(Parcel source) {
|
||||
return new MessageListContext(source);
|
||||
}
|
||||
|
||||
@Override
|
||||
public MessageListContext[] newArray(int size) {
|
||||
return new MessageListContext[size];
|
||||
}
|
||||
};
|
||||
}
|
||||
|
|
|
@ -43,13 +43,13 @@ import java.util.List;
|
|||
|
||||
/**
|
||||
* Base class for the UI controller.
|
||||
*
|
||||
* TODO Remove all the {@link MailboxFinder} stuff. It's now done in {@link Welcome}.
|
||||
*/
|
||||
abstract class UIControllerBase implements MailboxListFragment.Callback,
|
||||
MessageListFragment.Callback, MessageViewFragment.Callback {
|
||||
static final boolean DEBUG_FRAGMENTS = false; // DO NOT SUBMIT WITH TRUE
|
||||
|
||||
static final String KEY_LIST_CONTEXT = "UIControllerBase.listContext";
|
||||
|
||||
/** The owner activity */
|
||||
final EmailActivity mActivity;
|
||||
final FragmentManager mFragmentManager;
|
||||
|
@ -201,6 +201,7 @@ abstract class UIControllerBase implements MailboxListFragment.Callback,
|
|||
Log.d(Logging.LOG_TAG, this + " onSaveInstanceState");
|
||||
}
|
||||
mActionBarController.onSaveInstanceState(outState);
|
||||
outState.putParcelable(KEY_LIST_CONTEXT, mListContext);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -211,6 +212,7 @@ abstract class UIControllerBase implements MailboxListFragment.Callback,
|
|||
Log.d(Logging.LOG_TAG, this + " restoreInstanceState");
|
||||
}
|
||||
mActionBarController.onRestoreInstanceState(savedInstanceState);
|
||||
mListContext = savedInstanceState.getParcelable(KEY_LIST_CONTEXT);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -0,0 +1,54 @@
|
|||
/*
|
||||
* Copyright (C) 2011 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.android.email;
|
||||
|
||||
import android.os.Parcel;
|
||||
import android.test.AndroidTestCase;
|
||||
|
||||
import com.android.emailcommon.service.SearchParams;
|
||||
|
||||
public class MessageListContextTests extends AndroidTestCase {
|
||||
|
||||
public void testParcellingMailboxes() {
|
||||
long accountId = 123;
|
||||
long mailboxId = 456;
|
||||
MessageListContext original = MessageListContext.forMailbox(accountId, mailboxId);
|
||||
Parcel parcel = Parcel.obtain();
|
||||
|
||||
original.writeToParcel(parcel, 0);
|
||||
parcel.setDataPosition(0);
|
||||
|
||||
MessageListContext read = MessageListContext.CREATOR.createFromParcel(parcel);
|
||||
assertEquals(original, read);
|
||||
parcel.recycle();
|
||||
}
|
||||
|
||||
public void testParcellingSearches() {
|
||||
long accountId = 123;
|
||||
long mailboxId = 456;
|
||||
SearchParams params = new SearchParams(mailboxId, "search terms");
|
||||
MessageListContext original = MessageListContext.forSearch(accountId, mailboxId, params);
|
||||
Parcel parcel = Parcel.obtain();
|
||||
|
||||
original.writeToParcel(parcel, 0);
|
||||
parcel.setDataPosition(0);
|
||||
|
||||
MessageListContext read = MessageListContext.CREATOR.createFromParcel(parcel);
|
||||
assertEquals(original, read);
|
||||
parcel.recycle();
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue