mirror of
https://github.com/moparisthebest/k-9
synced 2024-11-27 11:42:16 -05:00
refactored sorting
This commit is contained in:
parent
d6a1f2e95c
commit
539ab93bcb
@ -7,7 +7,6 @@ import android.net.ConnectivityManager;
|
|||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
|
||||||
import com.fsck.k9.controller.MessagingController.SortType;
|
|
||||||
import com.fsck.k9.crypto.Apg;
|
import com.fsck.k9.crypto.Apg;
|
||||||
import com.fsck.k9.crypto.CryptoProvider;
|
import com.fsck.k9.crypto.CryptoProvider;
|
||||||
import com.fsck.k9.helper.Utility;
|
import com.fsck.k9.helper.Utility;
|
||||||
@ -25,6 +24,7 @@ import java.util.Arrays;
|
|||||||
import java.util.Calendar;
|
import java.util.Calendar;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
|
import java.util.HashMap;
|
||||||
import java.util.LinkedList;
|
import java.util.LinkedList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
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_EMAIL_KEY = "email";
|
||||||
public static final String IDENTITY_DESCRIPTION_KEY = "description";
|
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 SortType DEFAULT_SORT_TYPE = SortType.SORT_DATE;
|
||||||
public static final boolean DEFAULT_SORT_ASCENDING = false;
|
public static final boolean DEFAULT_SORT_ASCENDING = false;
|
||||||
|
|
||||||
@ -126,7 +157,7 @@ public class Account implements BaseAccount {
|
|||||||
private boolean mPushPollOnConnect;
|
private boolean mPushPollOnConnect;
|
||||||
private boolean mNotifySync;
|
private boolean mNotifySync;
|
||||||
private SortType mSortType;
|
private SortType mSortType;
|
||||||
private boolean mSortAscending;
|
private HashMap<SortType, Boolean> mSortAscending = new HashMap<SortType, Boolean>();
|
||||||
private ShowPictures mShowPictures;
|
private ShowPictures mShowPictures;
|
||||||
private boolean mEnableMoveButtons;
|
private boolean mEnableMoveButtons;
|
||||||
private boolean mIsSignatureBeforeQuotedText;
|
private boolean mIsSignatureBeforeQuotedText;
|
||||||
@ -218,7 +249,7 @@ public class Account implements BaseAccount {
|
|||||||
mFolderPushMode = FolderMode.FIRST_CLASS;
|
mFolderPushMode = FolderMode.FIRST_CLASS;
|
||||||
mFolderTargetMode = FolderMode.NOT_SECOND_CLASS;
|
mFolderTargetMode = FolderMode.NOT_SECOND_CLASS;
|
||||||
mSortType = DEFAULT_SORT_TYPE;
|
mSortType = DEFAULT_SORT_TYPE;
|
||||||
mSortAscending = DEFAULT_SORT_ASCENDING;
|
mSortAscending.put(DEFAULT_SORT_TYPE, DEFAULT_SORT_ASCENDING);
|
||||||
mShowPictures = ShowPictures.NEVER;
|
mShowPictures = ShowPictures.NEVER;
|
||||||
mEnableMoveButtons = false;
|
mEnableMoveButtons = false;
|
||||||
mIsSignatureBeforeQuotedText = false;
|
mIsSignatureBeforeQuotedText = false;
|
||||||
@ -348,7 +379,7 @@ public class Account implements BaseAccount {
|
|||||||
mSortType = SortType.SORT_DATE;
|
mSortType = SortType.SORT_DATE;
|
||||||
}
|
}
|
||||||
|
|
||||||
mSortAscending = prefs.getBoolean(mUuid + ".sortAscending", false);
|
mSortAscending.put(mSortType, prefs.getBoolean(mUuid + ".sortAscending", false));
|
||||||
|
|
||||||
try {
|
try {
|
||||||
mShowPictures = ShowPictures.valueOf(prefs.getString(mUuid + ".showPicturesEnum",
|
mShowPictures = ShowPictures.valueOf(prefs.getString(mUuid + ".showPicturesEnum",
|
||||||
@ -619,7 +650,7 @@ public class Account implements BaseAccount {
|
|||||||
editor.putString(mUuid + ".autoExpandFolderName", mAutoExpandFolderName);
|
editor.putString(mUuid + ".autoExpandFolderName", mAutoExpandFolderName);
|
||||||
editor.putInt(mUuid + ".accountNumber", mAccountNumber);
|
editor.putInt(mUuid + ".accountNumber", mAccountNumber);
|
||||||
editor.putString(mUuid + ".sortTypeEnum", mSortType.name());
|
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.putString(mUuid + ".showPicturesEnum", mShowPictures.name());
|
||||||
editor.putBoolean(mUuid + ".enableMoveButtons", mEnableMoveButtons);
|
editor.putBoolean(mUuid + ".enableMoveButtons", mEnableMoveButtons);
|
||||||
editor.putString(mUuid + ".folderDisplayMode", mFolderDisplayMode.name());
|
editor.putString(mUuid + ".folderDisplayMode", mFolderDisplayMode.name());
|
||||||
@ -1042,12 +1073,15 @@ public class Account implements BaseAccount {
|
|||||||
mSortType = sortType;
|
mSortType = sortType;
|
||||||
}
|
}
|
||||||
|
|
||||||
public synchronized boolean isSortAscending() {
|
public synchronized boolean isSortAscending(SortType sortType) {
|
||||||
return mSortAscending;
|
if (mSortAscending.get(sortType) == null) {
|
||||||
|
mSortAscending.put(sortType, sortType.isDefaultAscending());
|
||||||
|
}
|
||||||
|
return mSortAscending.get(sortType);
|
||||||
}
|
}
|
||||||
|
|
||||||
public synchronized void setSortAscending(boolean sortAscending) {
|
public synchronized void setSortAscending(SortType sortType, boolean sortAscending) {
|
||||||
mSortAscending = sortAscending;
|
mSortAscending.put(sortType, sortAscending);
|
||||||
}
|
}
|
||||||
|
|
||||||
public synchronized ShowPictures getShowPictures() {
|
public synchronized ShowPictures getShowPictures() {
|
||||||
|
@ -51,6 +51,7 @@ import android.widget.TextView;
|
|||||||
import android.widget.Toast;
|
import android.widget.Toast;
|
||||||
|
|
||||||
import com.fsck.k9.Account;
|
import com.fsck.k9.Account;
|
||||||
|
import com.fsck.k9.Account.SortType;
|
||||||
import com.fsck.k9.AccountStats;
|
import com.fsck.k9.AccountStats;
|
||||||
import com.fsck.k9.BaseAccount;
|
import com.fsck.k9.BaseAccount;
|
||||||
import com.fsck.k9.FontSizes;
|
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.FolderSettings;
|
||||||
import com.fsck.k9.activity.setup.Prefs;
|
import com.fsck.k9.activity.setup.Prefs;
|
||||||
import com.fsck.k9.controller.MessagingController;
|
import com.fsck.k9.controller.MessagingController;
|
||||||
import com.fsck.k9.controller.MessagingController.SortType;
|
|
||||||
import com.fsck.k9.controller.MessagingListener;
|
import com.fsck.k9.controller.MessagingListener;
|
||||||
import com.fsck.k9.helper.MessageHelper;
|
import com.fsck.k9.helper.MessageHelper;
|
||||||
import com.fsck.k9.helper.Utility;
|
import com.fsck.k9.helper.Utility;
|
||||||
@ -292,10 +292,9 @@ public class MessageList
|
|||||||
|
|
||||||
private MessageListHandler mHandler = new MessageListHandler();
|
private MessageListHandler mHandler = new MessageListHandler();
|
||||||
|
|
||||||
private SortType sortType = SortType.SORT_DATE;
|
private SortType mSortType = SortType.SORT_DATE;
|
||||||
|
private boolean mSortAscending = true;
|
||||||
private boolean sortAscending = true;
|
private boolean mSortDateAscending = false;
|
||||||
private boolean sortDateAscending = false;
|
|
||||||
|
|
||||||
private boolean mStars = true;
|
private boolean mStars = true;
|
||||||
private boolean mCheckboxes = true;
|
private boolean mCheckboxes = true;
|
||||||
@ -462,8 +461,8 @@ public class MessageList
|
|||||||
|
|
||||||
{
|
{
|
||||||
// add the specified comparator
|
// add the specified comparator
|
||||||
final Comparator<MessageInfoHolder> comparator = SORT_COMPARATORS.get(sortType);
|
final Comparator<MessageInfoHolder> comparator = SORT_COMPARATORS.get(mSortType);
|
||||||
if (sortAscending) {
|
if (mSortAscending) {
|
||||||
chain.add(comparator);
|
chain.add(comparator);
|
||||||
} else {
|
} else {
|
||||||
chain.add(new ReverseComparator<MessageInfoHolder>(comparator));
|
chain.add(new ReverseComparator<MessageInfoHolder>(comparator));
|
||||||
@ -472,9 +471,9 @@ public class MessageList
|
|||||||
|
|
||||||
{
|
{
|
||||||
// add the date comparator if not already specified
|
// 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<MessageInfoHolder> comparator = SORT_COMPARATORS.get(SortType.SORT_DATE);
|
final Comparator<MessageInfoHolder> comparator = SORT_COMPARATORS.get(SortType.SORT_DATE);
|
||||||
if (sortDateAscending) {
|
if (mSortDateAscending) {
|
||||||
chain.add(comparator);
|
chain.add(comparator);
|
||||||
} else {
|
} else {
|
||||||
chain.add(new ReverseComparator<MessageInfoHolder>(comparator));
|
chain.add(new ReverseComparator<MessageInfoHolder>(comparator));
|
||||||
@ -821,11 +820,9 @@ public class MessageList
|
|||||||
mStars = K9.messageListStars();
|
mStars = K9.messageListStars();
|
||||||
mCheckboxes = K9.messageListCheckboxes();
|
mCheckboxes = K9.messageListCheckboxes();
|
||||||
|
|
||||||
sortType = mAccount.getSortType();
|
mSortType = mAccount.getSortType();
|
||||||
mController.setSortType(sortType);
|
mSortAscending = mAccount.isSortAscending(mSortType);
|
||||||
sortAscending = mAccount.isSortAscending();
|
mSortDateAscending = mAccount.isSortAscending(SortType.SORT_DATE);
|
||||||
mController.setSortAscending(sortType, sortAscending);
|
|
||||||
sortDateAscending = mController.isSortAscending(SortType.SORT_DATE);
|
|
||||||
|
|
||||||
mController.addListener(mAdapter.mListener);
|
mController.addListener(mAdapter.mListener);
|
||||||
|
|
||||||
@ -1209,24 +1206,22 @@ public class MessageList
|
|||||||
AccountSettings.actionSettings(this, mAccount);
|
AccountSettings.actionSettings(this, mAccount);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void changeSort(SortType newSortType) {
|
private void changeSort(SortType sortType) {
|
||||||
if (sortType == newSortType) {
|
if (mSortType == sortType) {
|
||||||
onToggleSortAscending();
|
onToggleSortAscending();
|
||||||
} else {
|
} else {
|
||||||
sortType = newSortType;
|
mSortType = sortType;
|
||||||
mController.setSortType(sortType);
|
mAccount.setSortType(mSortType);
|
||||||
sortAscending = mController.isSortAscending(sortType);
|
mSortAscending = mAccount.isSortAscending(mSortType);
|
||||||
sortDateAscending = mController.isSortAscending(SortType.SORT_DATE);
|
mSortDateAscending = mAccount.isSortAscending(SortType.SORT_DATE);
|
||||||
|
|
||||||
mAccount.setSortType(sortType);
|
|
||||||
mAccount.setSortAscending(sortAscending);
|
|
||||||
mAccount.save(Preferences.getPreferences(this));
|
mAccount.save(Preferences.getPreferences(this));
|
||||||
reSort();
|
reSort();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void reSort() {
|
private void reSort() {
|
||||||
int toastString = sortType.getToast(sortAscending);
|
int toastString = mSortType.getToast(mSortAscending);
|
||||||
|
|
||||||
Toast toast = Toast.makeText(this, toastString, Toast.LENGTH_SHORT);
|
Toast toast = Toast.makeText(this, toastString, Toast.LENGTH_SHORT);
|
||||||
toast.show();
|
toast.show();
|
||||||
@ -1239,7 +1234,7 @@ public class MessageList
|
|||||||
int curIndex = 0;
|
int curIndex = 0;
|
||||||
|
|
||||||
for (int i = 0; i < sorts.length; i++) {
|
for (int i = 0; i < sorts.length; i++) {
|
||||||
if (sorts[i] == sortType) {
|
if (sorts[i] == mSortType) {
|
||||||
curIndex = i;
|
curIndex = i;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -1255,14 +1250,10 @@ public class MessageList
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void onToggleSortAscending() {
|
private void onToggleSortAscending() {
|
||||||
mController.setSortAscending(sortType, !sortAscending);
|
mSortAscending = !mSortAscending;
|
||||||
|
mAccount.setSortAscending(mSortType, mSortAscending);
|
||||||
sortAscending = mController.isSortAscending(sortType);
|
mSortDateAscending = mAccount.isSortAscending(SortType.SORT_DATE);
|
||||||
sortDateAscending = mController.isSortAscending(SortType.SORT_DATE);
|
|
||||||
|
|
||||||
mAccount.setSortAscending( sortAscending);
|
|
||||||
mAccount.save(Preferences.getPreferences(this));
|
mAccount.save(Preferences.getPreferences(this));
|
||||||
|
|
||||||
reSort();
|
reSort();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -136,47 +136,12 @@ public class MessagingController implements Runnable {
|
|||||||
private Thread mThread;
|
private Thread mThread;
|
||||||
private Set<MessagingListener> mListeners = new CopyOnWriteArraySet<MessagingListener>();
|
private Set<MessagingListener> mListeners = new CopyOnWriteArraySet<MessagingListener>();
|
||||||
|
|
||||||
private HashMap<SortType, Boolean> sortAscending = new HashMap<SortType, Boolean>();
|
|
||||||
|
|
||||||
private final ConcurrentHashMap<String, AtomicInteger> sendCount = new ConcurrentHashMap<String, AtomicInteger>();
|
private final ConcurrentHashMap<String, AtomicInteger> sendCount = new ConcurrentHashMap<String, AtomicInteger>();
|
||||||
|
|
||||||
ConcurrentHashMap<Account, Pusher> pushers = new ConcurrentHashMap<Account, Pusher>();
|
ConcurrentHashMap<Account, Pusher> pushers = new ConcurrentHashMap<Account, Pusher>();
|
||||||
|
|
||||||
private final ExecutorService threadPool = Executors.newCachedThreadPool();
|
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 MessagingListener checkMailListener = null;
|
||||||
|
|
||||||
private MemorizingListener memorizingListener = new MemorizingListener();
|
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<Pusher> getPushers() {
|
public Collection<Pusher> getPushers() {
|
||||||
return pushers.values();
|
return pushers.values();
|
||||||
}
|
}
|
||||||
|
@ -9,10 +9,10 @@ import java.util.TreeMap;
|
|||||||
|
|
||||||
import android.content.SharedPreferences;
|
import android.content.SharedPreferences;
|
||||||
import com.fsck.k9.Account;
|
import com.fsck.k9.Account;
|
||||||
|
import com.fsck.k9.Account.SortType;
|
||||||
import com.fsck.k9.K9;
|
import com.fsck.k9.K9;
|
||||||
import com.fsck.k9.R;
|
import com.fsck.k9.R;
|
||||||
import com.fsck.k9.Account.FolderMode;
|
import com.fsck.k9.Account.FolderMode;
|
||||||
import com.fsck.k9.controller.MessagingController.SortType;
|
|
||||||
import com.fsck.k9.crypto.Apg;
|
import com.fsck.k9.crypto.Apg;
|
||||||
import com.fsck.k9.mail.store.StorageManager;
|
import com.fsck.k9.mail.store.StorageManager;
|
||||||
import com.fsck.k9.preferences.Settings.*;
|
import com.fsck.k9.preferences.Settings.*;
|
||||||
|
Loading…
Reference in New Issue
Block a user