From 5578d928bf777f721ec0ec04c84ddb7d3ea56edb Mon Sep 17 00:00:00 2001 From: twyen Date: Mon, 25 Jun 2018 12:36:26 -0700 Subject: 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 --- java/com/android/incallui/ExternalCallNotifier.java | 19 ++++++------------- 1 file changed, 6 insertions(+), 13 deletions(-) (limited to 'java/com/android/incallui/ExternalCallNotifier.java') diff --git a/java/com/android/incallui/ExternalCallNotifier.java b/java/com/android/incallui/ExternalCallNotifier.java index 10c4a6490..160e2502f 100644 --- a/java/com/android/incallui/ExternalCallNotifier.java +++ b/java/com/android/incallui/ExternalCallNotifier.java @@ -38,10 +38,9 @@ import android.text.TextUtils; import android.util.ArrayMap; import com.android.contacts.common.ContactsUtils; import com.android.contacts.common.compat.CallCompat; -import com.android.contacts.common.preference.ContactsPreferences; -import com.android.contacts.common.util.ContactDisplayUtils; import com.android.dialer.common.Assert; import com.android.dialer.contactphoto.BitmapUtil; +import com.android.dialer.contacts.ContactsComponent; import com.android.dialer.notification.DialerNotificationManager; import com.android.dialer.notification.NotificationChannelId; import com.android.dialer.telecom.TelecomCallUtil; @@ -78,13 +77,11 @@ public class ExternalCallNotifier implements ExternalCallList.ExternalCallListen private final ContactInfoCache contactInfoCache; private Map notifications = new ArrayMap<>(); private int nextUniqueNotificationId; - private ContactsPreferences contactsPreferences; /** Initializes a new instance of the external call notifier. */ public ExternalCallNotifier( @NonNull Context context, @NonNull ContactInfoCache contactInfoCache) { this.context = context; - contactsPreferences = ContactsPreferencesFactory.newContactsPreferences(this.context); this.contactInfoCache = contactInfoCache; } @@ -216,7 +213,7 @@ public class ExternalCallNotifier implements ExternalCallList.ExternalCallListen * notification to the notification manager. */ private void saveContactInfo(NotificationInfo info, ContactInfoCache.ContactCacheEntry entry) { - info.setContentTitle(getContentTitle(context, contactsPreferences, entry, info.getCall())); + info.setContentTitle(getContentTitle(context, entry, info.getCall())); info.setPersonReference(getPersonReference(entry, info.getCall())); postNotification(info); } @@ -342,17 +339,12 @@ public class ExternalCallNotifier implements ExternalCallList.ExternalCallListen * number. * * @param context The context. - * @param contactsPreferences Contacts preferences, used to determine the preferred formatting for - * contact names. * @param contactInfo The contact info which was looked up in the contact cache. * @param call The call to generate a title for. * @return The content title. */ private @Nullable String getContentTitle( - Context context, - @Nullable ContactsPreferences contactsPreferences, - ContactInfoCache.ContactCacheEntry contactInfo, - android.telecom.Call call) { + Context context, ContactInfoCache.ContactCacheEntry contactInfo, android.telecom.Call call) { if (call.getDetails().hasProperty(android.telecom.Call.Details.PROPERTY_CONFERENCE)) { return CallerInfoUtils.getConferenceString( @@ -361,8 +353,9 @@ public class ExternalCallNotifier implements ExternalCallList.ExternalCallListen } String preferredName = - ContactDisplayUtils.getPreferredDisplayName( - contactInfo.namePrimary, contactInfo.nameAlternative, contactsPreferences); + ContactsComponent.get(context) + .contactDisplayPreferences() + .getDisplayName(contactInfo.namePrimary, contactInfo.nameAlternative); if (TextUtils.isEmpty(preferredName)) { return TextUtils.isEmpty(contactInfo.number) ? null -- cgit v1.2.3