Fix mailbox sync options.
- Change mailbox sync interval to be a boolean. - Decouple Inbox settings from account settings. Change-Id: Id02d43b281f323ca4db499ce97e8f4bb6d82c2bb
This commit is contained in:
parent
478417a794
commit
038924037b
@ -1016,8 +1016,11 @@ as <xliff:g id="filename">%s</xliff:g>.</string>
|
|||||||
<string name="mailbox_settings_activity_title_with_mailbox">Sync options (<xliff:g id="mailboxx_name" example="Family">%s</xliff:g>)</string>
|
<string name="mailbox_settings_activity_title_with_mailbox">Sync options (<xliff:g id="mailboxx_name" example="Family">%s</xliff:g>)</string>
|
||||||
<!-- Mailbox "sync settings" preference header [CHAR LIMIT=none] -->
|
<!-- Mailbox "sync settings" preference header [CHAR LIMIT=none] -->
|
||||||
<string name="mailbox_preferences_header">Sync settings</string>
|
<string name="mailbox_preferences_header">Sync settings</string>
|
||||||
<!-- On mailbox settings screen: Mailbox check frequency setting label [CHAR LIMIT=none] -->
|
<!-- TODO: Finalize the next two strings and set them to translate. -->
|
||||||
<string name="mailbox_settings_mailbox_check_frequency_label">Check frequency</string>
|
<!-- On mailbox settings screen: Whether to sync this mailbox when the account syncs. -->
|
||||||
|
<string translatable="false" name="mailbox_settings_sync_enabled_label">Auto sync this folder</string>
|
||||||
|
<!-- On mailbox settings screen: Explanatory text for what it means to "auto sync a folder". -->
|
||||||
|
<string translatable="false" name="mailbox_settings_sync_enabled_summary">Sync this folder when the account syncs</string>
|
||||||
<!-- On mailbox settings screen: Mailbox sync window (the number of days to synchronize email for) setting label [CHAR LIMIT=none] -->
|
<!-- On mailbox settings screen: Mailbox sync window (the number of days to synchronize email for) setting label [CHAR LIMIT=none] -->
|
||||||
<string name="mailbox_settings_mailbox_sync_window_label">Days to sync</string>
|
<string name="mailbox_settings_mailbox_sync_window_label">Days to sync</string>
|
||||||
|
|
||||||
|
@ -16,15 +16,11 @@
|
|||||||
|
|
||||||
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
|
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
|
||||||
|
|
||||||
<!-- summary is set at runtime -->
|
<CheckBoxPreference
|
||||||
<ListPreference
|
android:key="sync_enabled"
|
||||||
android:key="check_frequency"
|
android:defaultValue="false"
|
||||||
android:title="@string/mailbox_settings_mailbox_check_frequency_label"
|
android:title="@string/mailbox_settings_sync_enabled_label"
|
||||||
android:dialogTitle="@string/mailbox_settings_mailbox_check_frequency_label"
|
android:summary="@string/mailbox_settings_sync_enabled_summary" />
|
||||||
android:entries="@array/account_settings_check_frequency_entries_push"
|
|
||||||
android:entryValues="@array/account_settings_check_frequency_values_push"
|
|
||||||
android:persistent="false"
|
|
||||||
/>
|
|
||||||
|
|
||||||
<!-- summary is set at runtime -->
|
<!-- summary is set at runtime -->
|
||||||
<ListPreference
|
<ListPreference
|
||||||
|
@ -653,13 +653,33 @@ public class AccountSettingsFragment extends EmailPreferenceFragment
|
|||||||
PreferenceCategory dataUsageCategory =
|
PreferenceCategory dataUsageCategory =
|
||||||
(PreferenceCategory) findPreference(PREFERENCE_CATEGORY_DATA_USAGE);
|
(PreferenceCategory) findPreference(PREFERENCE_CATEGORY_DATA_USAGE);
|
||||||
|
|
||||||
|
final Policy policy;
|
||||||
|
if (mAccount.mPolicyKey != 0) {
|
||||||
|
// Make sure we have most recent data from account
|
||||||
|
mAccount.refresh(mContext);
|
||||||
|
policy = Policy.restorePolicyWithId(mContext, mAccount.mPolicyKey);
|
||||||
|
if (policy == null) {
|
||||||
|
// The account has been deleted? Crazy, but not impossible
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
policy = null;
|
||||||
|
}
|
||||||
|
|
||||||
mSyncWindow = null;
|
mSyncWindow = null;
|
||||||
if (info.offerLookback) {
|
if (info.offerLookback) {
|
||||||
mSyncWindow = new ListPreference(mContext);
|
mSyncWindow = new ListPreference(mContext);
|
||||||
mSyncWindow.setTitle(R.string.account_setup_options_mail_window_label);
|
mSyncWindow.setTitle(R.string.account_setup_options_mail_window_label);
|
||||||
mSyncWindow.setValue(String.valueOf(mAccount.getSyncLookback()));
|
mSyncWindow.setValue(String.valueOf(mAccount.getSyncLookback()));
|
||||||
mSyncWindow.setSummary(mSyncWindow.getEntry());
|
final int maxLookback;
|
||||||
MailboxSettings.setupLookbackPreferenceOptions(mContext, mSyncWindow, mAccount, false);
|
if (policy != null) {
|
||||||
|
maxLookback = policy.mMaxEmailLookback;
|
||||||
|
} else {
|
||||||
|
maxLookback = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
MailboxSettings.setupLookbackPreferenceOptions(mContext, mSyncWindow, maxLookback,
|
||||||
|
false);
|
||||||
|
|
||||||
// Must correspond to the hole in the XML file that's reserved.
|
// Must correspond to the hole in the XML file that's reserved.
|
||||||
mSyncWindow.setOrder(2);
|
mSyncWindow.setOrder(2);
|
||||||
@ -746,14 +766,7 @@ public class AccountSettingsFragment extends EmailPreferenceFragment
|
|||||||
final Preference retryAccount = findPreference(PREFERENCE_POLICIES_RETRY_ACCOUNT);
|
final Preference retryAccount = findPreference(PREFERENCE_POLICIES_RETRY_ACCOUNT);
|
||||||
final PreferenceCategory policiesCategory = (PreferenceCategory) findPreference(
|
final PreferenceCategory policiesCategory = (PreferenceCategory) findPreference(
|
||||||
PREFERENCE_CATEGORY_POLICIES);
|
PREFERENCE_CATEGORY_POLICIES);
|
||||||
if (mAccount.mPolicyKey > 0) {
|
if (policy != null) {
|
||||||
// Make sure we have most recent data from account
|
|
||||||
mAccount.refresh(mContext);
|
|
||||||
Policy policy = Policy.restorePolicyWithId(mContext, mAccount.mPolicyKey);
|
|
||||||
if (policy == null) {
|
|
||||||
// The account has been deleted? Crazy, but not impossible
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (policy.mProtocolPoliciesEnforced != null) {
|
if (policy.mProtocolPoliciesEnforced != null) {
|
||||||
ArrayList<String> policies = getSystemPoliciesList(policy);
|
ArrayList<String> policies = getSystemPoliciesList(policy);
|
||||||
setPolicyListSummary(policies, policy.mProtocolPoliciesEnforced,
|
setPolicyListSummary(policies, policy.mProtocolPoliciesEnforced,
|
||||||
|
@ -18,6 +18,7 @@ package com.android.email.activity.setup;
|
|||||||
|
|
||||||
import android.app.ActionBar;
|
import android.app.ActionBar;
|
||||||
import android.app.Activity;
|
import android.app.Activity;
|
||||||
|
import android.content.ContentResolver;
|
||||||
import android.content.ContentUris;
|
import android.content.ContentUris;
|
||||||
import android.content.ContentValues;
|
import android.content.ContentValues;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
@ -25,6 +26,7 @@ import android.content.Intent;
|
|||||||
import android.content.res.Resources;
|
import android.content.res.Resources;
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
|
import android.preference.CheckBoxPreference;
|
||||||
import android.preference.ListPreference;
|
import android.preference.ListPreference;
|
||||||
import android.preference.Preference;
|
import android.preference.Preference;
|
||||||
import android.preference.Preference.OnPreferenceChangeListener;
|
import android.preference.Preference.OnPreferenceChangeListener;
|
||||||
@ -32,16 +34,14 @@ import android.preference.PreferenceActivity;
|
|||||||
import android.view.MenuItem;
|
import android.view.MenuItem;
|
||||||
|
|
||||||
import com.android.email.R;
|
import com.android.email.R;
|
||||||
import com.android.email2.ui.MailActivityEmail;
|
|
||||||
import com.android.emailcommon.Logging;
|
import com.android.emailcommon.Logging;
|
||||||
import com.android.emailcommon.provider.Account;
|
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.EmailContent.MailboxColumns;
|
||||||
import com.android.emailcommon.provider.Mailbox;
|
import com.android.emailcommon.provider.Mailbox;
|
||||||
import com.android.emailcommon.provider.Policy;
|
import com.android.emailcommon.provider.Policy;
|
||||||
import com.android.emailcommon.utility.EmailAsyncTask;
|
import com.android.emailcommon.utility.EmailAsyncTask;
|
||||||
|
import com.android.emailcommon.utility.Utility;
|
||||||
import com.android.mail.utils.LogUtils;
|
import com.android.mail.utils.LogUtils;
|
||||||
import com.google.common.base.Objects;
|
|
||||||
import com.google.common.base.Preconditions;
|
import com.google.common.base.Preconditions;
|
||||||
|
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
@ -58,21 +58,29 @@ import java.util.Arrays;
|
|||||||
*/
|
*/
|
||||||
public class MailboxSettings extends PreferenceActivity {
|
public class MailboxSettings extends PreferenceActivity {
|
||||||
private static final String EXTRA_MAILBOX_ID = "MAILBOX_ID";
|
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_MAILBOX = "MailboxSettings.mailbox";
|
||||||
private static final String BUNDLE_NEEDS_SAVE = "MailboxSettings.needsSave";
|
private static final String BUNDLE_MAX_LOOKBACK = "MailboxSettings.maxLookback";
|
||||||
|
private static final String BUNDLE_SYNC_ENABLED_VALUE = "MailboxSettings.syncEnabled";
|
||||||
|
private static final String BUNDLE_SYNC_WINDOW_VALUE = "MailboxSettings.syncWindow";
|
||||||
|
|
||||||
private static final String PREF_CHECK_FREQUENCY_KEY = "check_frequency";
|
private static final String PREF_SYNC_ENABLED_KEY = "sync_enabled";
|
||||||
private static final String PREF_SYNC_WINDOW_KEY = "sync_window";
|
private static final String PREF_SYNC_WINDOW_KEY = "sync_window";
|
||||||
|
|
||||||
|
/** Projection for loading an account's policy key. */
|
||||||
|
private static final String[] POLICY_KEY_PROJECTION = { Account.POLICY_KEY };
|
||||||
|
private static final int POLICY_KEY_COLUMN = 0;
|
||||||
|
|
||||||
|
/** Projection for loading the max email lookback. */
|
||||||
|
private static final String[] MAX_EMAIL_LOOKBACK_PROJECTION = { Policy.MAX_EMAIL_LOOKBACK };
|
||||||
|
private static final int MAX_EMAIL_LOOKBACK_COLUMN = 0;
|
||||||
|
|
||||||
private final EmailAsyncTask.Tracker mTaskTracker = new EmailAsyncTask.Tracker();
|
private final EmailAsyncTask.Tracker mTaskTracker = new EmailAsyncTask.Tracker();
|
||||||
|
|
||||||
// Account and Mailbox -- directly loaded by LoadMailboxTask
|
|
||||||
private Account mAccount;
|
|
||||||
private Mailbox mMailbox;
|
private Mailbox mMailbox;
|
||||||
private boolean mNeedsSave;
|
/** The maximum lookback allowed for this mailbox, or 0 if no max. */
|
||||||
|
private int mMaxLookback;
|
||||||
|
|
||||||
private ListPreference mSyncIntervalPref;
|
private CheckBoxPreference mSyncEnabledPref;
|
||||||
private ListPreference mSyncLookbackPref;
|
private ListPreference mSyncLookbackPref;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -96,24 +104,21 @@ public class MailboxSettings extends PreferenceActivity {
|
|||||||
|
|
||||||
addPreferencesFromResource(R.xml.mailbox_preferences);
|
addPreferencesFromResource(R.xml.mailbox_preferences);
|
||||||
|
|
||||||
mSyncIntervalPref = (ListPreference) findPreference(PREF_CHECK_FREQUENCY_KEY);
|
mSyncEnabledPref = (CheckBoxPreference) findPreference(PREF_SYNC_ENABLED_KEY);
|
||||||
mSyncLookbackPref = (ListPreference) findPreference(PREF_SYNC_WINDOW_KEY);
|
mSyncLookbackPref = (ListPreference) findPreference(PREF_SYNC_WINDOW_KEY);
|
||||||
|
|
||||||
mSyncIntervalPref.setOnPreferenceChangeListener(mPreferenceChanged);
|
|
||||||
mSyncLookbackPref.setOnPreferenceChangeListener(mPreferenceChanged);
|
mSyncLookbackPref.setOnPreferenceChangeListener(mPreferenceChanged);
|
||||||
|
|
||||||
// Make them disabled until we load data
|
|
||||||
enablePreferences(false);
|
|
||||||
|
|
||||||
if (savedInstanceState != null) {
|
if (savedInstanceState != null) {
|
||||||
mAccount = savedInstanceState.getParcelable(BUNDLE_ACCOUNT);
|
|
||||||
mMailbox = savedInstanceState.getParcelable(BUNDLE_MAILBOX);
|
mMailbox = savedInstanceState.getParcelable(BUNDLE_MAILBOX);
|
||||||
mNeedsSave = savedInstanceState.getBoolean(BUNDLE_NEEDS_SAVE);
|
mMaxLookback = savedInstanceState.getInt(BUNDLE_MAX_LOOKBACK);
|
||||||
}
|
mSyncEnabledPref.setChecked(savedInstanceState.getBoolean(BUNDLE_SYNC_ENABLED_VALUE));
|
||||||
if (mAccount == null) {
|
mSyncLookbackPref.setValue(savedInstanceState.getString(BUNDLE_SYNC_WINDOW_VALUE));
|
||||||
new LoadMailboxTask(mailboxId).executeParallel((Void[]) null);
|
|
||||||
} else {
|
|
||||||
onDataLoaded();
|
onDataLoaded();
|
||||||
|
} else {
|
||||||
|
// Make them disabled until we load data
|
||||||
|
enablePreferences(false);
|
||||||
|
new LoadMailboxTask(mailboxId).executeParallel((Void[]) null);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Always show "app up" as we expect our parent to be an Email activity.
|
// Always show "app up" as we expect our parent to be an Email activity.
|
||||||
@ -124,16 +129,17 @@ public class MailboxSettings extends PreferenceActivity {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void enablePreferences(boolean enabled) {
|
private void enablePreferences(boolean enabled) {
|
||||||
mSyncIntervalPref.setEnabled(enabled);
|
mSyncEnabledPref.setEnabled(enabled);
|
||||||
mSyncLookbackPref.setEnabled(enabled);
|
mSyncLookbackPref.setEnabled(enabled);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onSaveInstanceState(Bundle outState) {
|
protected void onSaveInstanceState(Bundle outState) {
|
||||||
super.onSaveInstanceState(outState);
|
super.onSaveInstanceState(outState);
|
||||||
outState.putParcelable(BUNDLE_ACCOUNT, mAccount);
|
|
||||||
outState.putParcelable(BUNDLE_MAILBOX, mMailbox);
|
outState.putParcelable(BUNDLE_MAILBOX, mMailbox);
|
||||||
outState.putBoolean(BUNDLE_NEEDS_SAVE, mNeedsSave);
|
outState.putInt(BUNDLE_MAX_LOOKBACK, mMaxLookback);
|
||||||
|
outState.putBoolean(BUNDLE_SYNC_ENABLED_VALUE, mSyncEnabledPref.isChecked());
|
||||||
|
outState.putString(BUNDLE_SYNC_WINDOW_VALUE, mSyncLookbackPref.getValue());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -149,7 +155,7 @@ public class MailboxSettings extends PreferenceActivity {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Loads {@link #mAccount} and {@link #mMailbox}.
|
* Loads {@link #mMailbox} and {@link #mMaxLookback} from DB.
|
||||||
*/
|
*/
|
||||||
private class LoadMailboxTask extends EmailAsyncTask<Void, Void, Void> {
|
private class LoadMailboxTask extends EmailAsyncTask<Void, Void, Void> {
|
||||||
private final long mMailboxId;
|
private final long mMailboxId;
|
||||||
@ -163,19 +169,32 @@ public class MailboxSettings extends PreferenceActivity {
|
|||||||
protected Void doInBackground(Void... params) {
|
protected Void doInBackground(Void... params) {
|
||||||
final Context c = MailboxSettings.this;
|
final Context c = MailboxSettings.this;
|
||||||
mMailbox = Mailbox.restoreMailboxWithId(c, mMailboxId);
|
mMailbox = Mailbox.restoreMailboxWithId(c, mMailboxId);
|
||||||
|
mMaxLookback = 0;
|
||||||
if (mMailbox != null) {
|
if (mMailbox != null) {
|
||||||
mAccount = Account.restoreAccountWithId(c, mMailbox.mAccountKey);
|
final ContentResolver cr = c.getContentResolver();
|
||||||
|
// Get the max lookback from our policy, if we have one.
|
||||||
|
final Long policyKey = Utility.getFirstRowLong(c, ContentUris.withAppendedId(
|
||||||
|
Account.CONTENT_URI, mMailbox.mAccountKey), POLICY_KEY_PROJECTION,
|
||||||
|
null, null, null, POLICY_KEY_COLUMN);
|
||||||
|
if (policyKey != null) {
|
||||||
|
mMaxLookback = Utility.getFirstRowInt(c, ContentUris.withAppendedId(
|
||||||
|
Policy.CONTENT_URI, policyKey), MAX_EMAIL_LOOKBACK_PROJECTION,
|
||||||
|
null, null, null, MAX_EMAIL_LOOKBACK_COLUMN, 0);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onSuccess(Void result) {
|
protected void onSuccess(Void result) {
|
||||||
if ((mAccount == null) || (mMailbox == null)) {
|
if (mMailbox == null) {
|
||||||
finish(); // Account or mailbox removed.
|
finish(); // Account or mailbox removed.
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
mSyncEnabledPref.setChecked(mMailbox.mSyncInterval != 0);
|
||||||
|
mSyncLookbackPref.setValue(String.valueOf(mMailbox.mSyncLookback));
|
||||||
onDataLoaded();
|
onDataLoaded();
|
||||||
|
enablePreferences(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -183,11 +202,11 @@ public class MailboxSettings extends PreferenceActivity {
|
|||||||
* Setup the entries and entry values for the sync lookback preference
|
* Setup the entries and entry values for the sync lookback preference
|
||||||
* @param context the caller's context
|
* @param context the caller's context
|
||||||
* @param pref a ListPreference to be set up
|
* @param pref a ListPreference to be set up
|
||||||
* @param account the Account (or owner of a Mailbox) whose preference is being set
|
* @param maxLookback The maximum lookback allowed, or 0 if no max.
|
||||||
* @param showWithDefault Whether to show the version with default, or without.
|
* @param showWithDefault Whether to show the version with default, or without.
|
||||||
*/
|
*/
|
||||||
public static void setupLookbackPreferenceOptions(final Context context,
|
public static void setupLookbackPreferenceOptions(final Context context,
|
||||||
final ListPreference pref, final Account account, final boolean showWithDefault) {
|
final ListPreference pref, final int maxLookback, final boolean showWithDefault) {
|
||||||
final Resources resources = context.getResources();
|
final Resources resources = context.getResources();
|
||||||
// Load the complete list of entries/values
|
// Load the complete list of entries/values
|
||||||
CharSequence[] entries;
|
CharSequence[] entries;
|
||||||
@ -205,30 +224,26 @@ public class MailboxSettings extends PreferenceActivity {
|
|||||||
offset = 0;
|
offset = 0;
|
||||||
}
|
}
|
||||||
// If we have a maximum lookback policy, enforce it
|
// If we have a maximum lookback policy, enforce it
|
||||||
if (account.mPolicyKey > 0) {
|
if (maxLookback > 0) {
|
||||||
Policy policy = Policy.restorePolicyWithId(context, account.mPolicyKey);
|
final int size = maxLookback + offset;
|
||||||
if (policy != null && (policy.mMaxEmailLookback != 0)) {
|
entries = Arrays.copyOf(entries, size);
|
||||||
final int size = policy.mMaxEmailLookback + offset;
|
values = Arrays.copyOf(values, size);
|
||||||
entries = Arrays.copyOf(entries, size);
|
|
||||||
values = Arrays.copyOf(values, size);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
// Set up the preference
|
// Set up the preference
|
||||||
pref.setEntries(entries);
|
pref.setEntries(entries);
|
||||||
pref.setEntryValues(values);
|
pref.setEntryValues(values);
|
||||||
|
pref.setSummary(pref.getEntry());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Called when {@link #mAccount} and {@link #mMailbox} are loaded (either by the async task
|
* Called when {@link #mMailbox} is loaded (either by the async task or from the saved state).
|
||||||
* or from the saved state).
|
|
||||||
*/
|
*/
|
||||||
private void onDataLoaded() {
|
private void onDataLoaded() {
|
||||||
Preconditions.checkNotNull(mAccount);
|
|
||||||
Preconditions.checkNotNull(mMailbox);
|
Preconditions.checkNotNull(mMailbox);
|
||||||
|
|
||||||
// Update the title with the mailbox name.
|
// Update the title with the mailbox name.
|
||||||
ActionBar actionBar = getActionBar();
|
final ActionBar actionBar = getActionBar();
|
||||||
String mailboxName = mMailbox.mDisplayName;
|
final String mailboxName = mMailbox.mDisplayName;
|
||||||
if (actionBar != null) {
|
if (actionBar != null) {
|
||||||
actionBar.setTitle(mailboxName);
|
actionBar.setTitle(mailboxName);
|
||||||
actionBar.setSubtitle(getString(R.string.mailbox_settings_activity_title));
|
actionBar.setSubtitle(getString(R.string.mailbox_settings_activity_title));
|
||||||
@ -236,92 +251,19 @@ public class MailboxSettings extends PreferenceActivity {
|
|||||||
setTitle(getString(R.string.mailbox_settings_activity_title_with_mailbox, mailboxName));
|
setTitle(getString(R.string.mailbox_settings_activity_title_with_mailbox, mailboxName));
|
||||||
}
|
}
|
||||||
|
|
||||||
setupLookbackPreferenceOptions(this, mSyncLookbackPref, mAccount,
|
setupLookbackPreferenceOptions(this, mSyncLookbackPref, mMaxLookback, true);
|
||||||
mMailbox.mType != Mailbox.TYPE_INBOX);
|
|
||||||
|
|
||||||
// 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() {
|
|
||||||
int syncInterval;
|
|
||||||
if (mMailbox.mType == Mailbox.TYPE_INBOX) {
|
|
||||||
syncInterval = mAccount.mSyncInterval;
|
|
||||||
} else {
|
|
||||||
if (mMailbox.mSyncInterval == 0) {
|
|
||||||
// 0 is the default value, and it means "don't sync" (for non-inbox mailboxes)
|
|
||||||
syncInterval = Mailbox.CHECK_INTERVAL_NEVER;
|
|
||||||
} else {
|
|
||||||
syncInterval = mMailbox.mSyncInterval;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return syncInterval;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @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() {
|
private final OnPreferenceChangeListener mPreferenceChanged = new OnPreferenceChangeListener() {
|
||||||
@Override
|
@Override
|
||||||
public boolean onPreferenceChange(Preference preference, Object newValue) {
|
public boolean onPreferenceChange(Preference preference, Object newValue) {
|
||||||
final ListPreference lp = (ListPreference) preference;
|
mSyncLookbackPref.setValue((String) newValue);
|
||||||
if (Objects.equal(lp.getValue(), newValue)) {
|
mSyncLookbackPref.setSummary(mSyncLookbackPref.getEntry());
|
||||||
return false;
|
|
||||||
}
|
|
||||||
mNeedsSave = true;
|
|
||||||
if (MailActivityEmail.DEBUG) {
|
|
||||||
LogUtils.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;
|
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 (MailActivityEmail.DEBUG) {
|
|
||||||
LogUtils.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.
|
* Save changes to the database.
|
||||||
*
|
*
|
||||||
@ -331,48 +273,47 @@ public class MailboxSettings extends PreferenceActivity {
|
|||||||
* finished.
|
* finished.
|
||||||
*/
|
*/
|
||||||
private void saveToDatabase() {
|
private void saveToDatabase() {
|
||||||
if (!mNeedsSave) {
|
final int syncInterval = mSyncEnabledPref.isChecked() ? 1 : 0;
|
||||||
return;
|
final int syncLookback = Integer.valueOf(mSyncLookbackPref.getValue());
|
||||||
}
|
|
||||||
LogUtils.i(Logging.LOG_TAG, "Saving mailbox settings...");
|
|
||||||
enablePreferences(false);
|
|
||||||
|
|
||||||
// Since the activity will be destroyed...
|
final boolean syncIntervalChanged = syncInterval != mMailbox.mSyncInterval;
|
||||||
// Create local references (Although it's really okay to touch members of a destroyed
|
final boolean syncLookbackChanged = syncLookback != mMailbox.mSyncLookback;
|
||||||
// activity...)
|
|
||||||
final Account account = mAccount;
|
|
||||||
final Mailbox mailbox = mMailbox;
|
|
||||||
final Context context = getApplicationContext();
|
|
||||||
|
|
||||||
new EmailAsyncTask<Void, Void, Void> (null /* no cancel */) {
|
// Only save if a preference has changed value.
|
||||||
@Override
|
if (syncIntervalChanged || syncLookbackChanged) {
|
||||||
protected Void doInBackground(Void... params) {
|
LogUtils.i(Logging.LOG_TAG, "Saving mailbox settings...");
|
||||||
final ContentValues cv = new ContentValues();
|
enablePreferences(false);
|
||||||
final Uri uri;
|
|
||||||
|
|
||||||
if (mailbox.mType == Mailbox.TYPE_INBOX) {
|
final long id = mMailbox.mId;
|
||||||
cv.put(AccountColumns.SYNC_INTERVAL, account.mSyncInterval);
|
final Context context = getApplicationContext();
|
||||||
cv.put(AccountColumns.SYNC_LOOKBACK, account.mSyncLookback);
|
|
||||||
uri = ContentUris.withAppendedId(Account.CONTENT_URI, account.mId);
|
new EmailAsyncTask<Void, Void, Void> (null /* no cancel */) {
|
||||||
} else {
|
@Override
|
||||||
cv.put(MailboxColumns.SYNC_INTERVAL, mailbox.mSyncInterval);
|
protected Void doInBackground(Void... params) {
|
||||||
cv.put(MailboxColumns.SYNC_LOOKBACK, mailbox.mSyncLookback);
|
final ContentValues cv = new ContentValues(2);
|
||||||
uri = ContentUris.withAppendedId(Mailbox.CONTENT_URI, mailbox.mId);
|
final Uri uri;
|
||||||
|
if (syncIntervalChanged) {
|
||||||
|
cv.put(MailboxColumns.SYNC_INTERVAL, syncInterval);
|
||||||
|
}
|
||||||
|
if (syncLookbackChanged) {
|
||||||
|
cv.put(MailboxColumns.SYNC_LOOKBACK, syncLookback);
|
||||||
|
}
|
||||||
|
uri = ContentUris.withAppendedId(Mailbox.CONTENT_URI, id);
|
||||||
|
context.getContentResolver().update(uri, cv, null, null);
|
||||||
|
|
||||||
|
LogUtils.i(Logging.LOG_TAG, "Saved: " + uri);
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
context.getContentResolver().update(uri, cv, null, null);
|
|
||||||
|
|
||||||
LogUtils.i(Logging.LOG_TAG, "Saved: " + uri);
|
@Override
|
||||||
return null;
|
protected void onSuccess(Void result) {
|
||||||
}
|
// must be called on the ui thread
|
||||||
|
//***
|
||||||
@Override
|
//RefreshManager.getInstance(context).refreshMessageList(account.mId,
|
||||||
protected void onSuccess(Void result) {
|
// mailbox.mId, true);
|
||||||
// must be called on the ui thread
|
}
|
||||||
//***
|
}.executeSerial((Void [])null);
|
||||||
//RefreshManager.getInstance(context).refreshMessageList(account.mId, mailbox.mId,
|
}
|
||||||
// true);
|
|
||||||
}
|
|
||||||
}.executeSerial((Void [])null);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
Loading…
Reference in New Issue
Block a user