summaryrefslogtreecommitdiff
path: root/java/com/android/incallui
diff options
context:
space:
mode:
authortwyen <twyen@google.com>2018-06-25 12:36:26 -0700
committerCopybara-Service <copybara-piper@google.com>2018-06-26 13:42:08 -0700
commit5578d928bf777f721ec0ec04c84ddb7d3ea56edb (patch)
tree150f643cf67aee21a2ac730d3f7b1f6cada7db47 /java/com/android/incallui
parent03bacec1394032712c534605476fb634b85eee28 (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/incallui')
-rw-r--r--java/com/android/incallui/CallCardPresenter.java13
-rw-r--r--java/com/android/incallui/ConferenceParticipantListAdapter.java26
-rw-r--r--java/com/android/incallui/ContactsPreferencesFactory.java56
-rw-r--r--java/com/android/incallui/ExternalCallNotifier.java19
-rw-r--r--java/com/android/incallui/ReturnToCallController.java9
-rw-r--r--java/com/android/incallui/RttRequestDialogFragment.java9
-rw-r--r--java/com/android/incallui/StatusBarNotifier.java10
7 files changed, 32 insertions, 110 deletions
diff --git a/java/com/android/incallui/CallCardPresenter.java b/java/com/android/incallui/CallCardPresenter.java
index 91255cc7e..b9e6744ea 100644
--- a/java/com/android/incallui/CallCardPresenter.java
+++ b/java/com/android/incallui/CallCardPresenter.java
@@ -44,11 +44,10 @@ import android.view.View;
import android.view.accessibility.AccessibilityEvent;
import android.view.accessibility.AccessibilityManager;
import com.android.contacts.common.ContactsUtils;
-import com.android.contacts.common.preference.ContactsPreferences;
-import com.android.contacts.common.util.ContactDisplayUtils;
import com.android.dialer.common.Assert;
import com.android.dialer.common.LogUtil;
import com.android.dialer.configprovider.ConfigProviderComponent;
+import com.android.dialer.contacts.ContactsComponent;
import com.android.dialer.logging.DialerImpression;
import com.android.dialer.logging.Logger;
import com.android.dialer.multimedia.MultimediaData;
@@ -123,7 +122,6 @@ public class CallCardPresenter
private String secondaryNumber;
private ContactCacheEntry primaryContactInfo;
private ContactCacheEntry secondaryContactInfo;
- @Nullable private ContactsPreferences contactsPreferences;
private boolean isFullscreen = false;
private InCallScreen inCallScreen;
private boolean isInCallScreenReady;
@@ -159,7 +157,6 @@ public class CallCardPresenter
public void onInCallScreenDelegateInit(InCallScreen inCallScreen) {
Assert.isNotNull(inCallScreen);
this.inCallScreen = inCallScreen;
- contactsPreferences = ContactsPreferencesFactory.newContactsPreferences(context);
// Call may be null if disconnect happened already.
DialerCall call = CallList.getInstance().getFirstCall();
@@ -184,9 +181,6 @@ public class CallCardPresenter
public void onInCallScreenReady() {
LogUtil.i("CallCardPresenter.onInCallScreenReady", null);
Assert.checkState(!isInCallScreenReady);
- if (contactsPreferences != null) {
- contactsPreferences.refreshValue(ContactsPreferences.DISPLAY_ORDER_KEY);
- }
// Contact search may have completed before ui is ready.
if (primaryContactInfo != null) {
@@ -985,8 +979,9 @@ public class CallCardPresenter
/** Gets the name to display for the call. */
private String getNameForCall(ContactCacheEntry contactInfo) {
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
diff --git a/java/com/android/incallui/ConferenceParticipantListAdapter.java b/java/com/android/incallui/ConferenceParticipantListAdapter.java
index c71bf59b2..d13bd3d5a 100644
--- a/java/com/android/incallui/ConferenceParticipantListAdapter.java
+++ b/java/com/android/incallui/ConferenceParticipantListAdapter.java
@@ -18,7 +18,6 @@ package com.android.incallui;
import android.content.Context;
import android.net.Uri;
-import android.support.annotation.Nullable;
import android.support.v4.util.ArrayMap;
import android.telephony.PhoneNumberUtils;
import android.text.BidiFormatter;
@@ -33,11 +32,10 @@ import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.TextView;
-import com.android.contacts.common.preference.ContactsPreferences;
-import com.android.contacts.common.util.ContactDisplayUtils;
import com.android.dialer.common.LogUtil;
import com.android.dialer.contactphoto.ContactPhotoManager;
import com.android.dialer.contactphoto.ContactPhotoManager.DefaultImageRequest;
+import com.android.dialer.contacts.ContactsComponent;
import com.android.incallui.ContactInfoCache.ContactCacheEntry;
import com.android.incallui.call.CallList;
import com.android.incallui.call.DialerCall;
@@ -59,8 +57,6 @@ public class ConferenceParticipantListAdapter extends BaseAdapter {
private final ListView listView;
/** Hashmap to make accessing participant info by call Id faster. */
private final Map<String, ParticipantInfo> participantsByCallId = new ArrayMap<>();
- /** ContactsPreferences used to lookup displayName preferences */
- @Nullable private final ContactsPreferences contactsPreferences;
/** Contact photo manager to retrieve cached contact photo information. */
private final ContactPhotoManager contactPhotoManager;
/** Listener used to handle tap of the "disconnect' button for a participant. */
@@ -103,7 +99,6 @@ public class ConferenceParticipantListAdapter extends BaseAdapter {
ListView listView, ContactPhotoManager contactPhotoManager) {
this.listView = listView;
- contactsPreferences = ContactsPreferencesFactory.newContactsPreferences(getContext());
this.contactPhotoManager = contactPhotoManager;
}
@@ -116,10 +111,6 @@ public class ConferenceParticipantListAdapter extends BaseAdapter {
*/
public void updateParticipants(
List<DialerCall> conferenceParticipants, boolean parentCanSeparate) {
- if (contactsPreferences != null) {
- contactsPreferences.refreshValue(ContactsPreferences.DISPLAY_ORDER_KEY);
- contactsPreferences.refreshValue(ContactsPreferences.SORT_ORDER_KEY);
- }
this.parentCanSeparate = parentCanSeparate;
updateParticipantInfo(conferenceParticipants);
}
@@ -235,8 +226,9 @@ public class ConferenceParticipantListAdapter extends BaseAdapter {
call.can(android.telecom.Call.Details.CAPABILITY_DISCONNECT_FROM_CONFERENCE);
String name =
- ContactDisplayUtils.getPreferredDisplayName(
- contactCache.namePrimary, contactCache.nameAlternative, contactsPreferences);
+ ContactsComponent.get(getContext())
+ .contactDisplayPreferences()
+ .getDisplayName(contactCache.namePrimary, contactCache.nameAlternative);
setCallerInfoForRow(
result,
@@ -441,14 +433,16 @@ public class ConferenceParticipantListAdapter extends BaseAdapter {
// Contact names might be null, so replace with empty string.
ContactCacheEntry c1 = p1.getContactCacheEntry();
String p1Name =
- ContactDisplayUtils.getPreferredSortName(
- c1.namePrimary, c1.nameAlternative, contactsPreferences);
+ ContactsComponent.get(getContext())
+ .contactDisplayPreferences()
+ .getSortName(c1.namePrimary, c1.nameAlternative);
p1Name = p1Name != null ? p1Name : "";
ContactCacheEntry c2 = p2.getContactCacheEntry();
String p2Name =
- ContactDisplayUtils.getPreferredSortName(
- c2.namePrimary, c2.nameAlternative, contactsPreferences);
+ ContactsComponent.get(getContext())
+ .contactDisplayPreferences()
+ .getSortName(c2.namePrimary, c2.nameAlternative);
p2Name = p2Name != null ? p2Name : "";
return p1Name.compareToIgnoreCase(p2Name);
diff --git a/java/com/android/incallui/ContactsPreferencesFactory.java b/java/com/android/incallui/ContactsPreferencesFactory.java
deleted file mode 100644
index a9a210963..000000000
--- a/java/com/android/incallui/ContactsPreferencesFactory.java
+++ /dev/null
@@ -1,56 +0,0 @@
-/*
- * Copyright (C) 2016 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License
- */
-
-package com.android.incallui;
-
-import android.content.Context;
-import android.support.annotation.Nullable;
-import android.support.v4.os.UserManagerCompat;
-import com.android.contacts.common.preference.ContactsPreferences;
-
-/** Factory class for {@link ContactsPreferences}. */
-public class ContactsPreferencesFactory {
-
- private static boolean useTestInstance;
- private static ContactsPreferences testInstance;
-
- /**
- * Creates a new {@link ContactsPreferences} object if possible.
- *
- * @param context the context to use when creating the ContactsPreferences.
- * @return a new ContactsPreferences object or {@code null} if the user is locked.
- */
- @Nullable
- public static ContactsPreferences newContactsPreferences(Context context) {
- if (useTestInstance) {
- return testInstance;
- }
- if (UserManagerCompat.isUserUnlocked(context)) {
- return new ContactsPreferences(context);
- }
- return null;
- }
-
- /**
- * Sets the instance to be returned by all calls to {@link #newContactsPreferences(Context)}.
- *
- * @param testInstance the instance to return.
- */
- static void setTestInstance(ContactsPreferences testInstance) {
- useTestInstance = true;
- ContactsPreferencesFactory.testInstance = testInstance;
- }
-}
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<Call, NotificationInfo> 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
diff --git a/java/com/android/incallui/ReturnToCallController.java b/java/com/android/incallui/ReturnToCallController.java
index 94ce8d7af..addde55f0 100644
--- a/java/com/android/incallui/ReturnToCallController.java
+++ b/java/com/android/incallui/ReturnToCallController.java
@@ -30,9 +30,9 @@ import com.android.bubble.Bubble;
import com.android.bubble.BubbleComponent;
import com.android.bubble.BubbleInfo;
import com.android.bubble.BubbleInfo.Action;
-import com.android.contacts.common.util.ContactDisplayUtils;
import com.android.dialer.common.LogUtil;
import com.android.dialer.configprovider.ConfigProviderComponent;
+import com.android.dialer.contacts.ContactsComponent;
import com.android.dialer.lettertile.LetterTileDrawable;
import com.android.dialer.telecom.TelecomUtil;
import com.android.dialer.theme.base.ThemeComponent;
@@ -369,10 +369,9 @@ public class ReturnToCallController implements InCallUiListener, Listener, Audio
private LetterTileDrawable createLettleTileDrawable(
DialerCall dialerCall, ContactCacheEntry entry) {
String preferredName =
- ContactDisplayUtils.getPreferredDisplayName(
- entry.namePrimary,
- entry.nameAlternative,
- ContactsPreferencesFactory.newContactsPreferences(context));
+ ContactsComponent.get(context)
+ .contactDisplayPreferences()
+ .getDisplayName(entry.namePrimary, entry.nameAlternative);
if (TextUtils.isEmpty(preferredName)) {
preferredName = entry.number;
}
diff --git a/java/com/android/incallui/RttRequestDialogFragment.java b/java/com/android/incallui/RttRequestDialogFragment.java
index 5437cc699..589625b8e 100644
--- a/java/com/android/incallui/RttRequestDialogFragment.java
+++ b/java/com/android/incallui/RttRequestDialogFragment.java
@@ -28,9 +28,9 @@ import android.text.TextDirectionHeuristics;
import android.text.TextUtils;
import android.view.View;
import android.widget.TextView;
-import com.android.contacts.common.util.ContactDisplayUtils;
import com.android.dialer.common.Assert;
import com.android.dialer.common.LogUtil;
+import com.android.dialer.contacts.ContactsComponent;
import com.android.incallui.ContactInfoCache.ContactCacheEntry;
import com.android.incallui.ContactInfoCache.ContactInfoCacheCallback;
import com.android.incallui.call.CallList;
@@ -130,10 +130,9 @@ public class RttRequestDialogFragment extends DialogFragment {
private CharSequence getNameOrNumber(ContactCacheEntry entry, Context context) {
String preferredName =
- ContactDisplayUtils.getPreferredDisplayName(
- entry.namePrimary,
- entry.nameAlternative,
- ContactsPreferencesFactory.newContactsPreferences(context));
+ ContactsComponent.get(context)
+ .contactDisplayPreferences()
+ .getDisplayName(entry.namePrimary, entry.nameAlternative);
if (TextUtils.isEmpty(preferredName)) {
return TextUtils.isEmpty(entry.number)
? null
diff --git a/java/com/android/incallui/StatusBarNotifier.java b/java/com/android/incallui/StatusBarNotifier.java
index 1d73fe8e7..8316d76ee 100644
--- a/java/com/android/incallui/StatusBarNotifier.java
+++ b/java/com/android/incallui/StatusBarNotifier.java
@@ -64,12 +64,11 @@ import android.text.TextUtils;
import android.text.style.ForegroundColorSpan;
import com.android.contacts.common.ContactsUtils;
import com.android.contacts.common.ContactsUtils.UserType;
-import com.android.contacts.common.preference.ContactsPreferences;
-import com.android.contacts.common.util.ContactDisplayUtils;
import com.android.dialer.common.Assert;
import com.android.dialer.common.LogUtil;
import com.android.dialer.configprovider.ConfigProviderComponent;
import com.android.dialer.contactphoto.BitmapUtil;
+import com.android.dialer.contacts.ContactsComponent;
import com.android.dialer.enrichedcall.EnrichedCallManager;
import com.android.dialer.enrichedcall.Session;
import com.android.dialer.lettertile.LetterTileDrawable;
@@ -121,7 +120,6 @@ public class StatusBarNotifier
private final Context context;
private final ContactInfoCache contactInfoCache;
private final DialerRingtoneManager dialerRingtoneManager;
- @Nullable private ContactsPreferences contactsPreferences;
private int currentNotification = NOTIFICATION_NONE;
private int callState = DialerCallState.INVALID;
private int videoState = VideoProfile.STATE_AUDIO_ONLY;
@@ -136,7 +134,6 @@ public class StatusBarNotifier
public StatusBarNotifier(@NonNull Context context, @NonNull ContactInfoCache contactInfoCache) {
Trace.beginSection("StatusBarNotifier.Constructor");
this.context = Assert.isNotNull(context);
- contactsPreferences = ContactsPreferencesFactory.newContactsPreferences(this.context);
this.contactInfoCache = contactInfoCache;
dialerRingtoneManager =
new DialerRingtoneManager(
@@ -565,8 +562,9 @@ public class StatusBarNotifier
}
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