diff --git a/res/menu/message_list_option.xml b/res/menu/message_list_option.xml index dd5891372..aa97fed97 100644 --- a/res/menu/message_list_option.xml +++ b/res/menu/message_list_option.xml @@ -143,11 +143,9 @@ - diff --git a/res/values/strings.xml b/res/values/strings.xml index 24d180226..cfbdb9ceb 100644 --- a/res/values/strings.xml +++ b/res/values/strings.xml @@ -735,6 +735,8 @@ Please submit bug reports, contribute new features and ask questions at Latest messages first Subject alphabetical Subject reverse alphabetical + Sender alphabetical + Sender reverse alphabetical Starred messages first Unstarred messages first Unread messages first @@ -746,6 +748,7 @@ Please submit bug reports, contribute new features and ask questions at Date Arrival Subject + Sender Star Read/unread Attachments diff --git a/src/com/fsck/k9/Account.java b/src/com/fsck/k9/Account.java index ecb7059a3..4328a732e 100644 --- a/src/com/fsck/k9/Account.java +++ b/src/com/fsck/k9/Account.java @@ -106,7 +106,7 @@ public class Account implements BaseAccount { 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_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); diff --git a/src/com/fsck/k9/activity/MessageList.java b/src/com/fsck/k9/activity/MessageList.java index 1e48d158f..4d3fd1ace 100644 --- a/src/com/fsck/k9/activity/MessageList.java +++ b/src/com/fsck/k9/activity/MessageList.java @@ -769,10 +769,10 @@ public class MessageList extends K9FragmentActivity implements MessageListFragme mMessageListFragment.changeSort(SortType.SORT_SUBJECT); return true; } -// case R.id.set_sort_sender: { -// mMessageListFragment.changeSort(SortType.SORT_SENDER); -// return true; -// } + case R.id.set_sort_sender: { + mMessageListFragment.changeSort(SortType.SORT_SENDER); + return true; + } case R.id.set_sort_flag: { mMessageListFragment.changeSort(SortType.SORT_FLAGGED); return true; diff --git a/src/com/fsck/k9/fragment/MessageListFragment.java b/src/com/fsck/k9/fragment/MessageListFragment.java index 6fa1ac160..fefa25a9e 100644 --- a/src/com/fsck/k9/fragment/MessageListFragment.java +++ b/src/com/fsck/k9/fragment/MessageListFragment.java @@ -312,6 +312,25 @@ public class MessageListFragment extends SherlockFragment implements OnItemClick } } + public static class SenderComparator implements Comparator { + + @Override + public int compare(Cursor cursor1, Cursor cursor2) { + String sender1 = getSenderAddressFromCursor(cursor1); + String sender2 = getSenderAddressFromCursor(cursor2); + + if (sender1 == null && sender2 == null) { + return 0; + } else if (sender1 == null) { + return 1; + } else if (sender2 == null) { + return -1; + } else { + return sender1.compareToIgnoreCase(sender2); + } + } + } + private static final int ACTIVITY_CHOOSE_FOLDER_MOVE = 1; private static final int ACTIVITY_CHOOSE_FOLDER_COPY = 2; @@ -340,6 +359,7 @@ public class MessageListFragment extends SherlockFragment implements OnItemClick map.put(SortType.SORT_ARRIVAL, new ArrivalComparator()); map.put(SortType.SORT_FLAGGED, new FlaggedComparator()); map.put(SortType.SORT_SUBJECT, new SubjectComparator()); + map.put(SortType.SORT_SENDER, new SenderComparator()); map.put(SortType.SORT_UNREAD, new UnreadComparator()); // make it immutable to prevent accidental alteration (content is immutable already) @@ -1370,10 +1390,10 @@ public class MessageListFragment extends SherlockFragment implements OnItemClick changeSort(SortType.SORT_SUBJECT); return true; } -// case R.id.set_sort_sender: { -// changeSort(SortType.SORT_SENDER); -// return true; -// } + case R.id.set_sort_sender: { + changeSort(SortType.SORT_SENDER); + return true; + } case R.id.set_sort_flag: { changeSort(SortType.SORT_FLAGGED); return true; @@ -1503,7 +1523,7 @@ public class MessageListFragment extends SherlockFragment implements OnItemClick } - private String getSenderAddressFromCursor(Cursor cursor) { + private static String getSenderAddressFromCursor(Cursor cursor) { String fromList = cursor.getString(SENDER_LIST_COLUMN); Address[] fromAddrs = Address.unpack(fromList); return (fromAddrs.length > 0) ? fromAddrs[0].getAddress() : null; @@ -3240,11 +3260,11 @@ public class MessageListFragment extends SherlockFragment implements OnItemClick sortColumn = "(" + MessageColumns.FLAGGED + " != 1)"; break; } -// case SORT_SENDER: { -// //FIXME -// sortColumn = MessageColumns.SENDER_LIST; -// break; -// } + case SORT_SENDER: { + //FIXME + sortColumn = MessageColumns.SENDER_LIST; + break; + } case SORT_SUBJECT: { sortColumn = MessageColumns.SUBJECT + " COLLATE NOCASE"; break;