Fix bug when adding an empty editor type in Editor UI.
For both compact editor and full editor, using the method
in RawContactModifier to check if an empty editor type should
be inserted, since that method would check not only overall number,
but also the limit for each specific type.
BUG 22521808
Change-Id: Iefe401f26aec8d8cece4723c0486d3add6732f74
diff --git a/src/com/android/contacts/editor/CompactKindSectionView.java b/src/com/android/contacts/editor/CompactKindSectionView.java
index bab6fe3..7e5ff11 100644
--- a/src/com/android/contacts/editor/CompactKindSectionView.java
+++ b/src/com/android/contacts/editor/CompactKindSectionView.java
@@ -542,10 +542,11 @@
}
// Determine if we should add a new empty editor
final DataKind dataKind = mKindSectionDataList.get(0).getDataKind();
+ final RawContactDelta rawContactDelta =
+ mKindSectionDataList.get(0).getRawContactDelta();
if (dataKind == null // There is nothing we can do.
// We have already reached the maximum number of editors, don't add any more.
- || (dataKind.typeOverallMax == mEditors.getChildCount()
- && dataKind.typeOverallMax != 0)
+ || !RawContactModifier.canInsert(rawContactDelta, dataKind)
// We have already reached the maximum number of empty editors, don't add any more.
|| emptyEditors.size() == 1) {
return;
@@ -556,8 +557,6 @@
if (Nickname.CONTENT_ITEM_TYPE.equals(mimeType) && mEditors.getChildCount() > 0) {
return;
}
- final RawContactDelta rawContactDelta =
- mKindSectionDataList.get(0).getRawContactDelta();
final ValuesDelta values = RawContactModifier.insertChild(rawContactDelta, dataKind);
final Editor.EditorListener editorListener = Event.CONTENT_ITEM_TYPE.equals(mimeType)
? new EventEditorListener() : new NonNameEditorListener();
diff --git a/src/com/android/contacts/editor/KindSectionView.java b/src/com/android/contacts/editor/KindSectionView.java
index ee11645..e612361 100644
--- a/src/com/android/contacts/editor/KindSectionView.java
+++ b/src/com/android/contacts/editor/KindSectionView.java
@@ -249,7 +249,7 @@
} else if (isReadOnly()) {
// We don't show empty editors for read only data kinds.
return;
- } else if (mKind.typeOverallMax == getEditorCount() && mKind.typeOverallMax != 0) {
+ } else if (!RawContactModifier.canInsert(mState, mKind)) {
// We have already reached the maximum number of editors. Lets not add any more.
return;
} else if (emptyEditors.size() == 1) {