From 94506fdaf651363adaf60650d9a2301fdb76724d Mon Sep 17 00:00:00 2001 From: Makoto Onuki Date: Wed, 4 Aug 2010 11:33:52 -0700 Subject: [PATCH] Small fixes/clean-ups. - Fixed account selector default account look-up - Renamed MessageListFragment.onRestoreInstanceState to loadState. (Activity.onRestoreInstanceState is called after onStart, but this one is called in onCreate, so it wasn't a good idea to use the same name.) - Changed mailbox cursur requery timeout to 3 seconds - Added some TODOs. Change-Id: Ia2242cd9f74936d24756b800eacd126958eed330 --- src/com/android/email/activity/AccountSelectorAdapter.java | 2 ++ src/com/android/email/activity/MailboxListFragment.java | 3 ++- src/com/android/email/activity/MailboxesAdapter.java | 7 ++++++- src/com/android/email/activity/MessageListFragment.java | 4 ++-- src/com/android/email/activity/MessageListXL.java | 3 +-- .../com/android/email/activity/MessageListUnitTests.java | 2 +- 6 files changed, 14 insertions(+), 7 deletions(-) diff --git a/src/com/android/email/activity/AccountSelectorAdapter.java b/src/com/android/email/activity/AccountSelectorAdapter.java index 1e3910839..4c96e8946 100644 --- a/src/com/android/email/activity/AccountSelectorAdapter.java +++ b/src/com/android/email/activity/AccountSelectorAdapter.java @@ -34,6 +34,8 @@ import android.widget.TextView; * TODO Use layout? Or use the standard resources that ActionBarDemo uses? * TODO Revisit the sort order when we get more detailed UI spec. (current sort order makes things * simpler for now.) Maybe we can just use SimpleCursorAdapter. + * + * TODO We actually don't need the auto-requery. Just refresh it when we modify accounts. */ public class AccountSelectorAdapter extends CursorAdapter { private static final int AUTO_REQUERY_TIMEOUT = 5 * 1000; // in ms diff --git a/src/com/android/email/activity/MailboxListFragment.java b/src/com/android/email/activity/MailboxListFragment.java index 8c1a0ffec..ece0396eb 100644 --- a/src/com/android/email/activity/MailboxListFragment.java +++ b/src/com/android/email/activity/MailboxListFragment.java @@ -25,7 +25,6 @@ import android.app.LoaderManager.LoaderCallbacks; import android.content.Loader; import android.database.Cursor; import android.os.Bundle; -import android.os.Parcelable; import android.util.Log; import android.view.View; import android.widget.AdapterView; @@ -41,6 +40,8 @@ import java.security.InvalidParameterException; * - call bindActivityInfo() to provide the account ID and set callbacks * - provide callbacks for onOpen and onRefresh * - pass-through implementations of onCreateContextMenu() and onContextItemSelected() (temporary) + * + * TODO Restoring ListView state -- don't do this when changing accounts */ public class MailboxListFragment extends ListFragment implements OnItemClickListener { private static final int LOADER_ID_MAILBOX_LIST = 1; diff --git a/src/com/android/email/activity/MailboxesAdapter.java b/src/com/android/email/activity/MailboxesAdapter.java index c5b0cb52b..24c455956 100644 --- a/src/com/android/email/activity/MailboxesAdapter.java +++ b/src/com/android/email/activity/MailboxesAdapter.java @@ -16,6 +16,7 @@ package com.android.email.activity; +import com.android.email.Email; import com.android.email.R; import com.android.email.Utility; import com.android.email.data.ThrottlingCursorLoader; @@ -31,6 +32,7 @@ import android.database.MatrixCursor; import android.database.MatrixCursor.RowBuilder; import android.database.MergeCursor; import android.graphics.Typeface; +import android.util.Log; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; @@ -48,7 +50,7 @@ import android.widget.TextView; * TODO Unit test, when UI is settled. */ /* package */ class MailboxesAdapter extends CursorAdapter { - private static final int AUTO_REQUERY_TIMEOUT = 5000; // in ms + private static final int AUTO_REQUERY_TIMEOUT = 3 * 1000; // in ms private static final String[] PROJECTION = new String[] { MailboxColumns.ID, MailboxColumns.DISPLAY_NAME, MailboxColumns.TYPE, MailboxColumns.UNREAD_COUNT, @@ -131,6 +133,9 @@ import android.widget.TextView; * @return mailboxes Loader for an account. */ public static Loader createLoader(Context context, long accountId) { + if (Email.DEBUG_LIFECYCLE && Email.DEBUG) { + Log.d(Email.LOG_TAG, "MailboxesAdapter createLoader accountId=" + accountId); + } return new MailboxesLoader(context, accountId); } diff --git a/src/com/android/email/activity/MessageListFragment.java b/src/com/android/email/activity/MessageListFragment.java index 21d4cccd7..1a2946a15 100644 --- a/src/com/android/email/activity/MessageListFragment.java +++ b/src/com/android/email/activity/MessageListFragment.java @@ -167,7 +167,7 @@ public class MessageListFragment extends ListFragment implements OnItemClickList if (savedInstanceState != null) { // Fragment doesn't have this method. Call it manually. - onRestoreInstanceState(savedInstanceState); + loadState(savedInstanceState); } } @@ -238,7 +238,7 @@ public class MessageListFragment extends ListFragment implements OnItemClickList } // Unit tests use it - /* package */ void onRestoreInstanceState(Bundle savedInstanceState) { + /* package */ void loadState(Bundle savedInstanceState) { mSavedItemTop = savedInstanceState.getInt(STATE_SELECTED_ITEM_TOP, 0); mSavedItemPosition = savedInstanceState.getInt(STATE_SELECTED_POSITION, -1); Set checkedset = mListAdapter.getSelectedSet(); diff --git a/src/com/android/email/activity/MessageListXL.java b/src/com/android/email/activity/MessageListXL.java index 8d23b1693..f753895ea 100644 --- a/src/com/android/email/activity/MessageListXL.java +++ b/src/com/android/email/activity/MessageListXL.java @@ -375,8 +375,7 @@ MessageListXLFragmentManager.TargetActivity { // Find the currently selected account, and select it. int defaultSelection = 0; if (mFragmentManager.isAccountSelected()) { - // Need to change the selection - accountsCursor.moveToFirst(); + accountsCursor.moveToPosition(-1); int i = 0; while (accountsCursor.moveToNext()) { final long accountId = AccountSelectorAdapter.getAccountId(accountsCursor); diff --git a/tests/src/com/android/email/activity/MessageListUnitTests.java b/tests/src/com/android/email/activity/MessageListUnitTests.java index 5862bd6a0..98300bba2 100644 --- a/tests/src/com/android/email/activity/MessageListUnitTests.java +++ b/tests/src/com/android/email/activity/MessageListUnitTests.java @@ -152,7 +152,7 @@ public class MessageListUnitTests Set checkedset = ((MessagesAdapter)mListAdapter).getSelectedSet(); assertEquals(0, checkedset.size()); bundle.putLongArray(STATE_CHECKED_ITEMS, checkedarray); - mMessageList.getListFragmentForTest().onRestoreInstanceState(bundle); + mMessageList.getListFragmentForTest().loadState(bundle); checkedset = ((MessagesAdapter)mListAdapter).getSelectedSet(); assertEquals(3, checkedset.size()); assertTrue(checkedset.contains(1L));