Move setPhoto logic to CallLogListItemViews.

Bug: 19372817
Change-Id: Icddc1edd2ca1ad040a03726471a19ddc9d434d4d
diff --git a/src/com/android/dialer/calllog/CallLogAdapter.java b/src/com/android/dialer/calllog/CallLogAdapter.java
index d1a164a..ff841e6 100644
--- a/src/com/android/dialer/calllog/CallLogAdapter.java
+++ b/src/com/android/dialer/calllog/CallLogAdapter.java
@@ -42,8 +42,6 @@
 import android.widget.TextView;
 
 import com.android.common.widget.GroupingListAdapter;
-import com.android.contacts.common.ContactPhotoManager;
-import com.android.contacts.common.ContactPhotoManager.DefaultImageRequest;
 import com.android.contacts.common.util.UriUtils;
 import com.android.dialer.PhoneCallDetails;
 import com.android.dialer.PhoneCallDetailsHelper;
@@ -241,8 +239,6 @@
     /** Instance of helper class for managing views. */
     private final CallLogListItemHelper mCallLogViewsHelper;
 
-    /** Helper to set up contact photos. */
-    private final ContactPhotoManager mContactPhotoManager;
     /** Helper to parse and process phone numbers. */
     private PhoneNumberDisplayHelper mPhoneNumberHelper;
     /** Helper to access Telephony phone number utils class */
@@ -255,8 +251,6 @@
     /** Can be set to true by tests to disable processing of requests. */
     private volatile boolean mRequestProcessingDisabled = false;
 
-    private int mPhotoSize;
-
     /** Listener for the primary or secondary actions in the list.
      *  Primary opens the call details.
      *  Secondary calls or plays.
@@ -344,9 +338,7 @@
 
         Resources resources = mContext.getResources();
         CallTypeHelper callTypeHelper = new CallTypeHelper(resources);
-        mPhotoSize = resources.getDimensionPixelSize(R.dimen.contact_photo_size);
 
-        mContactPhotoManager = ContactPhotoManager.getInstance(mContext);
         mPhoneNumberHelper = new PhoneNumberDisplayHelper(mContext, resources);
         mPhoneNumberUtilsWrapper = new PhoneNumberUtilsWrapper(mContext);
         PhoneCallDetailsHelper phoneCallDetailsHelper =
@@ -744,17 +736,6 @@
 
         mCallLogViewsHelper.setPhoneCallDetails(mContext, views, details);
 
-        int contactType = ContactPhotoManager.TYPE_DEFAULT;
-
-        if (isVoicemailNumber) {
-            contactType = ContactPhotoManager.TYPE_VOICEMAIL;
-        } else if (mContactInfoHelper.isBusiness(info.sourceType)) {
-            contactType = ContactPhotoManager.TYPE_BUSINESS;
-        }
-
-        String lookupKey = lookupUri == null ? null
-                : ContactInfoHelper.getLookupKeyFromUri(lookupUri);
-
         String nameForDefaultImage = null;
         if (TextUtils.isEmpty(name)) {
             nameForDefaultImage = mPhoneNumberHelper.getDisplayNumber(details.accountHandle,
@@ -763,11 +744,8 @@
             nameForDefaultImage = name;
         }
 
-        if (photoId == 0 && photoUri != null) {
-            setPhoto(views, photoUri, lookupUri, nameForDefaultImage, lookupKey, contactType);
-        } else {
-            setPhoto(views, photoId, lookupUri, nameForDefaultImage, lookupKey, contactType);
-        }
+        views.setPhoto(photoId, photoUri, lookupUri, nameForDefaultImage, isVoicemailNumber,
+                mContactInfoHelper.isBusiness(info.sourceType));
         views.quickContactView.setPrioritizedMimeType(Phone.CONTENT_ITEM_TYPE);
 
         // Listen for the first draw
@@ -809,6 +787,7 @@
         }
         return CallLogGroupBuilder.DAY_GROUP_NONE;
     }
+
     /**
      * Determines if a call log row with the given Id is expanded.
      * @param rowId The row Id of the call.
@@ -987,26 +966,6 @@
         return features;
     }
 
-    private void setPhoto(CallLogListItemViews views, long photoId, Uri contactUri,
-            String displayName, String identifier, int contactType) {
-        views.quickContactView.assignContactUri(contactUri);
-        views.quickContactView.setOverlay(null);
-        DefaultImageRequest request = new DefaultImageRequest(displayName, identifier,
-                contactType, true /* isCircular */);
-        mContactPhotoManager.loadThumbnail(views.quickContactView, photoId, false /* darkTheme */,
-                true /* isCircular */, request);
-    }
-
-    private void setPhoto(CallLogListItemViews views, Uri photoUri, Uri contactUri,
-            String displayName, String identifier, int contactType) {
-        views.quickContactView.assignContactUri(contactUri);
-        views.quickContactView.setOverlay(null);
-        DefaultImageRequest request = new DefaultImageRequest(displayName, identifier,
-                contactType, true /* isCircular */);
-        mContactPhotoManager.loadPhoto(views.quickContactView, photoUri, mPhotoSize,
-                false /* darkTheme */, true /* isCircular */, request);
-    }
-
     /**
      * Bind a call log entry view for testing purposes.  Also inflates the action view stub so
      * unit tests can access the buttons contained within.
diff --git a/src/com/android/dialer/calllog/CallLogListItemViews.java b/src/com/android/dialer/calllog/CallLogListItemViews.java
index 427732e..9d11a3a 100644
--- a/src/com/android/dialer/calllog/CallLogListItemViews.java
+++ b/src/com/android/dialer/calllog/CallLogListItemViews.java
@@ -18,6 +18,7 @@
 
 import android.content.Context;
 import android.content.res.Resources;
+import android.net.Uri;
 import android.provider.CallLog.Calls;
 import android.telecom.PhoneAccountHandle;
 import android.text.TextUtils;
@@ -28,6 +29,8 @@
 import android.widget.TextView;
 
 import com.android.contacts.common.CallUtil;
+import com.android.contacts.common.ContactPhotoManager;
+import com.android.contacts.common.ContactPhotoManager.DefaultImageRequest;
 import com.android.contacts.common.testing.NeededForTesting;
 import com.android.dialer.PhoneCallDetailsViews;
 import com.android.dialer.R;
@@ -130,6 +133,7 @@
     private static final int VOICEMAIL_TRANSCRIPTION_MAX_LINES = 10;
 
     private Context mContext;
+    private int mPhotoSize;
 
     private int mCallLogBackgroundColor;
     private int mExpandedBackgroundColor;
@@ -156,6 +160,18 @@
         mCallLogBackgroundColor = resources.getColor(R.color.background_dialer_list_items);
         mExpandedBackgroundColor = resources.getColor(R.color.call_log_expanded_background_color);
         mExpandedTranslationZ = resources.getDimension(R.dimen.call_log_expanded_translation_z);
+        mPhotoSize = mContext.getResources().getDimensionPixelSize(R.dimen.contact_photo_size);
+    }
+
+    public static CallLogListItemViews fromView(Context context, View view) {
+        return new CallLogListItemViews(
+                context,
+                view,
+                (QuickContactBadge) view.findViewById(R.id.quick_contact_photo),
+                view.findViewById(R.id.primary_action_view),
+                PhoneCallDetailsViews.fromView(view),
+                view.findViewById(R.id.call_log_row),
+                (TextView) view.findViewById(R.id.call_log_day_group_label));
     }
 
     /**
@@ -335,15 +351,33 @@
         view.setSingleLine(!isExpanded);
     }
 
-    public static CallLogListItemViews fromView(Context context, View view) {
-        return new CallLogListItemViews(
-                context,
-                view,
-                (QuickContactBadge) view.findViewById(R.id.quick_contact_photo),
-                view.findViewById(R.id.primary_action_view),
-                PhoneCallDetailsViews.fromView(view),
-                view.findViewById(R.id.call_log_row),
-                (TextView) view.findViewById(R.id.call_log_day_group_label));
+    public void setPhoto(long photoId, Uri photoUri, Uri contactUri, String displayName,
+            boolean isVoicemail, boolean isBusiness) {
+        quickContactView.assignContactUri(contactUri);
+        quickContactView.setOverlay(null);
+
+        int contactType = ContactPhotoManager.TYPE_DEFAULT;
+        if (isVoicemail) {
+            contactType = ContactPhotoManager.TYPE_VOICEMAIL;
+        } else if (isBusiness) {
+            contactType = ContactPhotoManager.TYPE_BUSINESS;
+        }
+
+        String lookupKey = null;
+        if (contactUri != null) {
+            lookupKey = ContactInfoHelper.getLookupKeyFromUri(contactUri);
+        }
+
+        DefaultImageRequest request = new DefaultImageRequest(
+                displayName, lookupKey, contactType, true /* isCircular */);
+
+        if (photoId == 0 && photoUri != null) {
+            ContactPhotoManager.getInstance(mContext).loadPhoto(quickContactView, photoUri,
+                    mPhotoSize, false /* darkTheme */, true /* isCircular */, request);
+        } else {
+            ContactPhotoManager.getInstance(mContext).loadThumbnail(quickContactView, photoId,
+                    false /* darkTheme */, true /* isCircular */, request);
+        }
     }
 
     @NeededForTesting