Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Unverified Commit 908f7758 authored by cketti's avatar cketti Committed by GitHub
Browse files

Merge pull request #4962 from starshipcoder/favorites_contacts

In recipient selection dropdown display starred contacts first
parents 5cec85cb 19eb78de
Loading
Loading
Loading
Loading
+12 −4
Original line number Diff line number Diff line
@@ -30,6 +30,8 @@ import com.fsck.k9.view.RecipientSelectView.Recipient;
import com.fsck.k9.view.RecipientSelectView.RecipientCryptoStatus;
import timber.log.Timber;

import static java.lang.String.CASE_INSENSITIVE_ORDER;


public class RecipientLoader extends AsyncTaskLoader<List<Recipient>> {
    /*
@@ -44,6 +46,7 @@ public class RecipientLoader extends AsyncTaskLoader<List<Recipient>> {
    private static final int INDEX_PHOTO_URI = 7;
    private static final int INDEX_TIMES_CONTACTED = 8;
    private static final int INDEX_KEY_PRIMARY = 9;
    private static final int INDEX_STARRED = 10;

    private static final String[] PROJECTION = {
            ContactsContract.CommonDataKinds.Email._ID,
@@ -55,7 +58,8 @@ public class RecipientLoader extends AsyncTaskLoader<List<Recipient>> {
            ContactsContract.CommonDataKinds.Email.CONTACT_ID,
            ContactsContract.Contacts.PHOTO_THUMBNAIL_URI,
            ContactsContract.CommonDataKinds.Email.TIMES_CONTACTED,
            ContactsContract.Contacts.SORT_KEY_PRIMARY
            ContactsContract.Contacts.SORT_KEY_PRIMARY,
            ContactsContract.Contacts.STARRED,
    };

    private static final String SORT_ORDER = "" +
@@ -93,6 +97,10 @@ public class RecipientLoader extends AsyncTaskLoader<List<Recipient>> {
    private static final Comparator<Recipient> RECIPIENT_COMPARATOR = new Comparator<Recipient>() {
        @Override
        public int compare(Recipient lhs, Recipient rhs) {
            if (rhs.starred != lhs.starred) {
                return rhs.starred ? 1 : -1;
            }

            int timesContactedDiff = rhs.timesContacted - lhs.timesContacted;
            if (timesContactedDiff != 0) {
                return timesContactedDiff;
@@ -102,7 +110,7 @@ public class RecipientLoader extends AsyncTaskLoader<List<Recipient>> {
                return 0;
            }

            return lhs.sortKey.compareTo(rhs.sortKey);
            return CASE_INSENSITIVE_ORDER.compare(lhs.sortKey, rhs.sortKey);
        }
    };

@@ -436,7 +444,7 @@ public class RecipientLoader extends AsyncTaskLoader<List<Recipient>> {
            String lookupKey = cursor.getString(INDEX_LOOKUP_KEY);
            int timesContacted = cursor.getInt(INDEX_TIMES_CONTACTED);
            String sortKey = cursor.getString(INDEX_KEY_PRIMARY);

            boolean starred = cursor.getInt(INDEX_STARRED) == 1;
            int addressType = cursor.getInt(INDEX_EMAIL_TYPE);
            String addressLabel = null;
            switch (addressType) {
@@ -464,7 +472,7 @@ public class RecipientLoader extends AsyncTaskLoader<List<Recipient>> {
            }

            Recipient recipient = new Recipient(name, email, addressLabel, contactId, lookupKey,
                    timesContacted, sortKey);
                    timesContacted, sortKey, starred);

            if (recipient.isValidEmailAddress()) {

+4 −5
Original line number Diff line number Diff line
@@ -678,6 +678,7 @@ public class RecipientSelectView extends TokenCompleteTextView<Recipient> implem
        public String addressLabel;
        public final int timesContacted;
        public final String sortKey;
        public final boolean starred;

        @Nullable // null if the contact has no photo. transient because we serialize this manually, see below.
        public transient Uri photoThumbnailUri;
@@ -692,14 +693,11 @@ public class RecipientSelectView extends TokenCompleteTextView<Recipient> implem
            this.contactLookupKey = null;
            timesContacted = 0;
            sortKey = null;
        }

        public Recipient(String name, String email, String addressLabel, long contactId, String lookupKey) {
            this(name, email, addressLabel, contactId, lookupKey, 0, null);
            starred = false;
        }

        public Recipient(String name, String email, String addressLabel, long contactId, String lookupKey,
                int timesContacted, String sortKey) {
                int timesContacted, String sortKey, boolean starred) {
            this.address = new Address(email, name);
            this.contactId = contactId;
            this.addressLabel = addressLabel;
@@ -707,6 +705,7 @@ public class RecipientSelectView extends TokenCompleteTextView<Recipient> implem
            this.contactLookupKey = lookupKey;
            this.timesContacted = timesContacted;
            this.sortKey = sortKey;
            this.starred = starred;
        }

        public String getDisplayNameOrAddress() {
+6 −5
Original line number Diff line number Diff line
@@ -45,7 +45,8 @@ public class RecipientLoaderTest extends RobolectricTest {
            ContactsContract.CommonDataKinds.Email.CONTACT_ID,
            ContactsContract.Contacts.PHOTO_THUMBNAIL_URI,
            ContactsContract.CommonDataKinds.Email.TIMES_CONTACTED,
            ContactsContract.Contacts.SORT_KEY_PRIMARY
            ContactsContract.Contacts.SORT_KEY_PRIMARY,
            ContactsContract.Contacts.STARRED
    };
    static final String[] PROJECTION_NICKNAME = {
            ContactsContract.Data.CONTACT_ID,
@@ -57,14 +58,14 @@ public class RecipientLoaderTest extends RobolectricTest {
    static final Address CONTACT_ADDRESS_2 = Address.parse("Other Contact Name <address_two@example.org>")[0];
    static final String TYPE = "" + TYPE_HOME;
    static final String[] CONTACT_1 =
            new String[] { "0", "Bob", "bob", "bob@host.com", TYPE, null, "1", null, "100", "Bob" };
            new String[] { "0", "Bob", "bob", "bob@host.com", TYPE, null, "1", null, "100", "Bob", "0" };
    static final String[] CONTACT_2 =
            new String[] { "2", "Bob2", "bob2", "bob2@host.com", TYPE, null, "2", null, "99", "Bob2" };
            new String[] { "2", "Bob2", "bob2", "bob2@host.com", TYPE, null, "2", null, "99", "Bob2", "0" };
    static final String[] CONTACT_NO_EMAIL =
            new String[] { "0", "Bob", "bob", null, TYPE, null, "1", null, "10", "Bob_noMail" };
            new String[] { "0", "Bob", "bob", null, TYPE, null, "1", null, "10", "Bob_noMail", "0" };
    static final String[] CONTACT_WITH_NICKNAME_NOT_CONTACTED =
            new String[] { "0", "Eve_notContacted", "eve_notContacted", "eve_notContacted@host.com", TYPE, null, "2",
                    null, "0", "Eve" };
                    null, "0", "Eve", "0" };
    static final String[] NICKNAME_NOT_CONTACTED = new String[] { "2", "Eves_Nickname_Bob" };

    static final String QUERYSTRING = "querystring";