diff options
author | twyen <twyen@google.com> | 2018-06-25 12:36:26 -0700 |
---|---|---|
committer | Copybara-Service <copybara-piper@google.com> | 2018-06-26 13:42:08 -0700 |
commit | 5578d928bf777f721ec0ec04c84ddb7d3ea56edb (patch) | |
tree | 150f643cf67aee21a2ac730d3f7b1f6cada7db47 /java/com/android/dialer/app/list/PhoneFavoritesTileAdapter.java | |
parent | 03bacec1394032712c534605476fb634b85eee28 (diff) |
Refactor ContactPreference
Moving it outside contacts.commons reduces dependency to legacy code. Also removed redundant implementations such as caching SharedPreferences (it is already cached), custom ListPreferences (standard ListPreferences already have what we want), and corrected preference storage location (allow standard ListPreferences to work)
TEST=TAP
Test: TAP
PiperOrigin-RevId: 202000393
Change-Id: I45374e610b3510784b5a4da92e5d8462cbfc92bb
Diffstat (limited to 'java/com/android/dialer/app/list/PhoneFavoritesTileAdapter.java')
-rw-r--r-- | java/com/android/dialer/app/list/PhoneFavoritesTileAdapter.java | 19 |
1 files changed, 5 insertions, 14 deletions
diff --git a/java/com/android/dialer/app/list/PhoneFavoritesTileAdapter.java b/java/com/android/dialer/app/list/PhoneFavoritesTileAdapter.java index a20185989..4cc48a6de 100644 --- a/java/com/android/dialer/app/list/PhoneFavoritesTileAdapter.java +++ b/java/com/android/dialer/app/list/PhoneFavoritesTileAdapter.java @@ -37,10 +37,10 @@ import android.widget.BaseAdapter; import com.android.contacts.common.ContactTileLoaderFactory; import com.android.contacts.common.list.ContactEntry; import com.android.contacts.common.list.ContactTileView; -import com.android.contacts.common.preference.ContactsPreferences; import com.android.dialer.app.R; import com.android.dialer.common.LogUtil; import com.android.dialer.contactphoto.ContactPhotoManager; +import com.android.dialer.contacts.ContactsComponent; import com.android.dialer.duo.Duo; import com.android.dialer.duo.DuoComponent; import com.android.dialer.logging.InteractionEvent; @@ -78,11 +78,11 @@ public class PhoneFavoritesTileAdapter extends BaseAdapter implements OnDragDrop private OnDataSetChangedForAnimationListener dataSetChangedListener; private Context context; private Resources resources; - private ContactsPreferences contactsPreferences; private final Comparator<ContactEntry> contactEntryComparator = new Comparator<ContactEntry>() { @Override public int compare(ContactEntry lhs, ContactEntry rhs) { + return ComparisonChain.start() .compare(lhs.pinned, rhs.pinned) .compare(getPreferredSortName(lhs), getPreferredSortName(rhs)) @@ -90,11 +90,9 @@ public class PhoneFavoritesTileAdapter extends BaseAdapter implements OnDragDrop } private String getPreferredSortName(ContactEntry contactEntry) { - if (contactsPreferences.getSortOrder() == ContactsPreferences.SORT_ORDER_PRIMARY - || TextUtils.isEmpty(contactEntry.nameAlternative)) { - return contactEntry.namePrimary; - } - return contactEntry.nameAlternative; + return ContactsComponent.get(context) + .contactDisplayPreferences() + .getSortName(contactEntry.namePrimary, contactEntry.nameAlternative); } }; /** Back up of the temporarily removed Contact during dragging. */ @@ -121,7 +119,6 @@ public class PhoneFavoritesTileAdapter extends BaseAdapter implements OnDragDrop this.listener = listener; this.context = context; resources = context.getResources(); - contactsPreferences = new ContactsPreferences(this.context); numFrequents = 0; contactEntries = new ArrayList<>(); } @@ -140,11 +137,6 @@ public class PhoneFavoritesTileAdapter extends BaseAdapter implements OnDragDrop this.inDragging = inDragging; } - void refreshContactsPreferences() { - contactsPreferences.refreshValue(ContactsPreferences.DISPLAY_ORDER_KEY); - contactsPreferences.refreshValue(ContactsPreferences.SORT_ORDER_KEY); - } - /** * Gets the number of frequents from the passed in cursor. * @@ -256,7 +248,6 @@ public class PhoneFavoritesTileAdapter extends BaseAdapter implements OnDragDrop (!TextUtils.isEmpty(nameAlternative)) ? nameAlternative : resources.getString(R.string.missing_name); - contact.nameDisplayOrder = contactsPreferences.getDisplayOrder(); contact.photoUri = (photoUri != null ? Uri.parse(photoUri) : null); contact.lookupKey = lookupKey; contact.lookupUri = |