diff --git a/src/com/fsck/k9/Account.java b/src/com/fsck/k9/Account.java index f2d9ebf0d..c1490ad7a 100644 --- a/src/com/fsck/k9/Account.java +++ b/src/com/fsck/k9/Account.java @@ -7,6 +7,7 @@ import android.net.ConnectivityManager; import android.net.Uri; import android.util.Log; +import com.fsck.k9.controller.MessagingController.SORT_TYPE; import com.fsck.k9.crypto.Apg; import com.fsck.k9.crypto.CryptoProvider; import com.fsck.k9.helper.Utility; @@ -77,6 +78,9 @@ public class Account implements BaseAccount { public static final String IDENTITY_EMAIL_KEY = "email"; public static final String IDENTITY_DESCRIPTION_KEY = "description"; + public static final SORT_TYPE DEFAULT_SORT_TYPE = SORT_TYPE.SORT_DATE; + public static final boolean DEFAULT_SORT_ASCENDING = false; + /** *
@@ -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;
@@ -211,6 +217,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;
@@ -333,6 +341,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()));
@@ -466,6 +483,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");
@@ -599,6 +618,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());
@@ -1013,6 +1034,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 822d6186b..6dffc6121 100644
--- a/src/com/fsck/k9/activity/MessageList.java
+++ b/src/com/fsck/k9/activity/MessageList.java
@@ -821,8 +821,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);
@@ -1209,12 +1211,18 @@ public class MessageList
 
     private void changeSort(SORT_TYPE newSortType) {
         if (sortType == newSortType) {
+            mAccount.setSortAscending( !(mController.isSortAscending(newSortType)  ));
+            mAccount.save(Preferences.getPreferences(this));
             onToggleSortAscending();
         } else {
             sortType = newSortType;
             mController.setSortType(sortType);
             sortAscending = mController.isSortAscending(sortType);
             sortDateAscending = mController.isSortAscending(SORT_TYPE.SORT_DATE);
+
+            mAccount.setSortType(sortType);
+            mAccount.setSortAscending(sortAscending);
+            mAccount.save(Preferences.getPreferences(this));
             reSort();
         }
     }
diff --git a/src/com/fsck/k9/controller/MessagingController.java b/src/com/fsck/k9/controller/MessagingController.java
index 090db17ac..6fa610556 100644
--- a/src/com/fsck/k9/controller/MessagingController.java
+++ b/src/com/fsck/k9/controller/MessagingController.java
@@ -175,7 +175,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 f2dcf3669..1b4a066df 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.*;
@@ -159,6 +160,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))
             ));