From 1ddc2ca4a7e59189099d273bd1d364838dd7ce35 Mon Sep 17 00:00:00 2001 From: Makoto Onuki Date: Sat, 2 Jul 2011 14:48:43 -0700 Subject: [PATCH] Per-mailbox settings - Use PreferenceActivity, in the old style, meaning without PreferenceFragment. - If setting Inbox, change the account settings instead of mailbox settings. - Use the DialogWhenLarge theme, meaning it's a full-screen avitity on the phone and a dialog on the tablet. - Also fixed the bug that we the menu items that are made invisible by UIControllerBase may be made re-visible by the 1-pane controller. TODO The menu item shouldn't be shown for non-syncable mailboxes. Change-Id: I02b2faf6f593e1e2eb370217c27801aa58ca7e6c --- AndroidManifest.xml | 7 + res/menu-sw600dp/email_activity_options.xml | 10 +- res/menu/email_activity_options.xml | 10 +- res/values/arrays.xml | 26 ++ res/values/strings.xml | 15 + res/xml/mailbox_preferences.xml | 43 +++ .../android/email/activity/EmailActivity.java | 113 ------ .../email/activity/UIControllerBase.java | 20 +- .../email/activity/UIControllerOnePane.java | 19 +- .../email/activity/UIControllerTwoPane.java | 10 +- .../email/activity/setup/MailboxSettings.java | 321 ++++++++++++++++++ 11 files changed, 437 insertions(+), 157 deletions(-) create mode 100644 res/xml/mailbox_preferences.xml create mode 100644 src/com/android/email/activity/setup/MailboxSettings.java diff --git a/AndroidManifest.xml b/AndroidManifest.xml index 6a1cbc227..aeae0cce1 100644 --- a/AndroidManifest.xml +++ b/AndroidManifest.xml @@ -262,6 +262,13 @@ + + + diff --git a/res/menu-sw600dp/email_activity_options.xml b/res/menu-sw600dp/email_activity_options.xml index 798649670..5d0627f4e 100644 --- a/res/menu-sw600dp/email_activity_options.xml +++ b/res/menu-sw600dp/email_activity_options.xml @@ -58,15 +58,9 @@ android:icon="@android:drawable/ic_menu_preferences" /> - diff --git a/res/menu/email_activity_options.xml b/res/menu/email_activity_options.xml index ac07e93f2..27240fe86 100644 --- a/res/menu/email_activity_options.xml +++ b/res/menu/email_activity_options.xml @@ -63,15 +63,9 @@ android:icon="@android:drawable/ic_menu_preferences" /> - diff --git a/res/values/arrays.xml b/res/values/arrays.xml index 7c11753ca..c3758495c 100644 --- a/res/values/arrays.xml +++ b/res/values/arrays.xml @@ -83,6 +83,32 @@ 6 + + + @string/account_setup_options_mail_window_default + @string/account_setup_options_mail_window_auto + @string/account_setup_options_mail_window_1day + @string/account_setup_options_mail_window_3days + @string/account_setup_options_mail_window_1week + @string/account_setup_options_mail_window_2weeks + @string/account_setup_options_mail_window_1month + @string/account_setup_options_mail_window_all + + + + + 0 + -2 + 1 + 2 + 3 + 4 + 5 + 6 + + diff --git a/res/values/strings.xml b/res/values/strings.xml index 33be17fcb..d6cfd8d05 100644 --- a/res/values/strings.xml +++ b/res/values/strings.xml @@ -128,6 +128,8 @@ Search Account settings + + Folder settings Mark as unread @@ -775,6 +777,8 @@ save attachment. One month All + + Use account\'s default Username or password incorrect. @@ -1014,6 +1018,17 @@ save attachment. Remove account + + Folder settings + + Folder settings (%s) + + Sync settings + + Check frequency + + Amount to synchronize + Email account diff --git a/res/xml/mailbox_preferences.xml b/res/xml/mailbox_preferences.xml new file mode 100644 index 000000000..370ee559a --- /dev/null +++ b/res/xml/mailbox_preferences.xml @@ -0,0 +1,43 @@ + + + + + + + + + + + + + + + diff --git a/src/com/android/email/activity/EmailActivity.java b/src/com/android/email/activity/EmailActivity.java index d8153c181..7994bbbab 100644 --- a/src/com/android/email/activity/EmailActivity.java +++ b/src/com/android/email/activity/EmailActivity.java @@ -17,12 +17,7 @@ package com.android.email.activity; import android.app.Activity; -import android.app.AlertDialog; -import android.app.Dialog; import android.app.Fragment; -import android.content.ContentUris; -import android.content.ContentValues; -import android.content.DialogInterface; import android.content.Intent; import android.os.Bundle; import android.os.Handler; @@ -42,7 +37,6 @@ import com.android.email.R; import com.android.emailcommon.Logging; import com.android.emailcommon.mail.MessagingException; import com.android.emailcommon.provider.Account; -import com.android.emailcommon.provider.EmailContent.MailboxColumns; import com.android.emailcommon.provider.EmailContent.Message; import com.android.emailcommon.provider.Mailbox; import com.android.emailcommon.utility.EmailAsyncTask; @@ -83,9 +77,6 @@ public class EmailActivity extends Activity implements View.OnClickListener, Fra /** Id of the account that had a messaging exception most recently. */ private long mLastErrorAccountId; - // STOPSHIP Temporary mailbox settings UI - private int mDialogSelection = -1; - /** * Create an intent to launch and open account's inbox. * @@ -333,119 +324,15 @@ public class EmailActivity extends Activity implements View.OnClickListener, Fra return true; // Event handled. } - // STOPSHIP Set column from user options - private void setMailboxColumn(long mailboxId, String column, String value) { - if (mailboxId > 0) { - ContentValues cv = new ContentValues(); - cv.put(column, value); - getContentResolver().update( - ContentUris.withAppendedId(Mailbox.CONTENT_URI, mailboxId), - cv, null, null); - mUIController.onRefresh(); - } - } - // STOPSHIP Temporary mailbox settings UI. If this ends up being useful, it should - // be moved to Utility (emailcommon) - private int findInStringArray(String[] array, String item) { - int i = 0; - for (String str: array) { - if (str.equals(item)) { - return i; - } - i++; - } - return -1; - } - - // STOPSHIP Temporary mailbox settings UI - private final DialogInterface.OnClickListener mSelectionListener = - new DialogInterface.OnClickListener() { - public void onClick(DialogInterface dialog, int which) { - mDialogSelection = which; - } - }; - - // STOPSHIP Temporary mailbox settings UI - private final DialogInterface.OnClickListener mCancelListener = - new DialogInterface.OnClickListener() { - public void onClick(DialogInterface dialog, int which) { - } - }; - - // STOPSHIP Temporary mailbox settings UI - @Override - @Deprecated - protected Dialog onCreateDialog(int id, Bundle args) { - final long mailboxId = mUIController.getMailboxSettingsMailboxId(); - if (mailboxId < 0) { - return null; - } - final Mailbox mailbox = Mailbox.restoreMailboxWithId(this, mailboxId); - if (mailbox == null) return null; - switch (id) { - case MAILBOX_SYNC_FREQUENCY_DIALOG: - String freq = Integer.toString(mailbox.mSyncInterval); - final String[] freqValues = getResources().getStringArray( - R.array.account_settings_check_frequency_values_push); - int selection = findInStringArray(freqValues, freq); - // If not found, this is a push mailbox; trust me on this - if (selection == -1) selection = 0; - return new AlertDialog.Builder(this) - .setIconAttribute(android.R.attr.dialogIcon) - .setTitle(R.string.mailbox_options_check_frequency_label) - .setSingleChoiceItems(R.array.account_settings_check_frequency_entries_push, - selection, - mSelectionListener) - .setPositiveButton(R.string.okay_action, new DialogInterface.OnClickListener() { - public void onClick(DialogInterface dialog, int which) { - setMailboxColumn(mailboxId, MailboxColumns.SYNC_INTERVAL, - freqValues[mDialogSelection]); - }}) - .setNegativeButton(R.string.cancel_action, mCancelListener) - .create(); - - case MAILBOX_SYNC_LOOKBACK_DIALOG: - freq = Integer.toString(mailbox.mSyncLookback); - final String[] windowValues = getResources().getStringArray( - R.array.account_settings_mail_window_values); - selection = findInStringArray(windowValues, freq); - return new AlertDialog.Builder(this) - .setIconAttribute(android.R.attr.dialogIcon) - .setTitle(R.string.mailbox_options_lookback_label) - .setSingleChoiceItems(R.array.account_settings_mail_window_entries, - selection, - mSelectionListener) - .setPositiveButton(R.string.okay_action, new DialogInterface.OnClickListener() { - public void onClick(DialogInterface dialog, int which) { - setMailboxColumn(mailboxId, MailboxColumns.SYNC_LOOKBACK, - windowValues[mDialogSelection]); - }}) - .setNegativeButton(R.string.cancel_action, mCancelListener) - .create(); - } - return null; - } - @Override @SuppressWarnings("deprecation") public boolean onOptionsItemSelected(MenuItem item) { if (mUIController.onOptionsItemSelected(item)) { return true; } - switch (item.getItemId()) { - // STOPSHIP Temporary mailbox settings UI - case R.id.sync_lookback: - showDialog(MAILBOX_SYNC_LOOKBACK_DIALOG); - return true; - // STOPSHIP Temporary mailbox settings UI - case R.id.sync_frequency: - showDialog(MAILBOX_SYNC_FREQUENCY_DIALOG); - return true; - } return super.onOptionsItemSelected(item); } - /** * A {@link Controller.Result} to detect connection status. */ diff --git a/src/com/android/email/activity/UIControllerBase.java b/src/com/android/email/activity/UIControllerBase.java index e7f043903..f781711bd 100644 --- a/src/com/android/email/activity/UIControllerBase.java +++ b/src/com/android/email/activity/UIControllerBase.java @@ -33,6 +33,7 @@ import com.android.email.Preferences; import com.android.email.R; import com.android.email.RefreshManager; import com.android.email.activity.setup.AccountSettings; +import com.android.email.activity.setup.MailboxSettings; import com.android.emailcommon.Logging; import com.android.emailcommon.provider.Account; import com.android.emailcommon.provider.EmailContent.Message; @@ -735,8 +736,9 @@ abstract class UIControllerBase implements MailboxListFragment.Callback, // TODO: Should use an isSyncable call to prevent drafts/outbox from allowing this menu.findItem(R.id.search).setVisible(accountSearchable && isMessageListReady()); - menu.findItem(R.id.sync_lookback).setVisible(isEas); - menu.findItem(R.id.sync_frequency).setVisible(isEas); + // TODO Show only for syncable mailbox as well. + menu.findItem(R.id.mailbox_settings).setVisible(isEas + && (getMailboxSettingsMailboxId() != Mailbox.NO_MAILBOX)); return true; } @@ -762,6 +764,12 @@ abstract class UIControllerBase implements MailboxListFragment.Callback, case R.id.search: onSearchRequested(); return true; + case R.id.mailbox_settings: + final long mailboxId = getMailboxSettingsMailboxId(); + if (mailboxId != Mailbox.NO_MAILBOX) { + MailboxSettings.start(mActivity, mailboxId); + } + return true; } return false; } @@ -797,18 +805,14 @@ abstract class UIControllerBase implements MailboxListFragment.Callback, /** - * STOPSHIP For experimental UI. Remove this. - * * @return mailbox ID for "mailbox settings" option. */ - public abstract long getMailboxSettingsMailboxId(); + protected abstract long getMailboxSettingsMailboxId(); /** - * STOPSHIP For experimental UI. Make it abstract protected. - * * Performs "refesh". */ - public abstract void onRefresh(); + protected abstract void onRefresh(); /** * @return true if refresh is in progress for the current mailbox. diff --git a/src/com/android/email/activity/UIControllerOnePane.java b/src/com/android/email/activity/UIControllerOnePane.java index cb187e06d..2851bd525 100644 --- a/src/com/android/email/activity/UIControllerOnePane.java +++ b/src/com/android/email/activity/UIControllerOnePane.java @@ -562,11 +562,8 @@ class UIControllerOnePane extends UIControllerBase { super.installMessageListFragment(fragment); } - /* - * STOPSHIP Remove this -- see the base class method. - */ @Override - public long getMailboxSettingsMailboxId() { + protected long getMailboxSettingsMailboxId() { return isMessageListInstalled() ? getMessageListFragment().getMailboxId() : Mailbox.NO_MAILBOX; @@ -579,13 +576,13 @@ class UIControllerOnePane extends UIControllerBase { // Then override final boolean messageViewVisible = isMessageViewInstalled(); - menu.findItem(R.id.search).setVisible(!messageViewVisible); - menu.findItem(R.id.compose).setVisible(!messageViewVisible); - menu.findItem(R.id.refresh).setVisible(!messageViewVisible); - menu.findItem(R.id.account_settings).setVisible(!messageViewVisible); - menu.findItem(R.id.sync_frequency).setVisible(!messageViewVisible); - menu.findItem(R.id.sync_lookback).setVisible(!messageViewVisible); if (messageViewVisible) { + menu.findItem(R.id.search).setVisible(false); + menu.findItem(R.id.compose).setVisible(false); + menu.findItem(R.id.refresh).setVisible(false); + menu.findItem(R.id.account_settings).setVisible(false); + menu.findItem(R.id.mailbox_settings).setVisible(false); + final MessageOrderManager om = getMessageOrderManager(); menu.findItem(R.id.newer).setVisible(true); menu.findItem(R.id.older).setVisible(true); @@ -618,7 +615,7 @@ class UIControllerOnePane extends UIControllerBase { } @Override - public void onRefresh() { + protected void onRefresh() { if (!isRefreshEnabled()) { return; } diff --git a/src/com/android/email/activity/UIControllerTwoPane.java b/src/com/android/email/activity/UIControllerTwoPane.java index c309cecad..2c22f3544 100644 --- a/src/com/android/email/activity/UIControllerTwoPane.java +++ b/src/com/android/email/activity/UIControllerTwoPane.java @@ -282,10 +282,6 @@ class UIControllerTwoPane extends UIControllerBase implements ThreePaneLayout.Ca :Account.NO_ACCOUNT; } - - /* - * STOPSHIP Remove this -- see the base class method. - */ @Override public long getMailboxSettingsMailboxId() { return getMessageListMailboxId(); @@ -545,12 +541,8 @@ class UIControllerTwoPane extends UIControllerBase implements ThreePaneLayout.Ca return false; } - /** - * Handles the "refresh" option item. Opens the settings activity. - * TODO used by experimental code in the activity -- otherwise can be private. - */ @Override - public void onRefresh() { + protected void onRefresh() { // Cancel previously running instance if any. new RefreshTask(mTaskTracker, mActivity, getActualAccountId(), getMessageListMailboxId()).cancelPreviousAndExecuteParallel(); diff --git a/src/com/android/email/activity/setup/MailboxSettings.java b/src/com/android/email/activity/setup/MailboxSettings.java new file mode 100644 index 000000000..d94b69d81 --- /dev/null +++ b/src/com/android/email/activity/setup/MailboxSettings.java @@ -0,0 +1,321 @@ +/* + * 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.activity.setup; + +import com.android.email.Email; +import com.android.email.FolderProperties; +import com.android.email.R; +import com.android.email.RefreshManager; +import com.android.emailcommon.Logging; +import com.android.emailcommon.provider.Account; +import com.android.emailcommon.provider.EmailContent.AccountColumns; +import com.android.emailcommon.provider.EmailContent.MailboxColumns; +import com.android.emailcommon.provider.Mailbox; +import com.android.emailcommon.utility.EmailAsyncTask; +import com.google.common.base.Objects; +import com.google.common.base.Preconditions; + +import android.app.Activity; +import android.content.ContentUris; +import android.content.ContentValues; +import android.content.Context; +import android.content.Intent; +import android.net.Uri; +import android.os.Bundle; +import android.preference.ListPreference; +import android.preference.Preference; +import android.preference.Preference.OnPreferenceChangeListener; +import android.preference.PreferenceActivity; +import android.util.Log; + +/** + * "Mailbox settings" activity. + * + * It's used to update per-mailbox sync settings. It normally updates Mailbox settings, unless + * the target mailbox is Inbox, in which case it updates Account settings instead. + * + * All changes made by the user will not be immediately saved to the database, as changing the + * sync window may result in removal of messages. Instead, we only save to the database in {@link + * #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 BUNDLE_ACCOUNT = "MailboxSettings.account"; + private static final String BUNDLE_MAILBOX = "MailboxSettings.mailbox"; + private static final String BUNDLE_NEEDS_SAVE = "MailboxSettings.needsSave"; + + private static final String PREF_CHECK_FREQUENCY_KEY = "check_frequency"; + private static final String PREF_SYNC_WINDOW_KEY = "sync_window"; + + private final EmailAsyncTask.Tracker mTaskTracker = new EmailAsyncTask.Tracker(); + + // Account and Mailbox -- directly loaded by LoadMailboxTask + private Account mAccount; + private Mailbox mMailbox; + private boolean mNeedsSave; + + private ListPreference mSyncIntervalPref; + private ListPreference mSyncLookbackPref; + + /** + * Starts the activity for a mailbox. + */ + public static final void start(Activity parent, long mailboxId) { + Intent i = new Intent(parent, MailboxSettings.class); + i.putExtra(EXTRA_MAILBOX_ID, mailboxId); + parent.startActivity(i); + } + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + + final long mailboxId = getIntent().getLongExtra(EXTRA_MAILBOX_ID, Mailbox.NO_MAILBOX); + if (mailboxId == Mailbox.NO_MAILBOX) { + finish(); + return; + } + + addPreferencesFromResource(R.xml.mailbox_preferences); + + mSyncIntervalPref = (ListPreference) findPreference(PREF_CHECK_FREQUENCY_KEY); + mSyncLookbackPref = (ListPreference) findPreference(PREF_SYNC_WINDOW_KEY); + + mSyncIntervalPref.setOnPreferenceChangeListener(mPreferenceChanged); + mSyncLookbackPref.setOnPreferenceChangeListener(mPreferenceChanged); + + // Make them disabled until we load data + enablePreferences(false); + + if (savedInstanceState != null) { + mAccount = savedInstanceState.getParcelable(BUNDLE_ACCOUNT); + mMailbox = savedInstanceState.getParcelable(BUNDLE_MAILBOX); + mNeedsSave = savedInstanceState.getBoolean(BUNDLE_NEEDS_SAVE); + } + if (mAccount == null) { + new LoadMailboxTask(mailboxId).executeParallel((Void[]) null); + } else { + onDataLoaded(); + } + } + + private void enablePreferences(boolean enabled) { + mSyncIntervalPref.setEnabled(enabled); + mSyncLookbackPref.setEnabled(enabled); + } + + @Override + protected void onSaveInstanceState(Bundle outState) { + super.onSaveInstanceState(outState); + outState.putParcelable(BUNDLE_ACCOUNT, mAccount); + outState.putParcelable(BUNDLE_MAILBOX, mMailbox); + outState.putBoolean(BUNDLE_NEEDS_SAVE, mNeedsSave); + } + + /** + * We save all the settings in onDestroy, *unless it's for configuration changes*. + */ + @Override + protected void onDestroy() { + mTaskTracker.cancellAllInterrupt(); + if (!isChangingConfigurations()) { + saveToDatabase(); + } + super.onDestroy(); + } + + /** + * Loads {@link #mAccount} and {@link #mMailbox}. + */ + private class LoadMailboxTask extends EmailAsyncTask { + private final long mMailboxId; + + public LoadMailboxTask(long mailboxId) { + super(mTaskTracker); + mMailboxId = mailboxId; + } + + @Override + protected Void doInBackground(Void... params) { + final Context c = MailboxSettings.this; + mMailbox = Mailbox.restoreMailboxWithId(c, mMailboxId); + if (mMailbox != null) { + mAccount = Account.restoreAccountWithId(c, mMailbox.mAccountKey); + } + return null; + } + + @Override + protected void onSuccess(Void result) { + if ((mAccount == null) || (mMailbox == null)) { + finish(); // Account or mailbox removed. + return; + } + onDataLoaded(); + } + } + + /** + * Called when {@link #mAccount} and {@link #mMailbox} are loaded (either by the async task + * or from the saved state). + */ + private void onDataLoaded() { + Preconditions.checkNotNull(mAccount); + Preconditions.checkNotNull(mMailbox); + + // Update the title with the mailbox name. + setTitle(getString(R.string.mailbox_settings_activity_title_with_mailbox, + FolderProperties.getInstance(this).getDisplayName(mMailbox))); + + // Special case: If setting inbox, don't show "Use account's default". + if (mMailbox.mType == Mailbox.TYPE_INBOX) { + mSyncLookbackPref.setEntries(R.array.account_settings_mail_window_entries); + mSyncLookbackPref.setEntryValues(R.array.account_settings_mail_window_values); + } + + // Set default value & update summary + mSyncIntervalPref.setValue(String.valueOf(getSyncInterval())); + mSyncLookbackPref.setValue(String.valueOf(getSyncLookback())); + + updatePreferenceSummary(); + + // Make then enabled + enablePreferences(true); + } + + private void updatePreferenceSummary() { + mSyncIntervalPref.setSummary(mSyncIntervalPref.getEntry()); + mSyncLookbackPref.setSummary(mSyncLookbackPref.getEntry()); + } + + /** + * @return current sync interval setting from the objects + */ + private int getSyncInterval() { + if (mMailbox.mType == Mailbox.TYPE_INBOX) { + return mAccount.mSyncInterval; + } else { + if (mMailbox.mSyncInterval == 0) { + // 0 is the default value, and it means "don't sync" (for non-inbox mailboxes) + return Mailbox.CHECK_INTERVAL_NEVER; + } + return mMailbox.mSyncInterval; + } + } + + /** + * @return current sync lookback setting from the objects + */ + private int getSyncLookback() { + if (mMailbox.mType == Mailbox.TYPE_INBOX) { + return mAccount.mSyncLookback; + } else { + // Here, 0 is valid and means "use the account default sync window". + return mMailbox.mSyncLookback; + } + } + + private final OnPreferenceChangeListener mPreferenceChanged = new OnPreferenceChangeListener() { + @Override + public boolean onPreferenceChange(Preference preference, Object newValue) { + final ListPreference lp = (ListPreference) preference; + if (Objects.equal(lp.getValue(), newValue)) { + return false; + } + mNeedsSave = true; + if (Email.DEBUG) { + Log.i(Logging.LOG_TAG, "Setting changed"); + } + // In order to set the current entry to the summary, we need to udpate the value + // manually, rather than letting the framework do that (by returning true). + lp.setValue((String) newValue); + updatePreferenceSummary(); + updateObjects(); + return false; + } + }; + + /** + * Updates {@link #mAccount}/{@link #mMailbox}, but doesn't save to the database yet. + */ + private void updateObjects() { + final int syncInterval = Integer.valueOf(mSyncIntervalPref.getValue()); + final int syncLookback = Integer.valueOf(mSyncLookbackPref.getValue()); + if (Email.DEBUG) { + Log.i(Logging.LOG_TAG, "Updating object: " + syncInterval + "," + syncLookback); + } + if (mMailbox.mType == Mailbox.TYPE_INBOX) { + mAccount.mSyncInterval = syncInterval; + mAccount.mSyncLookback = syncLookback; + } else { + mMailbox.mSyncInterval = syncInterval; + mMailbox.mSyncLookback = syncLookback; + } + } + + /** + * Save changes to the database. + * + * Note it's called from {@link #onDestroy()}, which is called on the UI thread where we're not + * allowed to touch the database, so it uses {@link EmailAsyncTask} to do the save on a bg + * thread. This unfortunately means there's a chance that the app gets killed before the save is + * finished. + */ + private void saveToDatabase() { + if (!mNeedsSave) { + return; + } + Log.i(Logging.LOG_TAG, "Saving mailbox settings..."); + enablePreferences(false); + + // Since the activity will be destroyed... + // Create local references (Although it's really okay to touch members of a destroyed + // activity...) + final Account account = mAccount; + final Mailbox mailbox = mMailbox; + final Context context = this.getApplicationContext(); + + new EmailAsyncTask (null /* no cancel */) { + @Override + protected Void doInBackground(Void... params) { + final ContentValues cv = new ContentValues(); + final Uri uri; + + if (mailbox.mType == Mailbox.TYPE_INBOX) { + cv.put(AccountColumns.SYNC_INTERVAL, account.mSyncInterval); + cv.put(AccountColumns.SYNC_LOOKBACK, account.mSyncLookback); + uri = ContentUris.withAppendedId(Account.CONTENT_URI, account.mId); + } else { + cv.put(MailboxColumns.SYNC_INTERVAL, mailbox.mSyncInterval); + cv.put(MailboxColumns.SYNC_LOOKBACK, mailbox.mSyncLookback); + uri = ContentUris.withAppendedId(Mailbox.CONTENT_URI, mailbox.mId); + } + context.getContentResolver().update(uri, cv, null, null); + + Log.i(Logging.LOG_TAG, "Saved: " + uri); + return null; + } + + @Override + protected void onSuccess(Void result) { + // must be called on the ui thread + RefreshManager.getInstance(context).refreshMessageList(account.mId, mailbox.mId, + true); + } + }.executeSerial((Void [])null); + } +}