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/contactsfragment/ContactsCursorLoader.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/contactsfragment/ContactsCursorLoader.java')
-rw-r--r-- | java/com/android/dialer/contactsfragment/ContactsCursorLoader.java | 27 |
1 files changed, 16 insertions, 11 deletions
diff --git a/java/com/android/dialer/contactsfragment/ContactsCursorLoader.java b/java/com/android/dialer/contactsfragment/ContactsCursorLoader.java index e55f95149..d74afe538 100644 --- a/java/com/android/dialer/contactsfragment/ContactsCursorLoader.java +++ b/java/com/android/dialer/contactsfragment/ContactsCursorLoader.java @@ -21,7 +21,7 @@ import android.content.CursorLoader; import android.net.Uri; import android.provider.ContactsContract.Contacts; import android.text.TextUtils; -import com.android.contacts.common.preference.ContactsPreferences; +import com.android.dialer.contacts.ContactsComponent; /** Cursor Loader for {@link ContactsFragment}. */ final class ContactsCursorLoader extends CursorLoader { @@ -61,12 +61,13 @@ final class ContactsCursorLoader extends CursorLoader { } private static String[] getProjection(Context context) { - ContactsPreferences contactsPrefs = new ContactsPreferences(context); - boolean displayOrderPrimary = - (contactsPrefs.getDisplayOrder() == ContactsPreferences.DISPLAY_ORDER_PRIMARY); - return displayOrderPrimary - ? CONTACTS_PROJECTION_DISPLAY_NAME_PRIMARY - : CONTACTS_PROJECTION_DISPLAY_NAME_ALTERNATIVE; + switch (ContactsComponent.get(context).contactDisplayPreferences().getDisplayOrder()) { + case PRIMARY: + return CONTACTS_PROJECTION_DISPLAY_NAME_PRIMARY; + case ALTERNATIVE: + return CONTACTS_PROJECTION_DISPLAY_NAME_ALTERNATIVE; + } + throw new AssertionError("exhaustive switch"); } private static String getWhere(Context context, boolean hasPhoneNumbers) { @@ -78,10 +79,14 @@ final class ContactsCursorLoader extends CursorLoader { } private static String getSortKey(Context context) { - ContactsPreferences contactsPrefs = new ContactsPreferences(context); - boolean sortOrderPrimary = - (contactsPrefs.getSortOrder() == ContactsPreferences.SORT_ORDER_PRIMARY); - return sortOrderPrimary ? Contacts.SORT_KEY_PRIMARY : Contacts.SORT_KEY_ALTERNATIVE; + + switch (ContactsComponent.get(context).contactDisplayPreferences().getSortOrder()) { + case BY_PRIMARY: + return Contacts.SORT_KEY_PRIMARY; + case BY_ALTERNATIVE: + return Contacts.SORT_KEY_ALTERNATIVE; + } + throw new AssertionError("exhaustive switch"); } /** Update cursor loader to filter contacts based on the provided query. */ |