diff options
author | Treehugger Robot <treehugger-gerrit@google.com> | 2018-04-24 00:41:24 +0000 |
---|---|---|
committer | Gerrit Code Review <noreply-gerritcodereview@google.com> | 2018-04-24 00:41:24 +0000 |
commit | 24f0348fa71eb85fed2aabe871ae5057ee1f465e (patch) | |
tree | 818851f63faa07a0e76de52bba8791a5af9dceab /java/com/android/dialer | |
parent | 54468190f8c745eb4c6b443b2deef20f370b099c (diff) | |
parent | 4558ed566b2da4562b0ac9773cdb679e5d097277 (diff) |
Merge "Implement display name ordering in Speed Dial fragment."
Diffstat (limited to 'java/com/android/dialer')
-rw-r--r-- | java/com/android/dialer/speeddial/loader/SpeedDialUiItem.java | 22 | ||||
-rw-r--r-- | java/com/android/dialer/speeddial/loader/SpeedDialUiItemLoader.java | 23 |
2 files changed, 38 insertions, 7 deletions
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}. * * <p>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<SpeedDialUiItem> 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<SpeedDialUiItem> 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<SpeedDialEntry> entries) { Assert.isWorkerThread(); // Fetch the contact ids from the SpeedDialEntries - Set<String> contactIds = new HashSet<>(); + Set<String> 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; + } } |