From ac4b0efd9fa89f68b1a8b9794bf5c958666f7eb8 Mon Sep 17 00:00:00 2001 From: Tony Mantler Date: Fri, 15 Aug 2014 16:24:38 -0700 Subject: [PATCH] Fix folder sync settings for tablet b/17068128 Change-Id: Ia61cba10fb0edc97448d9ff39aa58578db1d4ac7 --- .../setup/AccountSettingsFragment.java | 12 ++++--- .../email/activity/setup/MailboxSettings.java | 34 +++++++++++++------ 2 files changed, 30 insertions(+), 16 deletions(-) diff --git a/src/com/android/email/activity/setup/AccountSettingsFragment.java b/src/com/android/email/activity/setup/AccountSettingsFragment.java index 4a9067e78..f6ea75614 100644 --- a/src/com/android/email/activity/setup/AccountSettingsFragment.java +++ b/src/com/android/email/activity/setup/AccountSettingsFragment.java @@ -133,6 +133,7 @@ public class AccountSettingsFragment extends MailAccountPrefsFragment private Account mAccount; private com.android.mail.providers.Account mUiAccount; private EmailServiceInfo mServiceInfo; + private Folder mInboxFolder; private Ringtone mRingtone; @@ -278,7 +279,8 @@ public class AccountSettingsFragment extends MailAccountPrefsFragment @NonNull Preference preference) { final String key = preference.getKey(); if (key.equals(PREFERENCE_SYNC_SETTINGS)) { - startActivity(MailboxSettings.getIntent(getActivity(), mUiAccount.allFolderListUri)); + startActivity(MailboxSettings.getIntent(getActivity(), mUiAccount.fullFolderListUri, + mInboxFolder)); return true; } else { return super.onPreferenceTreeClick(preferenceScreen, preference); @@ -550,7 +552,7 @@ public class AccountSettingsFragment extends MailAccountPrefsFragment return; } - final Folder inbox = (Folder) data.get(AccountLoader.RESULT_KEY_INBOX); + mInboxFolder = (Folder) data.get(AccountLoader.RESULT_KEY_INBOX); if (mUiAccount == null || mAccount == null) { activity.finish(); @@ -560,11 +562,11 @@ public class AccountSettingsFragment extends MailAccountPrefsFragment mServiceInfo = EmailServiceUtils.getServiceInfo(mContext, mAccount.getProtocol(mContext)); - if (inbox == null) { + if (mInboxFolder == null) { mInboxFolderPreferences = null; } else { - mInboxFolderPreferences = - new FolderPreferences(mContext, mUiAccount.getEmailAddress(), inbox, true); + mInboxFolderPreferences = new FolderPreferences(mContext, + mUiAccount.getEmailAddress(), mInboxFolder, true); } loadSettings(); } diff --git a/src/com/android/email/activity/setup/MailboxSettings.java b/src/com/android/email/activity/setup/MailboxSettings.java index 820f98960..33eb6a93b 100644 --- a/src/com/android/email/activity/setup/MailboxSettings.java +++ b/src/com/android/email/activity/setup/MailboxSettings.java @@ -71,35 +71,41 @@ import java.util.Map; */ public class MailboxSettings extends PreferenceActivity { private static final String EXTRA_FOLDERS_URI = "FOLDERS_URI"; + private static final String EXTRA_INBOX_ID = "INBOX_ID"; private static final int FOLDERS_LOADER_ID = 0; private Uri mFoldersUri; + private int mInboxId; private final List mFolders = new ArrayList<>(); /** * Starts the activity */ - public static Intent getIntent(Context context, Uri foldersUri) { + public static Intent getIntent(Context context, Uri foldersUri, Folder inbox) { final Intent i = new Intent(context, MailboxSettings.class); i.putExtra(EXTRA_FOLDERS_URI, foldersUri); + i.putExtra(EXTRA_INBOX_ID, inbox.id); return i; } @Override protected void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - // Always show "app up" as we expect our parent to be an Email activity. - ActionBar actionBar = getActionBar(); - if (actionBar != null) { - actionBar.setDisplayOptions(ActionBar.DISPLAY_HOME_AS_UP, ActionBar.DISPLAY_HOME_AS_UP); - } - + // This needs to happen before super.onCreate() since that calls onBuildHeaders() + mInboxId = getIntent().getIntExtra(EXTRA_INBOX_ID, -1); mFoldersUri = getIntent().getParcelableExtra(EXTRA_FOLDERS_URI); if (mFoldersUri != null) { getLoaderManager().initLoader(FOLDERS_LOADER_ID, null, new MailboxSettingsFolderLoaderCallbacks()); } + + super.onCreate(savedInstanceState); + + // Always show "app up" as we expect our parent to be an Email activity. + ActionBar actionBar = getActionBar(); + if (actionBar != null) { + actionBar.setDisplayOptions(ActionBar.DISPLAY_HOME_AS_UP, ActionBar.DISPLAY_HOME_AS_UP); + } } @Override @@ -107,6 +113,8 @@ public class MailboxSettings extends PreferenceActivity { if (mFolders.isEmpty()) { final Header dummy = new Header(); dummy.titleRes = R.string.mailbox_name_display_inbox; + dummy.fragment = MailboxSettingsFragment.class.getName(); + dummy.fragmentArguments = MailboxSettingsFragment.getArguments(mInboxId); target.add(dummy); } else { for (final Folder f : mFolders) { @@ -118,15 +126,19 @@ public class MailboxSettings extends PreferenceActivity { } h.fragment = MailboxSettingsFragment.class.getName(); h.fragmentArguments = MailboxSettingsFragment.getArguments(f.id); - target.add(h); + if (f.id == mInboxId) { + target.add(0, h); + } else { + target.add(h); + } } } } @Override protected boolean isValidFragment(String fragmentName) { - return TextUtils.equals(MailboxSettingsFragment.class.getName(), fragmentName) - || super.isValidFragment(fragmentName); + // Activity is not exported + return true; } @Override