diff options
author | calderwoodra <calderwoodra@google.com> | 2017-11-20 10:40:49 -0800 |
---|---|---|
committer | Copybara-Service <copybara-piper@google.com> | 2017-11-20 11:10:06 -0800 |
commit | 8d272bb15d3bb20b541da9f675bc5738cdfc2484 (patch) | |
tree | 4cb9a79488f1ce477a1d6c837bca532fe3d89bac /java/com/android/dialer/searchfragment/cp2/ContactFilterCursor.java | |
parent | 5f85a77502dc62c68103dfb998157d7b066d54d3 (diff) |
Search now supports alternative sort and display orders for contact names.
This means that names like "Bob Dylan" can be displayed as "Dylan, Bob" and
the names are now able to be sorted by last name as well.
This change also adds content descriptions to search icon for a11y.
Bug: 68293751
Test: NewSearchFragmentTest
PiperOrigin-RevId: 176382228
Change-Id: I5b2b0f3f3f1e2f23ea6b745fd809adfb0ba6242c
Diffstat (limited to 'java/com/android/dialer/searchfragment/cp2/ContactFilterCursor.java')
-rw-r--r-- | java/com/android/dialer/searchfragment/cp2/ContactFilterCursor.java | 20 |
1 files changed, 14 insertions, 6 deletions
diff --git a/java/com/android/dialer/searchfragment/cp2/ContactFilterCursor.java b/java/com/android/dialer/searchfragment/cp2/ContactFilterCursor.java index dc16f9dd0..23c0d6e6d 100644 --- a/java/com/android/dialer/searchfragment/cp2/ContactFilterCursor.java +++ b/java/com/android/dialer/searchfragment/cp2/ContactFilterCursor.java @@ -32,6 +32,7 @@ import android.support.annotation.IntDef; import android.support.annotation.Nullable; import android.support.v4.util.ArraySet; import android.text.TextUtils; +import android.util.ArrayMap; import com.android.dialer.searchfragment.common.Projections; import com.android.dialer.searchfragment.common.QueryFilteringUtil; import java.lang.annotation.Retention; @@ -40,6 +41,7 @@ import java.util.ArrayList; import java.util.Collections; import java.util.List; import java.util.Locale; +import java.util.Map; import java.util.Set; /** @@ -108,25 +110,24 @@ final class ContactFilterCursor implements Cursor { private static Cursor createCursor(Cursor cursor) { // Convert cursor rows into Cp2Contacts List<Cp2Contact> cp2Contacts = new ArrayList<>(); - Set<Integer> contactIds = new ArraySet<>(); + Map<Integer, Integer> contactIdsToPosition = new ArrayMap<>(); cursor.moveToPosition(-1); while (cursor.moveToNext()) { Cp2Contact contact = Cp2Contact.fromCursor(cursor); cp2Contacts.add(contact); - contactIds.add(contact.contactId()); + contactIdsToPosition.put(contact.contactId(), cursor.getPosition()); } cursor.close(); // Group then combine contact data List<Cp2Contact> coalescedContacts = new ArrayList<>(); - for (Integer contactId : contactIds) { + for (Integer contactId : contactIdsToPosition.keySet()) { List<Cp2Contact> duplicateContacts = getAllContactsWithContactId(contactId, cp2Contacts); coalescedContacts.addAll(coalesceContacts(duplicateContacts)); } - // Sort by display name, then build new cursor from coalesced contacts. - // We sort the contacts so that they are displayed to the user in lexicographic order. - Collections.sort(coalescedContacts, (o1, o2) -> o1.displayName().compareTo(o2.displayName())); + // Sort the contacts back into the exact same order they were inside of {@code cursor} + Collections.sort(coalescedContacts, (o1, o2) -> compare(contactIdsToPosition, o1, o2)); MatrixCursor newCursor = new MatrixCursor(Projections.CP2_PROJECTION, coalescedContacts.size()); for (Cp2Contact contact : coalescedContacts) { newCursor.addRow(contact.toCursorRow()); @@ -166,6 +167,13 @@ final class ContactFilterCursor implements Cursor { return coalescedContacts; } + private static int compare( + Map<Integer, Integer> contactIdsToPosition, Cp2Contact o1, Cp2Contact o2) { + int position1 = contactIdsToPosition.get(o1.contactId()); + int position2 = contactIdsToPosition.get(o2.contactId()); + return Integer.compare(position1, position2); + } + private static void removeDuplicatePhoneNumbers(List<Cp2Contact> phoneContacts) { for (int i = 0; i < phoneContacts.size(); i++) { Cp2Contact contact1 = phoneContacts.get(i); |