Fixing handling of single-item data kinds.
The bug was that if we had an existing row
for a single-item kind like nickname,
but that row was empty and therefore invisible,
we would allow the UI to create another,
visible row.
The fix finds that invisible row if it exists
and makes it visible thus eliminating duplication.
Bug: 3334481
Change-Id: Ic639e5ae42b485fe6830078e5043a4f10b757086
diff --git a/src/com/android/contacts/editor/KindSectionView.java b/src/com/android/contacts/editor/KindSectionView.java
index 77484ce..4ce8dda 100644
--- a/src/com/android/contacts/editor/KindSectionView.java
+++ b/src/com/android/contacts/editor/KindSectionView.java
@@ -34,6 +34,8 @@
import android.widget.LinearLayout;
import android.widget.TextView;
+import java.util.ArrayList;
+
/**
* Custom view for an entire section of data as segmented by
* {@link DataKind} around a {@link Data#MIMETYPE}. This view shows a
@@ -247,13 +249,26 @@
}
public void addItem() {
+ ValuesDelta values = null;
// if this is a list, we can freely add. if not, only allow adding the first
- if (!mKind.isList && getEditorCount() == 1)
- return;
+ if (!mKind.isList) {
+ if (getEditorCount() == 1) {
+ return;
+ }
+
+ // If we already have an item, just make it visible
+ ArrayList<ValuesDelta> entries = mState.getMimeEntries(mKind.mimeType);
+ if (entries != null && entries.size() > 0) {
+ values = entries.get(0);
+ }
+ }
// Insert a new child, create its view and set its focus
- final ValuesDelta newValues = EntityModifier.insertChild(mState, mKind);
- final View newField = createEditorView(newValues);
+ if (values == null) {
+ values = EntityModifier.insertChild(mState, mKind);
+ }
+
+ final View newField = createEditorView(values);
newField.requestFocus();
// For non-lists (e.g. Notes we can only have one field. in that case we need to disable