resolve merge conflicts of cf7f295 to master

Change-Id: I49249472948c29b97be8fe33cda8fa022d8e62f6
diff --git a/src/com/android/contacts/editor/CompactRawContactsEditorView.java b/src/com/android/contacts/editor/CompactRawContactsEditorView.java
index 1683bef..bdf329d 100644
--- a/src/com/android/contacts/editor/CompactRawContactsEditorView.java
+++ b/src/com/android/contacts/editor/CompactRawContactsEditorView.java
@@ -31,6 +31,7 @@
 import com.android.contacts.common.util.MaterialColorMapUtils;
 import com.android.contacts.util.UiClosables;
 
+import android.animation.LayoutTransition;
 import android.content.ContentUris;
 import android.content.Context;
 import android.database.Cursor;
@@ -622,12 +623,19 @@
             AccountWithDataSet primaryAccount, long rawContactIdToDisplayAlone,
             boolean rawContactDisplayAloneIsReadOnly,
             boolean isEditingReadOnlyRawContactWithNewContact) {
+        // Enable layout animations for new contacts. This looks nicer when switching to and from
+        // an account that doesn't support profile photos (e.g. SIM accounts).
+        if (hasNewContact && getLayoutTransition() == null) {
+            setLayoutTransition(new LayoutTransition());
+        }
+
         mRawContactDeltas = rawContactDeltas;
         mRawContactIdToDisplayAlone = rawContactIdToDisplayAlone;
         mRawContactDisplayAloneIsReadOnly = rawContactDisplayAloneIsReadOnly;
         mIsEditingReadOnlyRawContactWithNewContact = isEditingReadOnlyRawContactWithNewContact;
 
         mKindSectionDataMap.clear();
+        mKindSectionViewsMap.clear();
         mKindSectionViews.removeAllViews();
         mMoreFields.setVisibility(View.VISIBLE);
 
@@ -656,9 +664,11 @@
             return;
         }
 
+
         // Get the primary name kind section data
-        mPrimaryNameKindSectionData = mKindSectionDataMap.get(StructuredName.CONTENT_ITEM_TYPE)
-                .getEntryToWrite(/* id =*/ -1, mPrimaryAccount, mIsUserProfile);
+        mPrimaryNameKindSectionData =
+                getOrCreateKindSectionDataList(StructuredName.CONTENT_ITEM_TYPE)
+                        .getEntryToWrite(/* id =*/ -1, mPrimaryAccount, mIsUserProfile);
         if (mPrimaryNameKindSectionData != null) {
             // Ensure that a structured name and photo exists
             final RawContactDelta rawContactDelta =
@@ -707,6 +717,9 @@
     private void setupCompactEditorNormally() {
         addAccountInfo(mRawContactDeltas);
         addKindSectionViews();
+
+        mMoreFields.setVisibility(hasMoreFields() ? View.VISIBLE : View.GONE);
+
         if (mIsExpanded) showAllFields();
     }
 
@@ -978,13 +991,15 @@
     private void addPhotoView() {
         // Get the kind section data and values delta that we will display in the photo view
         final KindSectionDataList kindSectionDataList =
-                mKindSectionDataMap.get(Photo.CONTENT_ITEM_TYPE);
+                getOrCreateKindSectionDataList(Photo.CONTENT_ITEM_TYPE);
         final Pair<KindSectionData,ValuesDelta> photoToDisplay =
                 kindSectionDataList.getEntryToDisplay(mPhotoId);
         if (photoToDisplay == null) {
             wlog("photo: no kind section data parsed");
             mPhotoView.setVisibility(View.GONE);
             return;
+        } else {
+            mPhotoView.setVisibility(View.VISIBLE);
         }
 
         // Set the photo view
@@ -1132,6 +1147,17 @@
         mMoreFields.setVisibility(View.GONE);
     }
 
+    private boolean hasMoreFields() {
+        for (List<CompactKindSectionView> sections : mKindSectionViewsMap.values()) {
+            for (CompactKindSectionView section : sections) {
+                if (section.getVisibility() != View.VISIBLE) {
+                    return true;
+                }
+            }
+        }
+        return false;
+    }
+
     private static void vlog(String message) {
         if (Log.isLoggable(TAG, Log.VERBOSE)) {
             Log.v(TAG, message);