diff --git a/res/values/strings.xml b/res/values/strings.xml index 9bc0c5943..0e05b1f4e 100644 --- a/res/values/strings.xml +++ b/res/values/strings.xml @@ -822,4 +822,7 @@ Gmail + + + Folder sync settings diff --git a/res/xml/account_settings_preferences.xml b/res/xml/account_settings_preferences.xml index ac443d405..0eba071ca 100755 --- a/res/xml/account_settings_preferences.xml +++ b/res/xml/account_settings_preferences.xml @@ -53,23 +53,23 @@ android:entryValues="@array/account_settings_check_frequency_values" android:dialogTitle="@string/account_settings_mail_check_frequency_label" /> - + @@ -77,7 +77,7 @@ diff --git a/src/com/android/email/activity/setup/AccountSettingsFragment.java b/src/com/android/email/activity/setup/AccountSettingsFragment.java index 61f59aae2..4a9067e78 100644 --- a/src/com/android/email/activity/setup/AccountSettingsFragment.java +++ b/src/com/android/email/activity/setup/AccountSettingsFragment.java @@ -37,9 +37,11 @@ import android.preference.Preference; import android.preference.PreferenceActivity; import android.preference.PreferenceCategory; import android.preference.Preference.OnPreferenceClickListener; +import android.preference.PreferenceScreen; import android.provider.CalendarContract; import android.provider.ContactsContract; import android.provider.Settings; +import android.support.annotation.NonNull; import android.text.TextUtils; import android.view.Menu; import android.view.MenuInflater; @@ -89,6 +91,7 @@ public class AccountSettingsFragment extends MailAccountPrefsFragment private static final String PREFERENCE_QUICK_RESPONSES = "account_quick_responses"; private static final String PREFERENCE_FREQUENCY = "account_check_frequency"; private static final String PREFERENCE_SYNC_WINDOW = "account_sync_window"; + private static final String PREFERENCE_SYNC_SETTINGS = "account_sync_settings"; private static final String PREFERENCE_SYNC_EMAIL = "account_sync_email"; private static final String PREFERENCE_SYNC_CONTACTS = "account_sync_contacts"; private static final String PREFERENCE_SYNC_CALENDAR = "account_sync_calendar"; @@ -121,6 +124,7 @@ public class AccountSettingsFragment extends MailAccountPrefsFragment private EditTextPreference mAccountSignature; private ListPreference mCheckFrequency; private ListPreference mSyncWindow; + private Preference mSyncSettings; private CheckBoxPreference mInboxVibrate; private Preference mInboxRingtone; @@ -211,7 +215,7 @@ public class AccountSettingsFragment extends MailAccountPrefsFragment } @Override - public void onSaveInstanceState(Bundle outstate) { + public void onSaveInstanceState(@NonNull Bundle outstate) { super.onSaveInstanceState(outstate); if (mCheckFrequency != null) { outstate.putCharSequenceArray(SAVESTATE_SYNC_INTERVAL_STRINGS, @@ -269,6 +273,18 @@ public class AccountSettingsFragment extends MailAccountPrefsFragment mInboxRingtone.setSummary(summary); } + @Override + public boolean onPreferenceTreeClick(PreferenceScreen preferenceScreen, + @NonNull Preference preference) { + final String key = preference.getKey(); + if (key.equals(PREFERENCE_SYNC_SETTINGS)) { + startActivity(MailboxSettings.getIntent(getActivity(), mUiAccount.allFolderListUri)); + return true; + } else { + return super.onPreferenceTreeClick(preferenceScreen, preference); + } + } + /** * Listen to all preference changes in this class. * @param preference The changed Preference @@ -417,7 +433,7 @@ public class AccountSettingsFragment extends MailAccountPrefsFragment @Override public Map loadInBackground() { - final Map map = new HashMap(); + final Map map = new HashMap<>(); final Account account; if (!TextUtils.isEmpty(mAccountEmail)) { @@ -571,7 +587,7 @@ public class AccountSettingsFragment extends MailAccountPrefsFragment @SuppressWarnings("unused") // temporarily unused pending policy UI private ArrayList getSystemPoliciesList(Policy policy) { Resources res = mContext.getResources(); - ArrayList policies = new ArrayList(); + ArrayList policies = new ArrayList<>(); if (policy.mPasswordMode != Policy.PASSWORD_MODE_NONE) { policies.add(res.getString(R.string.policy_require_password)); } @@ -718,6 +734,15 @@ public class AccountSettingsFragment extends MailAccountPrefsFragment // Must correspond to the hole in the XML file that's reserved. mSyncWindow.setOrder(2); mSyncWindow.setOnPreferenceChangeListener(this); + + if (mSyncSettings == null) { + mSyncSettings = new Preference(mContext); + mSyncSettings.setKey(PREFERENCE_SYNC_SETTINGS); + dataUsageCategory.addPreference(mSyncSettings); + } + + mSyncSettings.setTitle(R.string.folder_sync_settings_pref_title); + mSyncSettings.setOrder(3); } final PreferenceCategory folderPrefs = diff --git a/src/com/android/email/activity/setup/EmailPreferenceActivity.java b/src/com/android/email/activity/setup/EmailPreferenceActivity.java index be02bf6bd..4a5dc4ed9 100644 --- a/src/com/android/email/activity/setup/EmailPreferenceActivity.java +++ b/src/com/android/email/activity/setup/EmailPreferenceActivity.java @@ -21,13 +21,13 @@ import android.app.Fragment; import android.content.Intent; import android.net.Uri; import android.os.Bundle; +import android.support.annotation.NonNull; import android.view.KeyEvent; import android.view.Menu; import android.view.MenuItem; import com.android.email.R; import com.android.emailcommon.utility.IntentUtilities; -import com.android.mail.providers.Folder; import com.android.mail.providers.UIProvider.EditSettingsExtras; import com.android.mail.ui.settings.MailPreferenceActivity; import com.android.mail.utils.Utils; @@ -110,8 +110,7 @@ public class EmailPreferenceActivity extends MailPreferenceActivity { // main screen. // android.accounts.Account acct = i.getParcelableExtra("account"); } else if (i.hasExtra(EditSettingsExtras.EXTRA_FOLDER)) { - launchMailboxSettings(i); - return; + throw new IllegalArgumentException("EXTRA_FOLDER is no longer supported"); } else { // Otherwise, we're called from within the Email app and look for our extras final long accountId = IntentUtilities.getAccountIdFromIntent(i); @@ -124,8 +123,11 @@ public class EmailPreferenceActivity extends MailPreferenceActivity { } mShowDebugMenu = i.getBooleanExtra(EXTRA_ENABLE_DEBUG, false); - getActionBar().setDisplayOptions( - ActionBar.DISPLAY_HOME_AS_UP, ActionBar.DISPLAY_HOME_AS_UP); + final ActionBar actionBar = getActionBar(); + if (actionBar != null) { + actionBar.setDisplayOptions( + ActionBar.DISPLAY_HOME_AS_UP, ActionBar.DISPLAY_HOME_AS_UP); + } mFeedbackUri = Utils.getValidUri(getString(R.string.email_feedback_uri)); } @@ -134,7 +136,7 @@ public class EmailPreferenceActivity extends MailPreferenceActivity { * Listen for secret sequence and, if heard, enable debug menu */ @Override - public boolean onKeyDown(int keyCode, KeyEvent event) { + public boolean onKeyDown(int keyCode, @NonNull KeyEvent event) { if (event.getKeyCode() == SECRET_KEY_CODES[mSecretKeyCodeIndex]) { mSecretKeyCodeIndex++; if (mSecretKeyCodeIndex == SECRET_KEY_CODES.length) { @@ -193,20 +195,6 @@ public class EmailPreferenceActivity extends MailPreferenceActivity { return true; } - private void launchMailboxSettings(Intent intent) { - final Folder folder = intent.getParcelableExtra(EditSettingsExtras.EXTRA_FOLDER); - - // TODO: determine from the account if we should navigate to the mailbox settings. - // See bug 6242668 - - // Get the mailbox id from the folder - final long mailboxId = - Long.parseLong(folder.folderUri.fullUri.getPathSegments().get(1)); - - MailboxSettings.start(this, mailboxId); - finish(); - } - private void enableDebugMenu() { mShowDebugMenu = true; invalidateHeaders(); @@ -245,7 +233,7 @@ public class EmailPreferenceActivity extends MailPreferenceActivity { * @param position The header's position in the list. */ @Override - public void onHeaderClick(Header header, int position) { + public void onHeaderClick(@NonNull Header header, int position) { // Secret keys: Click 10x to enable debug settings if (position == 0) { mNumGeneralHeaderClicked++; diff --git a/src/com/android/email/activity/setup/MailboxSettings.java b/src/com/android/email/activity/setup/MailboxSettings.java index 3673ae66f..820f98960 100644 --- a/src/com/android/email/activity/setup/MailboxSettings.java +++ b/src/com/android/email/activity/setup/MailboxSettings.java @@ -17,14 +17,15 @@ package com.android.email.activity.setup; import android.app.ActionBar; -import android.app.Activity; import android.app.LoaderManager; import android.content.ContentUris; import android.content.ContentValues; import android.content.Context; +import android.content.CursorLoader; import android.content.Intent; import android.content.Loader; import android.content.res.Resources; +import android.database.Cursor; import android.net.Uri; import android.os.Bundle; import android.preference.CheckBoxPreference; @@ -33,6 +34,7 @@ import android.preference.Preference; import android.preference.Preference.OnPreferenceChangeListener; import android.preference.PreferenceActivity; import android.preference.PreferenceFragment; +import android.support.annotation.NonNull; import android.text.TextUtils; import android.view.MenuItem; @@ -45,12 +47,16 @@ import com.android.emailcommon.provider.Mailbox; import com.android.emailcommon.provider.Policy; import com.android.emailcommon.utility.EmailAsyncTask; import com.android.emailcommon.utility.Utility; +import com.android.mail.providers.Folder; +import com.android.mail.providers.UIProvider; import com.android.mail.ui.MailAsyncTaskLoader; import com.android.mail.utils.LogUtils; import com.google.common.base.Preconditions; +import java.util.ArrayList; import java.util.Arrays; import java.util.HashMap; +import java.util.List; import java.util.Map; /** @@ -64,18 +70,19 @@ import java.util.Map; * #onDestroy()}, unless it's called for configuration changes. */ public class MailboxSettings extends PreferenceActivity { - private static final String EXTRA_MAILBOX_ID = "MAILBOX_ID"; + private static final String EXTRA_FOLDERS_URI = "FOLDERS_URI"; + + private static final int FOLDERS_LOADER_ID = 0; + private Uri mFoldersUri; + private final List mFolders = new ArrayList<>(); /** - * Starts the activity for a mailbox. + * Starts the activity */ - public static void start(Activity parent, long mailboxId) { - Intent i = new Intent(parent, MailboxSettings.class); - i.putExtra(EXTRA_SHOW_FRAGMENT, MailboxSettingsFragment.class.getName()); - final Bundle b = new Bundle(1); - b.putLong(EXTRA_MAILBOX_ID, mailboxId); - i.putExtra(EXTRA_SHOW_FRAGMENT_ARGUMENTS, b); - parent.startActivity(i); + public static Intent getIntent(Context context, Uri foldersUri) { + final Intent i = new Intent(context, MailboxSettings.class); + i.putExtra(EXTRA_FOLDERS_URI, foldersUri); + return i; } @Override @@ -86,11 +93,34 @@ public class MailboxSettings extends PreferenceActivity { if (actionBar != null) { actionBar.setDisplayOptions(ActionBar.DISPLAY_HOME_AS_UP, ActionBar.DISPLAY_HOME_AS_UP); } + + mFoldersUri = getIntent().getParcelableExtra(EXTRA_FOLDERS_URI); + + if (mFoldersUri != null) { + getLoaderManager().initLoader(FOLDERS_LOADER_ID, null, + new MailboxSettingsFolderLoaderCallbacks()); + } } @Override - public boolean onIsMultiPane() { - return false; + public void onBuildHeaders(List
target) { + if (mFolders.isEmpty()) { + final Header dummy = new Header(); + dummy.titleRes = R.string.mailbox_name_display_inbox; + target.add(dummy); + } else { + for (final Folder f : mFolders) { + final Header h = new Header(); + if (!TextUtils.isEmpty(f.hierarchicalDesc)) { + h.title = f.hierarchicalDesc; + } else { + h.title = f.name; + } + h.fragment = MailboxSettingsFragment.class.getName(); + h.fragmentArguments = MailboxSettingsFragment.getArguments(f.id); + target.add(h); + } + } } @Override @@ -145,7 +175,42 @@ public class MailboxSettings extends PreferenceActivity { pref.setSummary(pref.getEntry()); } + private class MailboxSettingsFolderLoaderCallbacks + implements LoaderManager.LoaderCallbacks { + + @Override + public Loader onCreateLoader(int i, Bundle bundle) { + return new CursorLoader(MailboxSettings.this, mFoldersUri, + UIProvider.FOLDERS_PROJECTION, null, null, null); + } + + @Override + public void onLoadFinished(Loader cursorLoader, Cursor cursor) { + if (cursor == null) { + return; + } + mFolders.clear(); + + while(cursor.moveToNext()) { + final Folder folder = new Folder(cursor); + if (!folder.supportsCapability(UIProvider.FolderCapabilities.IS_VIRTUAL) && + !folder.isTrash() && !folder.isDraft() && !folder.isOutbox()) { + mFolders.add(folder); + } + } + + invalidateHeaders(); + } + + @Override + public void onLoaderReset(Loader cursorLoader) { + mFolders.clear(); + } + } + public static class MailboxSettingsFragment extends PreferenceFragment { + private static final String EXTRA_MAILBOX_ID = "MailboxId"; + private static final String BUNDLE_MAILBOX = "MailboxSettings.mailbox"; private static final String BUNDLE_MAX_LOOKBACK = "MailboxSettings.maxLookback"; private static final String BUNDLE_SYNC_ENABLED_VALUE = "MailboxSettings.syncEnabled"; @@ -161,6 +226,12 @@ public class MailboxSettings extends PreferenceActivity { private CheckBoxPreference mSyncEnabledPref; private ListPreference mSyncLookbackPref; + private static Bundle getArguments(long mailboxId) { + final Bundle b = new Bundle(1); + b.putLong(EXTRA_MAILBOX_ID, mailboxId); + return b; + } + public MailboxSettingsFragment() {} @Override @@ -198,7 +269,7 @@ public class MailboxSettings extends PreferenceActivity { } @Override - public void onSaveInstanceState(Bundle outState) { + public void onSaveInstanceState(@NonNull Bundle outState) { super.onSaveInstanceState(outState); outState.putParcelable(BUNDLE_MAILBOX, mMailbox); outState.putInt(BUNDLE_MAX_LOOKBACK, mMaxLookback); @@ -240,7 +311,7 @@ public class MailboxSettings extends PreferenceActivity { @Override public Map loadInBackground() { - final Map result = new HashMap(); + final Map result = new HashMap<>(); final Mailbox mailbox = Mailbox.restoreMailboxWithId(getContext(), mMailboxId); result.put(RESULT_KEY_MAILBOX, mailbox);