diff --git a/res/menu/message_list_option.xml b/res/menu/message_list_option.xml index 2aa550a0f..b8bbf03a7 100644 --- a/res/menu/message_list_option.xml +++ b/res/menu/message_list_option.xml @@ -15,6 +15,10 @@ android:id="@+id/set_sort_date" android:title="@string/sort_by_date" /> + Sort by... Date + Arrival Sender Subject Star diff --git a/src/com/fsck/k9/activity/MessageInfoHolder.java b/src/com/fsck/k9/activity/MessageInfoHolder.java index e19fb953a..baee99b9a 100644 --- a/src/com/fsck/k9/activity/MessageInfoHolder.java +++ b/src/com/fsck/k9/activity/MessageInfoHolder.java @@ -7,6 +7,7 @@ import com.fsck.k9.mail.store.LocalStore.LocalMessage; public class MessageInfoHolder { public String date; public Date compareDate; + public Date compareArrival; public String compareSubject; public CharSequence sender; public String senderAddress; diff --git a/src/com/fsck/k9/activity/MessageList.java b/src/com/fsck/k9/activity/MessageList.java index f874267f9..aec709cfe 100644 --- a/src/com/fsck/k9/activity/MessageList.java +++ b/src/com/fsck/k9/activity/MessageList.java @@ -185,6 +185,15 @@ public class MessageList } + public static class ArrivalComparator implements Comparator { + + @Override + public int compare(MessageInfoHolder object1, MessageInfoHolder object2) { + return object1.compareArrival.compareTo(object2.compareArrival); + } + + } + public static class SubjectComparator implements Comparator { @Override @@ -234,6 +243,7 @@ public class MessageList final Map> map = new EnumMap>(SORT_TYPE.class); map.put(SORT_TYPE.SORT_ATTACHMENT, new AttachmentComparator()); map.put(SORT_TYPE.SORT_DATE, new DateComparator()); + map.put(SORT_TYPE.SORT_ARRIVAL, new ArrivalComparator()); map.put(SORT_TYPE.SORT_FLAGGED, new FlaggedComparator()); map.put(SORT_TYPE.SORT_SENDER, new SenderComparator()); map.put(SORT_TYPE.SORT_SUBJECT, new SubjectComparator()); @@ -460,7 +470,7 @@ public class MessageList { // add the date comparator if not already specified - if (sortType != SORT_TYPE.SORT_DATE) { + if (sortType != SORT_TYPE.SORT_DATE && sortType != SORT_TYPE.SORT_ARRIVAL) { final Comparator comparator = SORT_COMPARATORS.get(SORT_TYPE.SORT_DATE); if (sortDateAscending) { chain.add(comparator); @@ -1439,6 +1449,10 @@ public class MessageList changeSort(SORT_TYPE.SORT_DATE); return true; } + case R.id.set_sort_arrival: { + changeSort(SORT_TYPE.SORT_ARRIVAL); + return true; + } case R.id.set_sort_subject: { changeSort(SORT_TYPE.SORT_SUBJECT); return true; diff --git a/src/com/fsck/k9/controller/MessagingController.java b/src/com/fsck/k9/controller/MessagingController.java index 250e3fb3d..33acd96f1 100644 --- a/src/com/fsck/k9/controller/MessagingController.java +++ b/src/com/fsck/k9/controller/MessagingController.java @@ -146,6 +146,7 @@ public class MessagingController implements Runnable { public enum SORT_TYPE { 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), diff --git a/src/com/fsck/k9/helper/MessageHelper.java b/src/com/fsck/k9/helper/MessageHelper.java index 43b208a77..018b481e2 100644 --- a/src/com/fsck/k9/helper/MessageHelper.java +++ b/src/com/fsck/k9/helper/MessageHelper.java @@ -49,6 +49,7 @@ public class MessageHelper { try { LocalMessage message = (LocalMessage) m; target.message = message; + target.compareArrival = message.getInternalDate(); target.compareDate = message.getSentDate(); if (target.compareDate == null) { target.compareDate = message.getInternalDate();