diff options
author | calderwoodra <calderwoodra@google.com> | 2017-11-20 10:40:49 -0800 |
---|---|---|
committer | Copybara-Service <copybara-piper@google.com> | 2017-11-20 12:28:16 -0800 |
commit | 2c3d11eff44a8b61b32c0781a7cfc3b94a1d453d (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: Ia890ad20e9e484fa9c4622c4b899b33f5b6e3990
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); |