Put back setting of photo from template

* Mistakenly remove it in ag/790426
* Also looks like we weren't setting from template it to true
  after removing the photo.
* Finally, don't set super primary on the local profile

Bug 24981999
Bug 19697372
Bug 23589603

Change-Id: I3e759d5ea75e10c62108728874b771446ac61631
diff --git a/src/com/android/contacts/editor/CompactRawContactsEditorView.java b/src/com/android/contacts/editor/CompactRawContactsEditorView.java
index b3e4349..5388810 100644
--- a/src/com/android/contacts/editor/CompactRawContactsEditorView.java
+++ b/src/com/android/contacts/editor/CompactRawContactsEditorView.java
@@ -503,7 +503,7 @@
     }
 
     public void removePhoto() {
-        mPhotoValuesDelta.setFromTemplate(false);
+        mPhotoValuesDelta.setFromTemplate(true);
         mPhotoValuesDelta.put(Photo.PHOTO, (byte[]) null);
 
         mPhotoView.removePhoto();
@@ -517,11 +517,15 @@
     }
 
     public void updatePhoto(Uri photoUri) {
-        // Unset primary for all photos
-        unsetSuperPrimary();
+        mPhotoValuesDelta.setFromTemplate(false);
 
-        // Mark the currently displayed photo as primary
-        mPhotoValuesDelta.setSuperPrimary(true);
+        if (!mIsUserProfile) {
+            // Unset primary for all photos
+            unsetSuperPrimary();
+
+            // Mark the currently displayed photo as primary
+            mPhotoValuesDelta.setSuperPrimary(true);
+        }
 
         mPhotoView.setFullSizedPhoto(photoUri);
     }
@@ -603,9 +607,6 @@
      * UI.
      */
     public void setPrimaryPhoto(CompactPhotoSelectionFragment.Photo photo) {
-        // Unset primary for all photos
-        unsetSuperPrimary();
-
         // Find the values delta to mark as primary
         final KindSectionDataList kindSectionDataList =
                 mKindSectionDataMap.get(Photo.CONTENT_ITEM_TYPE);
@@ -623,7 +624,13 @@
         }
         final ValuesDelta valuesDelta = valuesDeltaList.get(photo.valuesDeltaListIndex);
         valuesDelta.setFromTemplate(false);
-        valuesDelta.setSuperPrimary(true);
+
+        if (!mIsUserProfile) {
+            // Unset primary for all other photos
+            unsetSuperPrimary();
+
+            valuesDelta.setSuperPrimary(true);
+        }
 
         // Update the UI
         mPhotoView.setPhoto(valuesDelta, mMaterialPalette);
@@ -1029,6 +1036,7 @@
         final CompactKindSectionView kindSectionView = (CompactKindSectionView)
                 mLayoutInflater.inflate(R.layout.compact_item_kind_section, viewGroup,
                         /* attachToRoot =*/ false);
+        kindSectionView.setIsUserProfile(mIsUserProfile);
 
         if (Phone.CONTENT_ITEM_TYPE.equals(mimeType)
                 || Email.CONTENT_ITEM_TYPE.equals(mimeType)) {