diff --git a/k9mail/src/main/java/com/fsck/k9/Account.java b/k9mail/src/main/java/com/fsck/k9/Account.java index 8f85570d9..b75932e54 100644 --- a/k9mail/src/main/java/com/fsck/k9/Account.java +++ b/k9mail/src/main/java/com/fsck/k9/Account.java @@ -47,6 +47,8 @@ import com.fsck.k9.mail.ssl.LocalKeyStore; import com.fsck.k9.view.ColorChip; import com.larswerkman.colorpicker.ColorPicker; +import static com.fsck.k9.Preferences.getEnumStringPref; + /** * Account stores all of the settings for a single account defined by the user. It is able to save * and delete itself given a Preferences to work with. Each account is defined by a UUID. @@ -62,19 +64,43 @@ public class Account implements BaseAccount, StoreConfig { */ public static final String OUTBOX = "K9MAIL_INTERNAL_OUTBOX"; - public static final String EXPUNGE_IMMEDIATELY = "EXPUNGE_IMMEDIATELY"; - public static final String EXPUNGE_MANUALLY = "EXPUNGE_MANUALLY"; - public static final String EXPUNGE_ON_POLL = "EXPUNGE_ON_POLL"; + public enum Expunge { + EXPUNGE_IMMEDIATELY, + EXPUNGE_MANUALLY, + EXPUNGE_ON_POLL + } - public static final int DELETE_POLICY_NEVER = 0; - public static final int DELETE_POLICY_7DAYS = 1; - public static final int DELETE_POLICY_ON_DELETE = 2; - public static final int DELETE_POLICY_MARK_AS_READ = 3; + public enum DeletePolicy { + NEVER(0), + SEVEN_DAYS(1), + ON_DELETE(2), + MARK_AS_READ(3); - public static final String TYPE_WIFI = "WIFI"; - public static final String TYPE_MOBILE = "MOBILE"; - public static final String TYPE_OTHER = "OTHER"; - private static final String[] networkTypes = { TYPE_WIFI, TYPE_MOBILE, TYPE_OTHER }; + public final int setting; + + DeletePolicy(int setting) { + this.setting = setting; + } + + public String preferenceString() { + return Integer.toString(setting); + } + + public static DeletePolicy fromInt(int initialSetting) { + for (DeletePolicy policy: values()) { + if (policy.setting == initialSetting) { + return policy; + } + } + throw new IllegalArgumentException("DeletePolicy " + initialSetting + " unknown"); + } + } + + public enum NetworkType { + WIFI, + MOBILE, + OTHER + } public static final MessageFormat DEFAULT_MESSAGE_FORMAT = MessageFormat.HTML; public static final boolean DEFAULT_MESSAGE_FORMAT_AUTO = false; @@ -138,16 +164,7 @@ public class Account implements BaseAccount, StoreConfig { public static final boolean DEFAULT_SORT_ASCENDING = false; public static final String NO_OPENPGP_PROVIDER = ""; - - /** - *
-     * 0 - Never (DELETE_POLICY_NEVER)
-     * 1 - After 7 days (DELETE_POLICY_7DAYS)
-     * 2 - When I delete from inbox (DELETE_POLICY_ON_DELETE)
-     * 3 - Mark as read (DELETE_POLICY_MARK_AS_READ)
-     * 
- */ - private int mDeletePolicy; + private DeletePolicy mDeletePolicy = DeletePolicy.NEVER; private final String mUuid; private String mStoreUri; @@ -186,11 +203,11 @@ public class Account implements BaseAccount, StoreConfig { private Map mSortAscending = new HashMap(); private ShowPictures mShowPictures; private boolean mIsSignatureBeforeQuotedText; - private String mExpungePolicy = EXPUNGE_IMMEDIATELY; + private Expunge mExpungePolicy = Expunge.EXPUNGE_IMMEDIATELY; private int mMaxPushFolders; private int mIdleRefreshMinutes; private boolean goToUnreadMessageSearch; - private final Map compressionMap = new ConcurrentHashMap(); + private final Map compressionMap = new ConcurrentHashMap(); private Searchable searchableFolders; private boolean subscribedFoldersOnly; private int maximumPolledMessageAge; @@ -283,7 +300,7 @@ public class Account implements BaseAccount, StoreConfig { mSortAscending.put(DEFAULT_SORT_TYPE, DEFAULT_SORT_ASCENDING); mShowPictures = ShowPictures.NEVER; mIsSignatureBeforeQuotedText = false; - mExpungePolicy = EXPUNGE_IMMEDIATELY; + mExpungePolicy = Expunge.EXPUNGE_IMMEDIATELY; mAutoExpandFolderName = INBOX; mInboxFolderName = INBOX; mMaxPushFolders = 10; @@ -379,22 +396,18 @@ public class Account implements BaseAccount, StoreConfig { mLastAutomaticCheckTime = prefs.getLong(mUuid + ".lastAutomaticCheckTime", 0); mLatestOldMessageSeenTime = prefs.getLong(mUuid + ".latestOldMessageSeenTime", 0); mNotifyNewMail = prefs.getBoolean(mUuid + ".notifyNewMail", false); - try { - mFolderNotifyNewMailMode = FolderMode.valueOf(prefs.getString(mUuid + ".folderNotifyNewMailMode", - FolderMode.ALL.name())); - } catch (Exception e) { - mFolderNotifyNewMailMode = FolderMode.ALL; - } + + mFolderNotifyNewMailMode = getEnumStringPref(prefs, mUuid + ".folderNotifyNewMailMode", FolderMode.ALL); mNotifySelfNewMail = prefs.getBoolean(mUuid + ".notifySelfNewMail", true); mNotifySync = prefs.getBoolean(mUuid + ".notifyMailCheck", false); - mDeletePolicy = prefs.getInt(mUuid + ".deletePolicy", 0); + mDeletePolicy = DeletePolicy.fromInt(prefs.getInt(mUuid + ".deletePolicy", DeletePolicy.NEVER.setting)); mInboxFolderName = prefs.getString(mUuid + ".inboxFolderName", INBOX); mDraftsFolderName = prefs.getString(mUuid + ".draftsFolderName", "Drafts"); mSentFolderName = prefs.getString(mUuid + ".sentFolderName", "Sent"); mTrashFolderName = prefs.getString(mUuid + ".trashFolderName", "Trash"); mArchiveFolderName = prefs.getString(mUuid + ".archiveFolderName", "Archive"); mSpamFolderName = prefs.getString(mUuid + ".spamFolderName", "Spam"); - mExpungePolicy = prefs.getString(mUuid + ".expungePolicy", EXPUNGE_IMMEDIATELY); + mExpungePolicy = getEnumStringPref(prefs, mUuid + ".expungePolicy", Expunge.EXPUNGE_IMMEDIATELY); mSyncRemoteDeletions = prefs.getBoolean(mUuid + ".syncRemoteDeletions", true); mMaxPushFolders = prefs.getInt(mUuid + ".maxPushFolders", 10); @@ -402,18 +415,18 @@ public class Account implements BaseAccount, StoreConfig { subscribedFoldersOnly = prefs.getBoolean(mUuid + ".subscribedFoldersOnly", false); maximumPolledMessageAge = prefs.getInt(mUuid + ".maximumPolledMessageAge", -1); maximumAutoDownloadMessageSize = prefs.getInt(mUuid + ".maximumAutoDownloadMessageSize", 32768); - mMessageFormat = MessageFormat.valueOf(prefs.getString(mUuid + ".messageFormat", DEFAULT_MESSAGE_FORMAT.name())); + mMessageFormat = getEnumStringPref(prefs, mUuid + ".messageFormat", DEFAULT_MESSAGE_FORMAT); mMessageFormatAuto = prefs.getBoolean(mUuid + ".messageFormatAuto", DEFAULT_MESSAGE_FORMAT_AUTO); if (mMessageFormatAuto && mMessageFormat == MessageFormat.TEXT) { mMessageFormat = MessageFormat.AUTO; } mMessageReadReceipt = prefs.getBoolean(mUuid + ".messageReadReceipt", DEFAULT_MESSAGE_READ_RECEIPT); - mQuoteStyle = QuoteStyle.valueOf(prefs.getString(mUuid + ".quoteStyle", DEFAULT_QUOTE_STYLE.name())); + mQuoteStyle = getEnumStringPref(prefs, mUuid + ".quoteStyle", DEFAULT_QUOTE_STYLE); mQuotePrefix = prefs.getString(mUuid + ".quotePrefix", DEFAULT_QUOTE_PREFIX); mDefaultQuotedTextShown = prefs.getBoolean(mUuid + ".defaultQuotedTextShown", DEFAULT_QUOTED_TEXT_SHOWN); mReplyAfterQuote = prefs.getBoolean(mUuid + ".replyAfterQuote", DEFAULT_REPLY_AFTER_QUOTE); mStripSignature = prefs.getBoolean(mUuid + ".stripSignature", DEFAULT_STRIP_SIGNATURE); - for (String type : networkTypes) { + for (NetworkType type : NetworkType.values()) { Boolean useCompression = prefs.getBoolean(mUuid + ".useCompression." + type, true); compressionMap.put(type, useCompression); @@ -425,21 +438,11 @@ public class Account implements BaseAccount, StoreConfig { mChipColor = prefs.getInt(mUuid + ".chipColor", ColorPicker.getRandomColor()); - try { - mSortType = SortType.valueOf(prefs.getString(mUuid + ".sortTypeEnum", - SortType.SORT_DATE.name())); - } catch (Exception e) { - mSortType = SortType.SORT_DATE; - } + mSortType = getEnumStringPref(prefs, mUuid + ".sortTypeEnum", SortType.SORT_DATE); mSortAscending.put(mSortType, prefs.getBoolean(mUuid + ".sortAscending", false)); - try { - mShowPictures = ShowPictures.valueOf(prefs.getString(mUuid + ".showPicturesEnum", - ShowPictures.NEVER.name())); - } catch (Exception e) { - mShowPictures = ShowPictures.NEVER; - } + mShowPictures = getEnumStringPref(prefs, mUuid + ".showPicturesEnum", ShowPictures.NEVER); mNotificationSetting.setVibrate(prefs.getBoolean(mUuid + ".vibrate", false)); mNotificationSetting.setVibratePattern(prefs.getInt(mUuid + ".vibratePattern", 0)); @@ -450,40 +453,15 @@ public class Account implements BaseAccount, StoreConfig { mNotificationSetting.setLed(prefs.getBoolean(mUuid + ".led", true)); mNotificationSetting.setLedColor(prefs.getInt(mUuid + ".ledColor", mChipColor)); - try { - mFolderDisplayMode = FolderMode.valueOf(prefs.getString(mUuid + ".folderDisplayMode", - FolderMode.NOT_SECOND_CLASS.name())); - } catch (Exception e) { - mFolderDisplayMode = FolderMode.NOT_SECOND_CLASS; - } + mFolderDisplayMode = getEnumStringPref(prefs, mUuid + ".folderDisplayMode", FolderMode.NOT_SECOND_CLASS); - try { - mFolderSyncMode = FolderMode.valueOf(prefs.getString(mUuid + ".folderSyncMode", - FolderMode.FIRST_CLASS.name())); - } catch (Exception e) { - mFolderSyncMode = FolderMode.FIRST_CLASS; - } + mFolderSyncMode = getEnumStringPref(prefs, mUuid + ".folderSyncMode", FolderMode.FIRST_CLASS); - try { - mFolderPushMode = FolderMode.valueOf(prefs.getString(mUuid + ".folderPushMode", - FolderMode.FIRST_CLASS.name())); - } catch (Exception e) { - mFolderPushMode = FolderMode.FIRST_CLASS; - } + mFolderPushMode = getEnumStringPref(prefs, mUuid + ".folderPushMode", FolderMode.FIRST_CLASS); - try { - mFolderTargetMode = FolderMode.valueOf(prefs.getString(mUuid + ".folderTargetMode", - FolderMode.NOT_SECOND_CLASS.name())); - } catch (Exception e) { - mFolderTargetMode = FolderMode.NOT_SECOND_CLASS; - } + mFolderTargetMode = getEnumStringPref(prefs, mUuid + ".folderTargetMode", FolderMode.NOT_SECOND_CLASS); - try { - searchableFolders = Searchable.valueOf(prefs.getString(mUuid + ".searchableFolders", - Searchable.ALL.name())); - } catch (Exception e) { - searchableFolders = Searchable.ALL; - } + searchableFolders = getEnumStringPref(prefs, mUuid + ".searchableFolders", Searchable.ALL); mIsSignatureBeforeQuotedText = prefs.getBoolean(mUuid + ".signatureBeforeQuotedText", false); identities = loadIdentities(prefs); @@ -591,8 +569,8 @@ public class Account implements BaseAccount, StoreConfig { editor.remove(mUuid + ".messageFormat"); editor.remove(mUuid + ".messageReadReceipt"); editor.remove(mUuid + ".notifyMailCheck"); - for (String type : networkTypes) { - editor.remove(mUuid + ".useCompression." + type); + for (NetworkType type : NetworkType.values()) { + editor.remove(mUuid + ".useCompression." + type.name()); } deleteIdentities(preferences.getPreferences(), editor); // TODO: Remove preference settings that may exist for individual @@ -707,7 +685,7 @@ public class Account implements BaseAccount, StoreConfig { editor.putString(mUuid + ".folderNotifyNewMailMode", mFolderNotifyNewMailMode.name()); editor.putBoolean(mUuid + ".notifySelfNewMail", mNotifySelfNewMail); editor.putBoolean(mUuid + ".notifyMailCheck", mNotifySync); - editor.putInt(mUuid + ".deletePolicy", mDeletePolicy); + editor.putInt(mUuid + ".deletePolicy", mDeletePolicy.setting); editor.putString(mUuid + ".inboxFolderName", mInboxFolderName); editor.putString(mUuid + ".draftsFolderName", mDraftsFolderName); editor.putString(mUuid + ".sentFolderName", mSentFolderName); @@ -724,7 +702,7 @@ public class Account implements BaseAccount, StoreConfig { editor.putString(mUuid + ".folderPushMode", mFolderPushMode.name()); editor.putString(mUuid + ".folderTargetMode", mFolderTargetMode.name()); editor.putBoolean(mUuid + ".signatureBeforeQuotedText", this.mIsSignatureBeforeQuotedText); - editor.putString(mUuid + ".expungePolicy", mExpungePolicy); + editor.putString(mUuid + ".expungePolicy", mExpungePolicy.name()); editor.putBoolean(mUuid + ".syncRemoteDeletions", mSyncRemoteDeletions); editor.putInt(mUuid + ".maxPushFolders", mMaxPushFolders); editor.putString(mUuid + ".searchableFolders", searchableFolders.name()); @@ -765,7 +743,7 @@ public class Account implements BaseAccount, StoreConfig { editor.putBoolean(mUuid + ".led", mNotificationSetting.isLed()); editor.putInt(mUuid + ".ledColor", mNotificationSetting.getLedColor()); - for (String type : networkTypes) { + for (NetworkType type : NetworkType.values()) { Boolean useCompression = compressionMap.get(type); if (useCompression != null) { editor.putBoolean(mUuid + ".useCompression." + type, useCompression); @@ -1056,11 +1034,11 @@ public class Account implements BaseAccount, StoreConfig { this.mFolderNotifyNewMailMode = folderNotifyNewMailMode; } - public synchronized int getDeletePolicy() { + public synchronized DeletePolicy getDeletePolicy() { return mDeletePolicy; } - public synchronized void setDeletePolicy(int deletePolicy) { + public synchronized void setDeletePolicy(DeletePolicy deletePolicy) { this.mDeletePolicy = deletePolicy; } @@ -1273,11 +1251,11 @@ public class Account implements BaseAccount, StoreConfig { mNotifySelfNewMail = notifySelfNewMail; } - public synchronized String getExpungePolicy() { + public synchronized Expunge getExpungePolicy() { return mExpungePolicy; } - public synchronized void setExpungePolicy(String expungePolicy) { + public synchronized void setExpungePolicy(Expunge expungePolicy) { mExpungePolicy = expungePolicy; } @@ -1312,11 +1290,11 @@ public class Account implements BaseAccount, StoreConfig { return mDescription; } - public synchronized void setCompression(String networkType, boolean useCompression) { + public synchronized void setCompression(NetworkType networkType, boolean useCompression) { compressionMap.put(networkType, useCompression); } - public synchronized boolean useCompression(String networkType) { + public synchronized boolean useCompression(NetworkType networkType) { Boolean useCompression = compressionMap.get(networkType); if (useCompression == null) { return true; @@ -1326,13 +1304,13 @@ public class Account implements BaseAccount, StoreConfig { } public boolean useCompression(int type) { - String networkType = TYPE_OTHER; + NetworkType networkType = NetworkType.OTHER; switch (type) { case ConnectivityManager.TYPE_MOBILE: - networkType = TYPE_MOBILE; + networkType = NetworkType.MOBILE; break; case ConnectivityManager.TYPE_WIFI: - networkType = TYPE_WIFI; + networkType = NetworkType.WIFI; break; } return useCompression(networkType); diff --git a/k9mail/src/main/java/com/fsck/k9/Preferences.java b/k9mail/src/main/java/com/fsck/k9/Preferences.java index 7d03b668e..eea45c144 100644 --- a/k9mail/src/main/java/com/fsck/k9/Preferences.java +++ b/k9mail/src/main/java/com/fsck/k9/Preferences.java @@ -70,6 +70,7 @@ public class Preferences { /** * Returns an array of the accounts on the system. If no accounts are * registered the method returns an empty array. + * * @return all accounts */ public synchronized List getAccounts() { @@ -83,6 +84,7 @@ public class Preferences { /** * Returns an array of the accounts on the system. If no accounts are * registered the method returns an empty array. + * * @return all accounts with {@link Account#isAvailable(Context)} */ public synchronized Collection getAvailableAccounts() { @@ -164,4 +166,21 @@ public class Preferences { public SharedPreferences getPreferences() { return mStorage; } + + public static > T getEnumStringPref(SharedPreferences prefs, String key, T defaultEnum) { + String stringPref = prefs.getString(key, null); + + if (stringPref == null) { + return defaultEnum; + } else { + try { + return Enum.valueOf(defaultEnum.getDeclaringClass(), stringPref); + } catch (IllegalArgumentException ex) { + Log.w(K9.LOG_TAG, "Unable to convert preference key [" + key + + "] value [" + stringPref + "] to enum of type " + defaultEnum.getDeclaringClass(), ex); + + return defaultEnum; + } + } + } } diff --git a/k9mail/src/main/java/com/fsck/k9/activity/setup/AccountSettings.java b/k9mail/src/main/java/com/fsck/k9/activity/setup/AccountSettings.java index c9127b2d7..9ebeee4f9 100644 --- a/k9mail/src/main/java/com/fsck/k9/activity/setup/AccountSettings.java +++ b/k9mail/src/main/java/com/fsck/k9/activity/setup/AccountSettings.java @@ -23,8 +23,13 @@ import android.preference.RingtonePreference; import android.util.Log; import com.fsck.k9.Account; +import com.fsck.k9.Account.DeletePolicy; +import com.fsck.k9.Account.Expunge; import com.fsck.k9.Account.FolderMode; +import com.fsck.k9.Account.MessageFormat; import com.fsck.k9.Account.QuoteStyle; +import com.fsck.k9.Account.Searchable; +import com.fsck.k9.Account.ShowPictures; import com.fsck.k9.K9; import com.fsck.k9.NotificationSetting; import com.fsck.k9.Preferences; @@ -353,9 +358,9 @@ public class AccountSettings extends K9PreferenceActivity { mDeletePolicy = (ListPreference) findPreference(PREFERENCE_DELETE_POLICY); if (!mIsSeenFlagSupported) { - removeListEntry(mDeletePolicy, Integer.toString(Account.DELETE_POLICY_MARK_AS_READ)); + removeListEntry(mDeletePolicy, DeletePolicy.MARK_AS_READ.preferenceString()); } - mDeletePolicy.setValue(Integer.toString(mAccount.getDeletePolicy())); + mDeletePolicy.setValue(mAccount.getDeletePolicy().preferenceString()); mDeletePolicy.setSummary(mDeletePolicy.getEntry()); mDeletePolicy.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() { public boolean onPreferenceChange(Preference preference, Object newValue) { @@ -370,7 +375,7 @@ public class AccountSettings extends K9PreferenceActivity { mExpungePolicy = (ListPreference) findPreference(PREFERENCE_EXPUNGE_POLICY); if (mIsExpungeCapable) { - mExpungePolicy.setValue(mAccount.getExpungePolicy()); + mExpungePolicy.setValue(mAccount.getExpungePolicy().name()); mExpungePolicy.setSummary(mExpungePolicy.getEntry()); mExpungePolicy.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() { public boolean onPreferenceChange(Preference preference, Object newValue) { @@ -729,7 +734,7 @@ public class AccountSettings extends K9PreferenceActivity { mAccount.setDescription(mAccountDescription.getText()); mAccount.setMarkMessageAsReadOnView(mMarkMessageAsReadOnView.isChecked()); mAccount.setNotifyNewMail(mAccountNotify.isChecked()); - mAccount.setFolderNotifyNewMailMode(Account.FolderMode.valueOf(mAccountNotifyNewMailMode.getValue())); + mAccount.setFolderNotifyNewMailMode(FolderMode.valueOf(mAccountNotifyNewMailMode.getValue())); mAccount.setNotifySelfNewMail(mAccountNotifySelf.isChecked()); mAccount.setShowOngoing(mAccountNotifySync.isChecked()); mAccount.setDisplayCount(Integer.parseInt(mDisplayCount.getValue())); @@ -742,14 +747,14 @@ public class AccountSettings extends K9PreferenceActivity { mAccount.getNotificationSetting().setVibrateTimes(Integer.parseInt(mAccountVibrateTimes.getValue())); mAccount.getNotificationSetting().setLed(mAccountLed.isChecked()); mAccount.setGoToUnreadMessageSearch(mNotificationOpensUnread.isChecked()); - mAccount.setFolderTargetMode(Account.FolderMode.valueOf(mTargetMode.getValue())); - mAccount.setDeletePolicy(Integer.parseInt(mDeletePolicy.getValue())); + mAccount.setFolderTargetMode(FolderMode.valueOf(mTargetMode.getValue())); + mAccount.setDeletePolicy(DeletePolicy.fromInt(Integer.parseInt(mDeletePolicy.getValue()))); if (mIsExpungeCapable) { - mAccount.setExpungePolicy(mExpungePolicy.getValue()); + mAccount.setExpungePolicy(Expunge.valueOf(mExpungePolicy.getValue())); } mAccount.setSyncRemoteDeletions(mSyncRemoteDeletions.isChecked()); - mAccount.setSearchableFolders(Account.Searchable.valueOf(mSearchableFolders.getValue())); - mAccount.setMessageFormat(Account.MessageFormat.valueOf(mMessageFormat.getValue())); + mAccount.setSearchableFolders(Searchable.valueOf(mSearchableFolders.getValue())); + mAccount.setMessageFormat(MessageFormat.valueOf(mMessageFormat.getValue())); mAccount.setAlwaysShowCcBcc(mAlwaysShowCcBcc.isChecked()); mAccount.setMessageReadReceipt(mMessageReadReceipt.isChecked()); mAccount.setQuoteStyle(QuoteStyle.valueOf(mQuoteStyle.getValue())); @@ -788,9 +793,9 @@ public class AccountSettings extends K9PreferenceActivity { } boolean needsRefresh = mAccount.setAutomaticCheckIntervalMinutes(Integer.parseInt(mCheckFrequency.getValue())); - needsRefresh |= mAccount.setFolderSyncMode(Account.FolderMode.valueOf(mSyncMode.getValue())); + needsRefresh |= mAccount.setFolderSyncMode(FolderMode.valueOf(mSyncMode.getValue())); - boolean displayModeChanged = mAccount.setFolderDisplayMode(Account.FolderMode.valueOf(mDisplayMode.getValue())); + boolean displayModeChanged = mAccount.setFolderDisplayMode(FolderMode.valueOf(mDisplayMode.getValue())); SharedPreferences prefs = mAccountRingtone.getPreferenceManager().getSharedPreferences(); String newRingtone = prefs.getString(PREFERENCE_RINGTONE, null); @@ -803,11 +808,11 @@ public class AccountSettings extends K9PreferenceActivity { } } - mAccount.setShowPictures(Account.ShowPictures.valueOf(mAccountShowPictures.getValue())); + mAccount.setShowPictures(ShowPictures.valueOf(mAccountShowPictures.getValue())); //IMAP specific stuff if (mIsPushCapable) { - boolean needsPushRestart = mAccount.setFolderPushMode(Account.FolderMode.valueOf(mPushMode.getValue())); + boolean needsPushRestart = mAccount.setFolderPushMode(FolderMode.valueOf(mPushMode.getValue())); if (mAccount.getFolderPushMode() != FolderMode.NONE) { needsPushRestart |= displayModeChanged; needsPushRestart |= mIncomingChanged; diff --git a/k9mail/src/main/java/com/fsck/k9/activity/setup/AccountSetupBasics.java b/k9mail/src/main/java/com/fsck/k9/activity/setup/AccountSetupBasics.java index a0c129541..91cd119ba 100644 --- a/k9mail/src/main/java/com/fsck/k9/activity/setup/AccountSetupBasics.java +++ b/k9mail/src/main/java/com/fsck/k9/activity/setup/AccountSetupBasics.java @@ -27,6 +27,7 @@ import android.widget.CompoundButton.OnCheckedChangeListener; import android.widget.EditText; import com.fsck.k9.Account; +import com.fsck.k9.Account.DeletePolicy; import com.fsck.k9.EmailAddressValidator; import com.fsck.k9.K9; import com.fsck.k9.Preferences; @@ -331,9 +332,9 @@ public class AccountSetupBasics extends K9Activity } mAccount.setSentFolderName(getString(R.string.special_mailbox_name_sent)); if (incomingUri.toString().startsWith("imap")) { - mAccount.setDeletePolicy(Account.DELETE_POLICY_ON_DELETE); + mAccount.setDeletePolicy(DeletePolicy.ON_DELETE); } else if (incomingUri.toString().startsWith("pop3")) { - mAccount.setDeletePolicy(Account.DELETE_POLICY_NEVER); + mAccount.setDeletePolicy(DeletePolicy.NEVER); } // Check incoming here. Then check outgoing in onActivityResult() AccountSetupCheckSettings.actionCheckSettings(this, mAccount, CheckDirection.INCOMING); diff --git a/k9mail/src/main/java/com/fsck/k9/activity/setup/AccountSetupIncoming.java b/k9mail/src/main/java/com/fsck/k9/activity/setup/AccountSetupIncoming.java index 2a97b0f93..07281a48b 100644 --- a/k9mail/src/main/java/com/fsck/k9/activity/setup/AccountSetupIncoming.java +++ b/k9mail/src/main/java/com/fsck/k9/activity/setup/AccountSetupIncoming.java @@ -16,7 +16,9 @@ import android.widget.AdapterView.OnItemSelectedListener; import android.widget.CompoundButton.OnCheckedChangeListener; import com.fsck.k9.*; +import com.fsck.k9.Account.DeletePolicy; import com.fsck.k9.Account.FolderMode; +import com.fsck.k9.Account.NetworkType; import com.fsck.k9.activity.K9Activity; import com.fsck.k9.activity.setup.AccountSetupCheckSettings.CheckDirection; import com.fsck.k9.helper.Utility; @@ -200,7 +202,7 @@ public class AccountSetupIncoming extends K9Activity implements OnClickListener findViewById(R.id.compression_section).setVisibility(View.GONE); findViewById(R.id.compression_label).setVisibility(View.GONE); mSubscribedFoldersOnly.setVisibility(View.GONE); - mAccount.setDeletePolicy(Account.DELETE_POLICY_NEVER); + mAccount.setDeletePolicy(DeletePolicy.NEVER); } else if (ImapStore.STORE_TYPE.equals(settings.type)) { serverLabelView.setText(R.string.account_setup_incoming_imap_server_label); mDefaultPort = IMAP_PORT; @@ -217,7 +219,7 @@ public class AccountSetupIncoming extends K9Activity implements OnClickListener findViewById(R.id.webdav_mailbox_alias_section).setVisibility(View.GONE); findViewById(R.id.webdav_owa_path_section).setVisibility(View.GONE); findViewById(R.id.webdav_auth_path_section).setVisibility(View.GONE); - mAccount.setDeletePolicy(Account.DELETE_POLICY_ON_DELETE); + mAccount.setDeletePolicy(DeletePolicy.ON_DELETE); if (!Intent.ACTION_EDIT.equals(getIntent().getAction())) { findViewById(R.id.imap_folder_setup_section).setVisibility(View.GONE); @@ -251,7 +253,7 @@ public class AccountSetupIncoming extends K9Activity implements OnClickListener if (webDavSettings.mailboxPath != null) { mWebdavMailboxPathView.setText(webDavSettings.mailboxPath); } - mAccount.setDeletePolicy(Account.DELETE_POLICY_ON_DELETE); + mAccount.setDeletePolicy(DeletePolicy.ON_DELETE); } else { throw new Exception("Unknown account type: " + mAccount.getStoreUri()); } @@ -280,9 +282,9 @@ public class AccountSetupIncoming extends K9Activity implements OnClickListener updateAuthPlainTextFromSecurityType(settings.connectionSecurity); - mCompressionMobile.setChecked(mAccount.useCompression(Account.TYPE_MOBILE)); - mCompressionWifi.setChecked(mAccount.useCompression(Account.TYPE_WIFI)); - mCompressionOther.setChecked(mAccount.useCompression(Account.TYPE_OTHER)); + mCompressionMobile.setChecked(mAccount.useCompression(NetworkType.MOBILE)); + mCompressionWifi.setChecked(mAccount.useCompression(NetworkType.WIFI)); + mCompressionOther.setChecked(mAccount.useCompression(NetworkType.OTHER)); if (settings.host != null) { mServerView.setText(settings.host); @@ -607,9 +609,9 @@ public class AccountSetupIncoming extends K9Activity implements OnClickListener mAccount.setStoreUri(RemoteStore.createStoreUri(settings)); - mAccount.setCompression(Account.TYPE_MOBILE, mCompressionMobile.isChecked()); - mAccount.setCompression(Account.TYPE_WIFI, mCompressionWifi.isChecked()); - mAccount.setCompression(Account.TYPE_OTHER, mCompressionOther.isChecked()); + mAccount.setCompression(NetworkType.MOBILE, mCompressionMobile.isChecked()); + mAccount.setCompression(NetworkType.WIFI, mCompressionWifi.isChecked()); + mAccount.setCompression(NetworkType.OTHER, mCompressionOther.isChecked()); mAccount.setSubscribedFoldersOnly(mSubscribedFoldersOnly.isChecked()); AccountSetupCheckSettings.actionCheckSettings(this, mAccount, CheckDirection.INCOMING); diff --git a/k9mail/src/main/java/com/fsck/k9/controller/MessagingController.java b/k9mail/src/main/java/com/fsck/k9/controller/MessagingController.java index 8d0dd8f20..9a5c356f9 100644 --- a/k9mail/src/main/java/com/fsck/k9/controller/MessagingController.java +++ b/k9mail/src/main/java/com/fsck/k9/controller/MessagingController.java @@ -42,6 +42,8 @@ import android.text.style.TextAppearanceSpan; import android.util.Log; import com.fsck.k9.Account; +import com.fsck.k9.Account.DeletePolicy; +import com.fsck.k9.Account.Expunge; import com.fsck.k9.AccountStats; import com.fsck.k9.K9; import com.fsck.k9.K9.NotificationHideSubject; @@ -1007,7 +1009,7 @@ public class MessagingController implements Runnable { Log.v(K9.LOG_TAG, "SYNC: About to open remote folder " + folder); remoteFolder.open(Folder.OPEN_MODE_RW); - if (Account.EXPUNGE_ON_POLL.equals(account.getExpungePolicy())) { + if (Expunge.EXPUNGE_ON_POLL == account.getExpungePolicy()) { if (K9.DEBUG) Log.d(K9.LOG_TAG, "SYNC: Expunging folder " + account.getDescription() + ":" + folder); remoteFolder.expunge(); @@ -2124,7 +2126,7 @@ public class MessagingController implements Runnable { } if (remoteDate != null) { remoteMessage.setFlag(Flag.DELETED, true); - if (Account.EXPUNGE_IMMEDIATELY.equals(account.getExpungePolicy())) { + if (Expunge.EXPUNGE_IMMEDIATELY == account.getExpungePolicy()) { remoteFolder.expunge(); } } @@ -2301,7 +2303,7 @@ public class MessagingController implements Runnable { remoteUidMap = remoteSrcFolder.moveMessages(messages, remoteDestFolder); } } - if (!isCopy && Account.EXPUNGE_IMMEDIATELY.equals(account.getExpungePolicy())) { + if (!isCopy && Expunge.EXPUNGE_IMMEDIATELY == account.getExpungePolicy()) { if (K9.DEBUG) Log.i(K9.LOG_TAG, "processingPendingMoveOrCopy expunging folder " + account.getDescription() + ":" + srcFolder); @@ -4088,14 +4090,14 @@ public class MessagingController implements Runnable { queuePendingCommand(account, command); } processPendingCommands(account); - } else if (account.getDeletePolicy() == Account.DELETE_POLICY_ON_DELETE) { + } else if (account.getDeletePolicy() == DeletePolicy.ON_DELETE) { if (folder.equals(account.getTrashFolderName())) { queueSetFlag(account, folder, Boolean.toString(true), Flag.DELETED.toString(), uids); } else { queueMoveOrCopy(account, folder, account.getTrashFolderName(), false, uids, uidMap); } processPendingCommands(account); - } else if (account.getDeletePolicy() == Account.DELETE_POLICY_MARK_AS_READ) { + } else if (account.getDeletePolicy() == DeletePolicy.MARK_AS_READ) { queueSetFlag(account, folder, Boolean.toString(true), Flag.SEEN.toString(), uids); processPendingCommands(account); } else { @@ -4133,7 +4135,7 @@ public class MessagingController implements Runnable { if (remoteFolder.exists()) { remoteFolder.open(Folder.OPEN_MODE_RW); remoteFolder.setFlags(Collections.singleton(Flag.DELETED), true); - if (Account.EXPUNGE_IMMEDIATELY.equals(account.getExpungePolicy())) { + if (Expunge.EXPUNGE_IMMEDIATELY == account.getExpungePolicy()) { remoteFolder.expunge(); } diff --git a/k9mail/src/main/java/com/fsck/k9/preferences/AccountSettings.java b/k9mail/src/main/java/com/fsck/k9/preferences/AccountSettings.java index 6bdcb4699..fd63c4d8f 100644 --- a/k9mail/src/main/java/com/fsck/k9/preferences/AccountSettings.java +++ b/k9mail/src/main/java/com/fsck/k9/preferences/AccountSettings.java @@ -9,10 +9,16 @@ import java.util.TreeMap; import android.content.SharedPreferences; import com.fsck.k9.Account; +import com.fsck.k9.Account.DeletePolicy; +import com.fsck.k9.Account.Expunge; +import com.fsck.k9.Account.FolderMode; +import com.fsck.k9.Account.MessageFormat; +import com.fsck.k9.Account.QuoteStyle; +import com.fsck.k9.Account.Searchable; +import com.fsck.k9.Account.ShowPictures; import com.fsck.k9.Account.SortType; import com.fsck.k9.K9; import com.fsck.k9.R; -import com.fsck.k9.Account.FolderMode; import com.fsck.k9.mailstore.StorageManager; import com.fsck.k9.preferences.Settings.*; @@ -56,7 +62,7 @@ public class AccountSettings { new V(1, new BooleanSetting(Account.DEFAULT_QUOTED_TEXT_SHOWN)) )); s.put("deletePolicy", Settings.versions( - new V(1, new DeletePolicySetting(Account.DELETE_POLICY_NEVER)) + new V(1, new DeletePolicySetting(DeletePolicy.NEVER)) )); s.put("displayCount", Settings.versions( new V(1, new IntegerResourceSetting(K9.DEFAULT_VISIBLE_LIMIT, @@ -66,7 +72,7 @@ public class AccountSettings { new V(1, new StringSetting("Drafts")) )); s.put("expungePolicy", Settings.versions( - new V(1, new StringResourceSetting(Account.EXPUNGE_IMMEDIATELY, + new V(1, new StringResourceSetting(Expunge.EXPUNGE_IMMEDIATELY.name(), R.array.account_setup_expunge_policy_values)) )); s.put("folderDisplayMode", Settings.versions( @@ -114,8 +120,8 @@ public class AccountSettings { R.array.account_settings_message_age_values)) )); s.put("messageFormat", Settings.versions( - new V(1, new EnumSetting( - Account.MessageFormat.class, Account.DEFAULT_MESSAGE_FORMAT)) + new V(1, new EnumSetting( + MessageFormat.class, Account.DEFAULT_MESSAGE_FORMAT)) )); s.put("messageFormatAuto", Settings.versions( new V(2, new BooleanSetting(Account.DEFAULT_MESSAGE_FORMAT_AUTO)) @@ -142,8 +148,8 @@ public class AccountSettings { new V(1, new StringSetting(Account.DEFAULT_QUOTE_PREFIX)) )); s.put("quoteStyle", Settings.versions( - new V(1, new EnumSetting( - Account.QuoteStyle.class, Account.DEFAULT_QUOTE_STYLE)) + new V(1, new EnumSetting( + QuoteStyle.class, Account.DEFAULT_QUOTE_STYLE)) )); s.put("replyAfterQuote", Settings.versions( new V(1, new BooleanSetting(Account.DEFAULT_REPLY_AFTER_QUOTE)) @@ -155,8 +161,8 @@ public class AccountSettings { new V(1, new RingtoneSetting("content://settings/system/notification_sound")) )); s.put("searchableFolders", Settings.versions( - new V(1, new EnumSetting( - Account.Searchable.class, Account.Searchable.ALL)) + new V(1, new EnumSetting( + Searchable.class, Searchable.ALL)) )); s.put("sentFolderName", Settings.versions( new V(1, new StringSetting("Sent")) @@ -168,8 +174,8 @@ public class AccountSettings { new V(9, new BooleanSetting(Account.DEFAULT_SORT_ASCENDING)) )); s.put("showPicturesEnum", Settings.versions( - new V(1, new EnumSetting( - Account.ShowPictures.class, Account.ShowPictures.NEVER)) + new V(1, new EnumSetting( + ShowPictures.class, ShowPictures.NEVER)) )); s.put("signatureBeforeQuotedText", Settings.versions( new V(1, new BooleanSetting(false)) @@ -363,18 +369,15 @@ public class AccountSettings { } } - /** - * The delete policy setting. - */ public static class DeletePolicySetting extends PseudoEnumSetting { private Map mMapping; - public DeletePolicySetting(int defaultValue) { + public DeletePolicySetting(DeletePolicy defaultValue) { super(defaultValue); Map mapping = new HashMap(); - mapping.put(Account.DELETE_POLICY_NEVER, "NEVER"); - mapping.put(Account.DELETE_POLICY_ON_DELETE, "DELETE"); - mapping.put(Account.DELETE_POLICY_MARK_AS_READ, "MARK_AS_READ"); + mapping.put(DeletePolicy.NEVER.setting, "NEVER"); + mapping.put(DeletePolicy.ON_DELETE.setting, "DELETE"); + mapping.put(DeletePolicy.MARK_AS_READ.setting, "MARK_AS_READ"); mMapping = Collections.unmodifiableMap(mapping); }