From 4558ed566b2da4562b0ac9773cdb679e5d097277 Mon Sep 17 00:00:00 2001 From: calderwoodra Date: Mon, 23 Apr 2018 16:07:05 -0700 Subject: Implement display name ordering in Speed Dial fragment. Bug: 77724765 Test: manual PiperOrigin-RevId: 194001119 Change-Id: I6bef1f746e39c36df5daf5938c774041b0f0f47e --- .../dialer/speeddial/loader/SpeedDialUiItem.java | 22 +++++++++++++++++++-- .../speeddial/loader/SpeedDialUiItemLoader.java | 23 +++++++++++++++++----- 2 files changed, 38 insertions(+), 7 deletions(-) (limited to 'java/com/android/dialer') diff --git a/java/com/android/dialer/speeddial/loader/SpeedDialUiItem.java b/java/com/android/dialer/speeddial/loader/SpeedDialUiItem.java index 5b7906fdb..24bc776e7 100644 --- a/java/com/android/dialer/speeddial/loader/SpeedDialUiItem.java +++ b/java/com/android/dialer/speeddial/loader/SpeedDialUiItem.java @@ -52,7 +52,7 @@ public abstract class SpeedDialUiItem { public static final int PHOTO_URI = 8; public static final int CARRIER_PRESENCE = 9; - public static final String[] PHONE_PROJECTION = { + private static final String[] PHONE_PROJECTION = { Phone.LOOKUP_KEY, Phone.CONTACT_ID, Phone.DISPLAY_NAME, @@ -65,12 +65,30 @@ public abstract class SpeedDialUiItem { Phone.CARRIER_PRESENCE }; + private static final String[] PHONE_PROJECTION_ALTERNATIVE = { + Phone.LOOKUP_KEY, + Phone.CONTACT_ID, + Phone.DISPLAY_NAME_ALTERNATIVE, + Phone.STARRED, + Phone.NUMBER, + Phone.TYPE, + Phone.LABEL, + Phone.PHOTO_ID, + Phone.PHOTO_URI, + Phone.CARRIER_PRESENCE + }; + + public static String[] getPhoneProjection(boolean primaryDisplayOrder) { + return primaryDisplayOrder ? PHONE_PROJECTION : PHONE_PROJECTION_ALTERNATIVE; + } + public static Builder builder() { return new AutoValue_SpeedDialUiItem.Builder().setChannels(ImmutableList.of()); } /** - * Convert a cursor with projection {@link #PHONE_PROJECTION} into a {@link SpeedDialUiItem}. + * Convert a cursor with projection {@link #getPhoneProjection(boolean)} into a {@link + * SpeedDialUiItem}. * *

This cursor is structured such that contacts are grouped by contact id and lookup key and * each row that shares the same contact id and lookup key represents a phone number that belongs diff --git a/java/com/android/dialer/speeddial/loader/SpeedDialUiItemLoader.java b/java/com/android/dialer/speeddial/loader/SpeedDialUiItemLoader.java index 955793d72..71540da51 100644 --- a/java/com/android/dialer/speeddial/loader/SpeedDialUiItemLoader.java +++ b/java/com/android/dialer/speeddial/loader/SpeedDialUiItemLoader.java @@ -29,6 +29,7 @@ import android.support.annotation.MainThread; import android.support.annotation.WorkerThread; import android.util.ArrayMap; import android.util.ArraySet; +import com.android.contacts.common.preference.ContactsPreferences; import com.android.dialer.common.Assert; import com.android.dialer.common.LogUtil; import com.android.dialer.common.concurrent.Annotations.BackgroundExecutor; @@ -46,7 +47,6 @@ import com.google.common.collect.ImmutableList; import com.google.common.util.concurrent.ListenableFuture; import com.google.common.util.concurrent.ListeningExecutorService; import java.util.ArrayList; -import java.util.HashSet; import java.util.List; import java.util.Map; import java.util.Set; @@ -83,6 +83,7 @@ public final class SpeedDialUiItemLoader { private final ListeningExecutorService backgroundExecutor; // Used to ensure that only one refresh flow runs at a time. private final DialerFutureSerializer dialerFutureSerializer = new DialerFutureSerializer(); + private final ContactsPreferences contactsPreferences; @Inject public SpeedDialUiItemLoader( @@ -90,6 +91,7 @@ public final class SpeedDialUiItemLoader { @BackgroundExecutor ListeningExecutorService backgroundExecutor) { this.appContext = appContext; this.backgroundExecutor = backgroundExecutor; + this.contactsPreferences = new ContactsPreferences(appContext); } /** @@ -113,10 +115,16 @@ public final class SpeedDialUiItemLoader { @WorkerThread private ImmutableList insertNewContactEntry(Uri contactUri) { Assert.isWorkerThread(); + contactsPreferences.refreshValue(ContactsPreferences.DISPLAY_ORDER_KEY); try (Cursor cursor = appContext .getContentResolver() - .query(contactUri, SpeedDialUiItem.PHONE_PROJECTION, null, null, null)) { + .query( + contactUri, + SpeedDialUiItem.getPhoneProjection(isPrimaryDisplayNameOrder()), + null, + null, + null)) { if (cursor == null) { LogUtil.e("SpeedDialUiItemLoader.insertNewContactEntry", "Cursor was null"); return loadSpeedDialUiItemsInternal(); @@ -152,6 +160,7 @@ public final class SpeedDialUiItemLoader { @WorkerThread private ImmutableList loadSpeedDialUiItemsInternal() { Assert.isWorkerThread(); + contactsPreferences.refreshValue(ContactsPreferences.DISPLAY_ORDER_KEY); SpeedDialEntryDao db = getSpeedDialEntryDao(); // This is the list of contacts that we will display to the user @@ -280,7 +289,7 @@ public final class SpeedDialUiItemLoader { List entries) { Assert.isWorkerThread(); // Fetch the contact ids from the SpeedDialEntries - Set contactIds = new HashSet<>(); + Set contactIds = new ArraySet<>(); entries.forEach(entry -> contactIds.add(Long.toString(entry.contactId()))); if (contactIds.isEmpty()) { return new ArrayMap<>(); @@ -294,7 +303,7 @@ public final class SpeedDialUiItemLoader { .getContentResolver() .query( Phone.CONTENT_URI, - SpeedDialUiItem.PHONE_PROJECTION, + SpeedDialUiItem.getPhoneProjection(isPrimaryDisplayNameOrder()), selection.getSelection(), selection.getSelectionArgs(), null)) { @@ -388,7 +397,7 @@ public final class SpeedDialUiItemLoader { .getContentResolver() .query( Phone.CONTENT_URI, - SpeedDialUiItem.PHONE_PROJECTION, + SpeedDialUiItem.getPhoneProjection(isPrimaryDisplayNameOrder()), selection.getSelection(), selection.getSelectionArgs(), null)) { @@ -476,4 +485,8 @@ public final class SpeedDialUiItemLoader { private SpeedDialEntryDao getSpeedDialEntryDao() { return new SpeedDialEntryDatabaseHelper(appContext); } + + private boolean isPrimaryDisplayNameOrder() { + return contactsPreferences.getDisplayOrder() == ContactsPreferences.DISPLAY_ORDER_PRIMARY; + } } -- cgit v1.2.3