diff --git a/src/com/fsck/k9/Account.java b/src/com/fsck/k9/Account.java index 99af120fa..57305cf04 100644 --- a/src/com/fsck/k9/Account.java +++ b/src/com/fsck/k9/Account.java @@ -7,7 +7,6 @@ import android.net.ConnectivityManager; import android.net.Uri; import android.util.Log; -import com.fsck.k9.controller.MessagingController.SortType; import com.fsck.k9.crypto.Apg; import com.fsck.k9.crypto.CryptoProvider; import com.fsck.k9.helper.Utility; @@ -25,6 +24,7 @@ import java.util.Arrays; import java.util.Calendar; import java.util.Collections; import java.util.Date; +import java.util.HashMap; import java.util.LinkedList; import java.util.List; import java.util.Map; @@ -78,6 +78,37 @@ public class Account implements BaseAccount { public static final String IDENTITY_EMAIL_KEY = "email"; public static final String IDENTITY_DESCRIPTION_KEY = "description"; + public enum SortType { + SORT_DATE(R.string.sort_earliest_first, R.string.sort_latest_first, false), + SORT_ARRIVAL(R.string.sort_earliest_first, R.string.sort_latest_first, false), + SORT_SUBJECT(R.string.sort_subject_alpha, R.string.sort_subject_re_alpha, true), + SORT_SENDER(R.string.sort_sender_alpha, R.string.sort_sender_re_alpha, true), + SORT_UNREAD(R.string.sort_unread_first, R.string.sort_unread_last, true), + SORT_FLAGGED(R.string.sort_flagged_first, R.string.sort_flagged_last, true), + SORT_ATTACHMENT(R.string.sort_attach_first, R.string.sort_unattached_first, true); + + private int ascendingToast; + private int descendingToast; + private boolean defaultAscending; + + SortType(int ascending, int descending, boolean ndefaultAscending) { + ascendingToast = ascending; + descendingToast = descending; + defaultAscending = ndefaultAscending; + } + + public int getToast(boolean ascending) { + if (ascending) { + return ascendingToast; + } else { + return descendingToast; + } + } + public boolean isDefaultAscending() { + return defaultAscending; + } + } + public static final SortType DEFAULT_SORT_TYPE = SortType.SORT_DATE; public static final boolean DEFAULT_SORT_ASCENDING = false; @@ -126,7 +157,7 @@ public class Account implements BaseAccount { private boolean mPushPollOnConnect; private boolean mNotifySync; private SortType mSortType; - private boolean mSortAscending; + private HashMap mSortAscending = new HashMap(); private ShowPictures mShowPictures; private boolean mEnableMoveButtons; private boolean mIsSignatureBeforeQuotedText; @@ -218,7 +249,7 @@ public class Account implements BaseAccount { mFolderPushMode = FolderMode.FIRST_CLASS; mFolderTargetMode = FolderMode.NOT_SECOND_CLASS; mSortType = DEFAULT_SORT_TYPE; - mSortAscending = DEFAULT_SORT_ASCENDING; + mSortAscending.put(DEFAULT_SORT_TYPE, DEFAULT_SORT_ASCENDING); mShowPictures = ShowPictures.NEVER; mEnableMoveButtons = false; mIsSignatureBeforeQuotedText = false; @@ -348,7 +379,7 @@ public class Account implements BaseAccount { mSortType = SortType.SORT_DATE; } - mSortAscending = prefs.getBoolean(mUuid + ".sortAscending", false); + mSortAscending.put(mSortType, prefs.getBoolean(mUuid + ".sortAscending", false)); try { mShowPictures = ShowPictures.valueOf(prefs.getString(mUuid + ".showPicturesEnum", @@ -619,7 +650,7 @@ public class Account implements BaseAccount { editor.putString(mUuid + ".autoExpandFolderName", mAutoExpandFolderName); editor.putInt(mUuid + ".accountNumber", mAccountNumber); editor.putString(mUuid + ".sortTypeEnum", mSortType.name()); - editor.putBoolean(mUuid + ".sortAscending", mSortAscending); + editor.putBoolean(mUuid + ".sortAscending", mSortAscending.get(mSortType)); editor.putString(mUuid + ".showPicturesEnum", mShowPictures.name()); editor.putBoolean(mUuid + ".enableMoveButtons", mEnableMoveButtons); editor.putString(mUuid + ".folderDisplayMode", mFolderDisplayMode.name()); @@ -1042,12 +1073,15 @@ public class Account implements BaseAccount { mSortType = sortType; } - public synchronized boolean isSortAscending() { - return mSortAscending; + public synchronized boolean isSortAscending(SortType sortType) { + if (mSortAscending.get(sortType) == null) { + mSortAscending.put(sortType, sortType.isDefaultAscending()); + } + return mSortAscending.get(sortType); } - public synchronized void setSortAscending(boolean sortAscending) { - mSortAscending = sortAscending; + public synchronized void setSortAscending(SortType sortType, boolean sortAscending) { + mSortAscending.put(sortType, sortAscending); } public synchronized ShowPictures getShowPictures() { diff --git a/src/com/fsck/k9/activity/MessageList.java b/src/com/fsck/k9/activity/MessageList.java index 4eabb8721..ddfd7bd7f 100644 --- a/src/com/fsck/k9/activity/MessageList.java +++ b/src/com/fsck/k9/activity/MessageList.java @@ -51,6 +51,7 @@ import android.widget.TextView; import android.widget.Toast; import com.fsck.k9.Account; +import com.fsck.k9.Account.SortType; import com.fsck.k9.AccountStats; import com.fsck.k9.BaseAccount; import com.fsck.k9.FontSizes; @@ -63,7 +64,6 @@ import com.fsck.k9.activity.setup.AccountSettings; import com.fsck.k9.activity.setup.FolderSettings; import com.fsck.k9.activity.setup.Prefs; import com.fsck.k9.controller.MessagingController; -import com.fsck.k9.controller.MessagingController.SortType; import com.fsck.k9.controller.MessagingListener; import com.fsck.k9.helper.MessageHelper; import com.fsck.k9.helper.Utility; @@ -292,10 +292,9 @@ public class MessageList private MessageListHandler mHandler = new MessageListHandler(); - private SortType sortType = SortType.SORT_DATE; - - private boolean sortAscending = true; - private boolean sortDateAscending = false; + private SortType mSortType = SortType.SORT_DATE; + private boolean mSortAscending = true; + private boolean mSortDateAscending = false; private boolean mStars = true; private boolean mCheckboxes = true; @@ -462,8 +461,8 @@ public class MessageList { // add the specified comparator - final Comparator comparator = SORT_COMPARATORS.get(sortType); - if (sortAscending) { + final Comparator comparator = SORT_COMPARATORS.get(mSortType); + if (mSortAscending) { chain.add(comparator); } else { chain.add(new ReverseComparator(comparator)); @@ -472,9 +471,9 @@ public class MessageList { // add the date comparator if not already specified - if (sortType != SortType.SORT_DATE && sortType != SortType.SORT_ARRIVAL) { + if (mSortType != SortType.SORT_DATE && mSortType != SortType.SORT_ARRIVAL) { final Comparator comparator = SORT_COMPARATORS.get(SortType.SORT_DATE); - if (sortDateAscending) { + if (mSortDateAscending) { chain.add(comparator); } else { chain.add(new ReverseComparator(comparator)); @@ -821,11 +820,9 @@ public class MessageList mStars = K9.messageListStars(); mCheckboxes = K9.messageListCheckboxes(); - sortType = mAccount.getSortType(); - mController.setSortType(sortType); - sortAscending = mAccount.isSortAscending(); - mController.setSortAscending(sortType, sortAscending); - sortDateAscending = mController.isSortAscending(SortType.SORT_DATE); + mSortType = mAccount.getSortType(); + mSortAscending = mAccount.isSortAscending(mSortType); + mSortDateAscending = mAccount.isSortAscending(SortType.SORT_DATE); mController.addListener(mAdapter.mListener); @@ -1209,24 +1206,22 @@ public class MessageList AccountSettings.actionSettings(this, mAccount); } - private void changeSort(SortType newSortType) { - if (sortType == newSortType) { + private void changeSort(SortType sortType) { + if (mSortType == sortType) { onToggleSortAscending(); } else { - sortType = newSortType; - mController.setSortType(sortType); - sortAscending = mController.isSortAscending(sortType); - sortDateAscending = mController.isSortAscending(SortType.SORT_DATE); + mSortType = sortType; + mAccount.setSortType(mSortType); + mSortAscending = mAccount.isSortAscending(mSortType); + mSortDateAscending = mAccount.isSortAscending(SortType.SORT_DATE); - mAccount.setSortType(sortType); - mAccount.setSortAscending(sortAscending); mAccount.save(Preferences.getPreferences(this)); reSort(); } } private void reSort() { - int toastString = sortType.getToast(sortAscending); + int toastString = mSortType.getToast(mSortAscending); Toast toast = Toast.makeText(this, toastString, Toast.LENGTH_SHORT); toast.show(); @@ -1239,7 +1234,7 @@ public class MessageList int curIndex = 0; for (int i = 0; i < sorts.length; i++) { - if (sorts[i] == sortType) { + if (sorts[i] == mSortType) { curIndex = i; break; } @@ -1255,14 +1250,10 @@ public class MessageList } private void onToggleSortAscending() { - mController.setSortAscending(sortType, !sortAscending); - - sortAscending = mController.isSortAscending(sortType); - sortDateAscending = mController.isSortAscending(SortType.SORT_DATE); - - mAccount.setSortAscending( sortAscending); + mSortAscending = !mSortAscending; + mAccount.setSortAscending(mSortType, mSortAscending); + mSortDateAscending = mAccount.isSortAscending(SortType.SORT_DATE); 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 328c3844c..538aa0fdf 100644 --- a/src/com/fsck/k9/controller/MessagingController.java +++ b/src/com/fsck/k9/controller/MessagingController.java @@ -136,47 +136,12 @@ public class MessagingController implements Runnable { private Thread mThread; private Set mListeners = new CopyOnWriteArraySet(); - private HashMap sortAscending = new HashMap(); - private final ConcurrentHashMap sendCount = new ConcurrentHashMap(); ConcurrentHashMap pushers = new ConcurrentHashMap(); private final ExecutorService threadPool = Executors.newCachedThreadPool(); - public enum SortType { - SORT_DATE(R.string.sort_earliest_first, R.string.sort_latest_first, false), - SORT_ARRIVAL(R.string.sort_earliest_first, R.string.sort_latest_first, false), - SORT_SUBJECT(R.string.sort_subject_alpha, R.string.sort_subject_re_alpha, true), - SORT_SENDER(R.string.sort_sender_alpha, R.string.sort_sender_re_alpha, true), - SORT_UNREAD(R.string.sort_unread_first, R.string.sort_unread_last, true), - SORT_FLAGGED(R.string.sort_flagged_first, R.string.sort_flagged_last, true), - SORT_ATTACHMENT(R.string.sort_attach_first, R.string.sort_unattached_first, true); - - private int ascendingToast; - private int descendingToast; - private boolean defaultAscending; - - SortType(int ascending, int descending, boolean ndefaultAscending) { - ascendingToast = ascending; - descendingToast = descending; - defaultAscending = ndefaultAscending; - } - - public int getToast(boolean ascending) { - if (ascending) { - return ascendingToast; - } else { - return descendingToast; - } - } - public boolean isDefaultAscending() { - return defaultAscending; - } - } - - private SortType sortType = Account.DEFAULT_SORT_TYPE; - private MessagingListener checkMailListener = null; private MemorizingListener memorizingListener = new MemorizingListener(); @@ -4362,25 +4327,6 @@ public class MessagingController implements Runnable { } } - public SortType getSortType() { - return sortType; - } - - public void setSortType(SortType sortType) { - this.sortType = sortType; - } - - public boolean isSortAscending(SortType sortType) { - Boolean sortAsc = sortAscending.get(sortType); - if (sortAsc == null) { - return sortType.isDefaultAscending(); - } else return sortAsc; - } - - public void setSortAscending(SortType sortType, boolean nsortAscending) { - sortAscending.put(sortType, nsortAscending); - } - public Collection getPushers() { return pushers.values(); } diff --git a/src/com/fsck/k9/preferences/AccountSettings.java b/src/com/fsck/k9/preferences/AccountSettings.java index 685d4b315..2374897f7 100644 --- a/src/com/fsck/k9/preferences/AccountSettings.java +++ b/src/com/fsck/k9/preferences/AccountSettings.java @@ -9,10 +9,10 @@ import java.util.TreeMap; import android.content.SharedPreferences; import com.fsck.k9.Account; +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.controller.MessagingController.SortType; import com.fsck.k9.crypto.Apg; import com.fsck.k9.mail.store.StorageManager; import com.fsck.k9.preferences.Settings.*;