Update content description after updating primary

Here's what went wrong: we set content description of photos in
CompactRawContactsEditorView.getPhotos() (see ag/834274) and then
we modify "primary" before entering photo picker (see ag/854600).

We need to update content description of photos after modifying
"primary" to reflect the change in which photo is checked.

Bug 27881948

Change-Id: Iad9723c9adbeaf8396fc46c578cc4a519d9ba85a
(cherry picked from commit 5a59c26c4e43fedcd449dfae97ea435f1ce885e3)
diff --git a/src/com/android/contacts/editor/CompactContactEditorFragment.java b/src/com/android/contacts/editor/CompactContactEditorFragment.java
index e441264..4a731db 100644
--- a/src/com/android/contacts/editor/CompactContactEditorFragment.java
+++ b/src/com/android/contacts/editor/CompactContactEditorFragment.java
@@ -261,6 +261,25 @@
             } else {
                 photo.primary = false;
             }
+            updateContentDescription(photo);
+        }
+    }
+
+    private void updateContentDescription(CompactPhotoSelectionFragment.Photo photo) {
+        if (!TextUtils.isEmpty(photo.accountType)) {
+            photo.contentDescription = getResources().getString(photo.primary ?
+                            R.string.photo_view_description_checked :
+                            R.string.photo_view_description_not_checked,
+                    photo.accountType, photo.accountName);
+            photo.contentDescriptionChecked = getResources().getString(
+                    R.string.photo_view_description_checked,
+                    photo.accountType, photo.accountName);
+        } else {
+            photo.contentDescription = getResources().getString(photo.primary ?
+                    R.string.photo_view_description_checked_no_info :
+                    R.string.photo_view_description_not_checked_no_info);
+            photo.contentDescriptionChecked = getResources().getString(
+                    R.string.photo_view_description_checked_no_info);
         }
     }
 
diff --git a/src/com/android/contacts/editor/CompactPhotoSelectionFragment.java b/src/com/android/contacts/editor/CompactPhotoSelectionFragment.java
index 3f157a4..0a8894f 100644
--- a/src/com/android/contacts/editor/CompactPhotoSelectionFragment.java
+++ b/src/com/android/contacts/editor/CompactPhotoSelectionFragment.java
@@ -95,6 +95,8 @@
 
         public String contentDescription;
         public String contentDescriptionChecked; // Talkback announcement when the photo is checked
+        public String accountType;
+        public String accountName;
 
         public ValuesDelta valuesDelta;
 
diff --git a/src/com/android/contacts/editor/CompactRawContactsEditorView.java b/src/com/android/contacts/editor/CompactRawContactsEditorView.java
index 72f1c66..ece3829 100644
--- a/src/com/android/contacts/editor/CompactRawContactsEditorView.java
+++ b/src/com/android/contacts/editor/CompactRawContactsEditorView.java
@@ -554,27 +554,10 @@
                             kindSectionData.getRawContactDelta().getRawContactId()));
                 }
 
-                // set content descriptions of the photo
-                final CharSequence accountTypeText = accountType.getDisplayLabel(getContext());
-                if (accountTypeText != null) {
-                    final String accountNameText =
-                            kindSectionData.getRawContactDelta().getAccountName();
-                    photo.contentDescription = getResources().getString(photo.primary ?
-                                    R.string.photo_view_description_checked :
-                                    R.string.photo_view_description_not_checked,
-                            accountTypeText,
-                            accountNameText == null ? "" : accountNameText);
-                    photo.contentDescriptionChecked = getResources().getString(
-                            R.string.photo_view_description_checked,
-                            accountTypeText,
-                            accountNameText == null ? "" : accountNameText);
-                } else {
-                    photo.contentDescription = getResources().getString(photo.primary ?
-                            R.string.photo_view_description_checked_no_info :
-                            R.string.photo_view_description_not_checked_no_info);
-                    photo.contentDescriptionChecked = getResources().getString(
-                            R.string.photo_view_description_checked_no_info);
-                }
+                final CharSequence accountTypeLabel = accountType.getDisplayLabel(getContext());
+                photo.accountType = accountTypeLabel == null ? "" : accountTypeLabel.toString();
+                final String accountName = kindSectionData.getRawContactDelta().getAccountName();
+                photo.accountName = accountName == null ? "" : accountName;
 
                 photos.add(photo);
             }