Search in sources :

Example 1 with ReverseComparator

use of com.fsck.k9.fragment.MessageListFragmentComparators.ReverseComparator in project k-9 by k9mail.

the class MessageListFragment method getComparator.

/**
     * @return The comparator to use to display messages in an ordered
     *         fashion. Never {@code null}.
     */
private Comparator<Cursor> getComparator() {
    final List<Comparator<Cursor>> chain = new ArrayList<>(3);
    // Add the specified comparator
    final Comparator<Cursor> comparator = SORT_COMPARATORS.get(sortType);
    if (sortAscending) {
        chain.add(comparator);
    } else {
        chain.add(new ReverseComparator<>(comparator));
    }
    // Add the date comparator if not already specified
    if (sortType != SortType.SORT_DATE && sortType != SortType.SORT_ARRIVAL) {
        final Comparator<Cursor> dateComparator = SORT_COMPARATORS.get(SortType.SORT_DATE);
        if (sortDateAscending) {
            chain.add(dateComparator);
        } else {
            chain.add(new ReverseComparator<>(dateComparator));
        }
    }
    // Add the id comparator
    chain.add(new ReverseIdComparator());
    // Build the comparator chain
    return new ComparatorChain<>(chain);
}
Also used : ComparatorChain(com.fsck.k9.fragment.MessageListFragmentComparators.ComparatorChain) ArrayList(java.util.ArrayList) ReverseIdComparator(com.fsck.k9.fragment.MessageListFragmentComparators.ReverseIdComparator) Cursor(android.database.Cursor) UnreadComparator(com.fsck.k9.fragment.MessageListFragmentComparators.UnreadComparator) AttachmentComparator(com.fsck.k9.fragment.MessageListFragmentComparators.AttachmentComparator) SenderComparator(com.fsck.k9.fragment.MessageListFragmentComparators.SenderComparator) DateComparator(com.fsck.k9.fragment.MessageListFragmentComparators.DateComparator) ReverseIdComparator(com.fsck.k9.fragment.MessageListFragmentComparators.ReverseIdComparator) ReverseComparator(com.fsck.k9.fragment.MessageListFragmentComparators.ReverseComparator) SubjectComparator(com.fsck.k9.fragment.MessageListFragmentComparators.SubjectComparator) ArrivalComparator(com.fsck.k9.fragment.MessageListFragmentComparators.ArrivalComparator) FlaggedComparator(com.fsck.k9.fragment.MessageListFragmentComparators.FlaggedComparator) Comparator(java.util.Comparator)

Aggregations

Cursor (android.database.Cursor)1 ArrivalComparator (com.fsck.k9.fragment.MessageListFragmentComparators.ArrivalComparator)1 AttachmentComparator (com.fsck.k9.fragment.MessageListFragmentComparators.AttachmentComparator)1 ComparatorChain (com.fsck.k9.fragment.MessageListFragmentComparators.ComparatorChain)1 DateComparator (com.fsck.k9.fragment.MessageListFragmentComparators.DateComparator)1 FlaggedComparator (com.fsck.k9.fragment.MessageListFragmentComparators.FlaggedComparator)1 ReverseComparator (com.fsck.k9.fragment.MessageListFragmentComparators.ReverseComparator)1 ReverseIdComparator (com.fsck.k9.fragment.MessageListFragmentComparators.ReverseIdComparator)1 SenderComparator (com.fsck.k9.fragment.MessageListFragmentComparators.SenderComparator)1 SubjectComparator (com.fsck.k9.fragment.MessageListFragmentComparators.SubjectComparator)1 UnreadComparator (com.fsck.k9.fragment.MessageListFragmentComparators.UnreadComparator)1 ArrayList (java.util.ArrayList)1 Comparator (java.util.Comparator)1