From ff6e1f6c85815e2d83adbe0af30a723f7b7db8eb Mon Sep 17 00:00:00 2001 From: Srinath Warrier Date: Sun, 26 Feb 2012 14:56:46 +0530 Subject: [PATCH 1/3] Create default sort setting by preference --- res/values/arrays.xml | 18 +++++++++ res/values/strings.xml | 4 ++ res/xml/account_settings_preferences.xml | 15 ++++++++ src/com/fsck/k9/Account.java | 37 +++++++++++++++++++ src/com/fsck/k9/activity/MessageList.java | 6 ++- .../k9/activity/setup/AccountSettings.java | 24 ++++++++++++ .../k9/controller/MessagingController.java | 2 +- .../fsck/k9/preferences/AccountSettings.java | 7 ++++ 8 files changed, 110 insertions(+), 3 deletions(-) diff --git a/res/values/arrays.xml b/res/values/arrays.xml index 8608cb367..cc96d658c 100644 --- a/res/values/arrays.xml +++ b/res/values/arrays.xml @@ -149,6 +149,24 @@ NOT_SECOND_CLASS + + @string/sort_by_date + @string/sort_by_subject + @string/sort_by_sender + @string/sort_by_unread + @string/sort_by_flag + @string/sort_by_attach + + + + SORT_DATE + SORT_SUBJECT + SORT_SENDER + SORT_UNREAD + SORT_FLAGGED + SORT_ATTACHMENT + + @string/account_settings_show_pictures_never @string/account_settings_show_pictures_only_from_contacts diff --git a/res/values/strings.xml b/res/values/strings.xml index 51ea0c50f..a1e668f7d 100644 --- a/res/values/strings.xml +++ b/res/values/strings.xml @@ -553,6 +553,10 @@ Welcome to K-9 Mail setup. K-9 is an open source mail client for Android origin Enable refile buttons Show the Archive, Move, and Spam buttons. + Default Sort Type + Sort order + Sort in ascending order + Always show images No From contacts diff --git a/res/xml/account_settings_preferences.xml b/res/xml/account_settings_preferences.xml index 9fa5a11a6..0356280ed 100644 --- a/res/xml/account_settings_preferences.xml +++ b/res/xml/account_settings_preferences.xml @@ -56,6 +56,21 @@ android:title="@string/account_settings_color_label" android:summary="@string/account_settings_color_summary" /> + + + + @@ -121,6 +125,8 @@ public class Account implements BaseAccount { private boolean mSaveAllHeaders; private boolean mPushPollOnConnect; private boolean mNotifySync; + private SORT_TYPE mSortType; + private boolean mSortAscending; private ShowPictures mShowPictures; private boolean mEnableMoveButtons; private boolean mIsSignatureBeforeQuotedText; @@ -210,6 +216,8 @@ public class Account implements BaseAccount { mFolderSyncMode = FolderMode.FIRST_CLASS; mFolderPushMode = FolderMode.FIRST_CLASS; mFolderTargetMode = FolderMode.NOT_SECOND_CLASS; + mSortType = DEFAULT_SORT_TYPE; + mSortAscending = DEFAULT_SORT_ASCENDING; mShowPictures = ShowPictures.NEVER; mEnableMoveButtons = false; mIsSignatureBeforeQuotedText = false; @@ -331,6 +339,15 @@ public class Account implements BaseAccount { (random.nextInt(0x70) * 0xffff) + 0xff000000); + try { + mSortType = SORT_TYPE.valueOf(prefs.getString(mUuid + ".sortTypeEnum", + SORT_TYPE.SORT_DATE.name())); + } catch (Exception e) { + mSortType = SORT_TYPE.SORT_DATE; + } + + mSortAscending = prefs.getBoolean(mUuid + ".sortAscending", false); + try { mShowPictures = ShowPictures.valueOf(prefs.getString(mUuid + ".showPicturesEnum", ShowPictures.NEVER.name())); @@ -463,6 +480,8 @@ public class Account implements BaseAccount { editor.remove(mUuid + ".messageFormatAuto"); editor.remove(mUuid + ".quoteStyle"); editor.remove(mUuid + ".quotePrefix"); + editor.remove(mUuid + ".sortTypeEnum"); + editor.remove(mUuid + ".sortAscending"); editor.remove(mUuid + ".showPicturesEnum"); editor.remove(mUuid + ".replyAfterQuote"); editor.remove(mUuid + ".stripSignature"); @@ -595,6 +614,8 @@ public class Account implements BaseAccount { editor.putString(mUuid + ".spamFolderName", mSpamFolderName); editor.putString(mUuid + ".autoExpandFolderName", mAutoExpandFolderName); editor.putInt(mUuid + ".accountNumber", mAccountNumber); + editor.putString(mUuid + ".sortTypeEnum", mSortType.name()); + editor.putBoolean(mUuid + ".sortAscending", mSortAscending); editor.putString(mUuid + ".showPicturesEnum", mShowPictures.name()); editor.putBoolean(mUuid + ".enableMoveButtons", mEnableMoveButtons); editor.putString(mUuid + ".folderDisplayMode", mFolderDisplayMode.name()); @@ -1000,6 +1021,22 @@ public class Account implements BaseAccount { this.mNotifySync = showOngoing; } + public synchronized SORT_TYPE getSortType() { + return mSortType; + } + + public synchronized void setSortType(SORT_TYPE sortType) { + mSortType = sortType; + } + + public synchronized boolean isSortAscending() { + return mSortAscending; + } + + public synchronized void setSortAscending(boolean sortAscending) { + mSortAscending = sortAscending; + } + public synchronized ShowPictures getShowPictures() { return mShowPictures; } diff --git a/src/com/fsck/k9/activity/MessageList.java b/src/com/fsck/k9/activity/MessageList.java index f874267f9..d2238a27e 100644 --- a/src/com/fsck/k9/activity/MessageList.java +++ b/src/com/fsck/k9/activity/MessageList.java @@ -809,8 +809,10 @@ public class MessageList mStars = K9.messageListStars(); mCheckboxes = K9.messageListCheckboxes(); - sortType = mController.getSortType(); - sortAscending = mController.isSortAscending(sortType); + sortType = mAccount.getSortType(); + mController.setSortType(sortType); + sortAscending = mAccount.isSortAscending(); + mController.setSortAscending(sortType, sortAscending); sortDateAscending = mController.isSortAscending(SORT_TYPE.SORT_DATE); mController.addListener(mAdapter.mListener); diff --git a/src/com/fsck/k9/activity/setup/AccountSettings.java b/src/com/fsck/k9/activity/setup/AccountSettings.java index 9ac8f7058..140fb0f9c 100644 --- a/src/com/fsck/k9/activity/setup/AccountSettings.java +++ b/src/com/fsck/k9/activity/setup/AccountSettings.java @@ -28,6 +28,7 @@ import com.fsck.k9.activity.ChooseIdentity; import com.fsck.k9.activity.ColorPickerDialog; import com.fsck.k9.activity.K9PreferenceActivity; import com.fsck.k9.activity.ManageIdentities; +import com.fsck.k9.controller.MessagingController.SORT_TYPE; import com.fsck.k9.crypto.Apg; import com.fsck.k9.mail.Store; import com.fsck.k9.service.MailService; @@ -53,6 +54,8 @@ public class AccountSettings extends K9PreferenceActivity { private static final String PREFERENCE_FREQUENCY = "account_check_frequency"; private static final String PREFERENCE_DISPLAY_COUNT = "account_display_count"; private static final String PREFERENCE_DEFAULT = "account_default"; + private static final String PREFERENCE_SORT_TYPE = "sort_type_enum"; + private static final String PREFERENCE_SORT_ASCENDING = "sort_ascending"; private static final String PREFERENCE_SHOW_PICTURES = "show_pictures_enum"; private static final String PREFERENCE_ENABLE_MOVE_BUTTONS = "enable_move_buttons"; private static final String PREFERENCE_NOTIFY = "account_notify"; @@ -121,6 +124,8 @@ public class AccountSettings extends K9PreferenceActivity { private CheckBoxPreference mAccountDefault; private CheckBoxPreference mAccountNotify; private CheckBoxPreference mAccountNotifySelf; + private ListPreference mAccountSortType; + private CheckBoxPreference mAccountSortAscending; private ListPreference mAccountShowPictures; private CheckBoxPreference mAccountEnableMoveButtons; private CheckBoxPreference mAccountNotifySync; @@ -427,6 +432,22 @@ public class AccountSettings extends K9PreferenceActivity { mAccountEnableMoveButtons.setEnabled(mIsMoveCapable); mAccountEnableMoveButtons.setChecked(mAccount.getEnableMoveButtons()); + mAccountSortType = (ListPreference) findPreference(PREFERENCE_SORT_TYPE); + mAccountSortType.setValue("" + mAccount.getSortType()); + mAccountSortType.setSummary(mAccountSortType.getEntry()); + mAccountSortType.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() { + public boolean onPreferenceChange(Preference preference, Object newValue) { + final String summary = newValue.toString(); + int index = mAccountSortType.findIndexOfValue(summary); + mAccountSortType.setSummary(mAccountSortType.getEntries()[index]); + mAccountSortType.setValue(summary); + return false; + } + }); + + mAccountSortAscending = (CheckBoxPreference) findPreference(PREFERENCE_SORT_ASCENDING); + mAccountSortAscending.setChecked(mAccount.isSortAscending()); + mAccountShowPictures = (ListPreference) findPreference(PREFERENCE_SHOW_PICTURES); mAccountShowPictures.setValue("" + mAccount.getShowPictures()); mAccountShowPictures.setSummary(mAccountShowPictures.getEntry()); @@ -750,6 +771,9 @@ public class AccountSettings extends K9PreferenceActivity { } } + mAccount.setSortType(SORT_TYPE.valueOf(mAccountSortType.getValue())); + mAccount.setSortAscending(mAccountSortAscending.isChecked()); + mAccount.setShowPictures(Account.ShowPictures.valueOf(mAccountShowPictures.getValue())); if (mIsPushCapable) { diff --git a/src/com/fsck/k9/controller/MessagingController.java b/src/com/fsck/k9/controller/MessagingController.java index 1b2b47a6b..c23a02162 100644 --- a/src/com/fsck/k9/controller/MessagingController.java +++ b/src/com/fsck/k9/controller/MessagingController.java @@ -173,7 +173,7 @@ public class MessagingController implements Runnable { } } - private SORT_TYPE sortType = SORT_TYPE.SORT_DATE; + private SORT_TYPE sortType = Account.DEFAULT_SORT_TYPE; private MessagingListener checkMailListener = null; diff --git a/src/com/fsck/k9/preferences/AccountSettings.java b/src/com/fsck/k9/preferences/AccountSettings.java index fdc311820..67c55c0cf 100644 --- a/src/com/fsck/k9/preferences/AccountSettings.java +++ b/src/com/fsck/k9/preferences/AccountSettings.java @@ -12,6 +12,7 @@ import com.fsck.k9.Account; import com.fsck.k9.K9; import com.fsck.k9.R; import com.fsck.k9.Account.FolderMode; +import com.fsck.k9.controller.MessagingController.SORT_TYPE; import com.fsck.k9.crypto.Apg; import com.fsck.k9.mail.store.StorageManager; import com.fsck.k9.preferences.Settings.*; @@ -156,6 +157,12 @@ public class AccountSettings { s.put("sentFolderName", Settings.versions( new V(1, new StringSetting("Sent")) )); + s.put("sortTypeEnum", Settings.versions( + new V(1, new EnumSetting(SORT_TYPE.class, Account.DEFAULT_SORT_TYPE)) + )); + s.put("sortAscending", Settings.versions( + new V(1, new BooleanSetting(Account.DEFAULT_SORT_ASCENDING)) + )); s.put("showPicturesEnum", Settings.versions( new V(1, new EnumSetting(Account.ShowPictures.class, Account.ShowPictures.NEVER)) )); From 3ebd3c1fc2f82c924c175d47763e505233ad3f86 Mon Sep 17 00:00:00 2001 From: Srinath Warrier Date: Mon, 12 Mar 2012 22:04:10 +0530 Subject: [PATCH 2/3] Create implicit sort remembering setting --- res/values/arrays.xml | 18 -------------- res/values/strings.xml | 4 ---- res/xml/account_settings_preferences.xml | 15 ------------ src/com/fsck/k9/activity/MessageList.java | 9 ++++++- .../k9/activity/setup/AccountSettings.java | 24 ------------------- 5 files changed, 8 insertions(+), 62 deletions(-) diff --git a/res/values/arrays.xml b/res/values/arrays.xml index cc96d658c..8608cb367 100644 --- a/res/values/arrays.xml +++ b/res/values/arrays.xml @@ -149,24 +149,6 @@ NOT_SECOND_CLASS - - @string/sort_by_date - @string/sort_by_subject - @string/sort_by_sender - @string/sort_by_unread - @string/sort_by_flag - @string/sort_by_attach - - - - SORT_DATE - SORT_SUBJECT - SORT_SENDER - SORT_UNREAD - SORT_FLAGGED - SORT_ATTACHMENT - - @string/account_settings_show_pictures_never @string/account_settings_show_pictures_only_from_contacts diff --git a/res/values/strings.xml b/res/values/strings.xml index a1e668f7d..51ea0c50f 100644 --- a/res/values/strings.xml +++ b/res/values/strings.xml @@ -553,10 +553,6 @@ Welcome to K-9 Mail setup. K-9 is an open source mail client for Android origin Enable refile buttons Show the Archive, Move, and Spam buttons. - Default Sort Type - Sort order - Sort in ascending order - Always show images No From contacts diff --git a/res/xml/account_settings_preferences.xml b/res/xml/account_settings_preferences.xml index 0356280ed..9fa5a11a6 100644 --- a/res/xml/account_settings_preferences.xml +++ b/res/xml/account_settings_preferences.xml @@ -56,21 +56,6 @@ android:title="@string/account_settings_color_label" android:summary="@string/account_settings_color_summary" /> - - - - Date: Mon, 12 Mar 2012 22:55:31 +0530 Subject: [PATCH 3/3] Create implicit sort remembering setting2(minor indentation error) --- src/com/fsck/k9/activity/MessageList.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/com/fsck/k9/activity/MessageList.java b/src/com/fsck/k9/activity/MessageList.java index c91565e16..9eae5ab22 100644 --- a/src/com/fsck/k9/activity/MessageList.java +++ b/src/com/fsck/k9/activity/MessageList.java @@ -1195,8 +1195,7 @@ public class MessageList mAccount.setSortType(sortType); mAccount.setSortAscending(sortAscending); mAccount.save(Preferences.getPreferences(this)); - - reSort(); + reSort(); } }