Restore birthday label after deleting an existing birthday
Once user removes a birthday editor, we update the editor at the bottom
to be "birthday".
Bug: 23959614
Change-Id: I650ac70f67e190a8e544d9010eda942694bec0fe
diff --git a/src/com/android/contacts/editor/CompactKindSectionView.java b/src/com/android/contacts/editor/CompactKindSectionView.java
index a5f159c..448e7c5 100644
--- a/src/com/android/contacts/editor/CompactKindSectionView.java
+++ b/src/com/android/contacts/editor/CompactKindSectionView.java
@@ -101,7 +101,7 @@
* Whether a new empty editor is added is controlled by {@link #setShowOneEmptyEditor} and
* {@link #setHideWhenEmpty}.
*/
- private final class NonNameEditorListener implements Editor.EditorListener {
+ private class NonNameEditorListener implements Editor.EditorListener {
@Override
public void onRequest(int request) {
@@ -124,6 +124,27 @@
}
}
+ private class EventEditorListener extends NonNameEditorListener {
+
+ @Override
+ public void onRequest(int request) {
+ super.onRequest(request);
+ }
+
+ @Override
+ public void onDeleteRequested(Editor editor) {
+ if (editor instanceof EventFieldEditorView){
+ final EventFieldEditorView delView = (EventFieldEditorView) editor;
+ if (delView.isBirthdayType() && mEditors.getChildCount() > 1) {
+ final EventFieldEditorView bottomView = (EventFieldEditorView) mEditors
+ .getChildAt(mEditors.getChildCount() - 1);
+ bottomView.restoreBirthday();
+ }
+ }
+ super.onDeleteRequested(editor);
+ }
+ }
+
private List<KindSectionData> mKindSectionDataList;
private ViewIdGenerator mViewIdGenerator;
private CompactRawContactsEditorView.Listener mListener;
@@ -241,8 +262,14 @@
addGroupEditorView(kindSectionData.getRawContactDelta(),
kindSectionData.getDataKind());
} else {
- final Editor.EditorListener editorListener = kindSectionData.isNicknameDataKind()
- ? new OtherNameKindEditorListener() : new NonNameEditorListener();
+ final Editor.EditorListener editorListener;
+ if (kindSectionData.isNicknameDataKind()) {
+ editorListener = new OtherNameKindEditorListener();
+ } else if (kindSectionData.isEventDataKind()) {
+ editorListener = new EventEditorListener();
+ } else {
+ editorListener = new NonNameEditorListener();
+ }
for (ValuesDelta valuesDelta : kindSectionData.getValuesDeltas()) {
addNonNameEditorView(kindSectionData.getRawContactDelta(),
kindSectionData.getDataKind(), valuesDelta, editorListener);
@@ -461,8 +488,10 @@
final RawContactDelta rawContactDelta =
mKindSectionDataList.get(0).getRawContactDelta();
final ValuesDelta values = RawContactModifier.insertChild(rawContactDelta, dataKind);
+ final Editor.EditorListener editorListener = mKindSectionDataList.get(0)
+ .isEventDataKind() ? new EventEditorListener() : new NonNameEditorListener();
final View view = addNonNameEditorView(rawContactDelta, dataKind, values,
- new NonNameEditorListener());
+ editorListener);
showView(view, shouldAnimate);
}
}
diff --git a/src/com/android/contacts/editor/EventFieldEditorView.java b/src/com/android/contacts/editor/EventFieldEditorView.java
index 17e52a7..b8ded06 100644
--- a/src/com/android/contacts/editor/EventFieldEditorView.java
+++ b/src/com/android/contacts/editor/EventFieldEditorView.java
@@ -20,6 +20,8 @@
import android.content.Context;
import android.content.res.Resources;
import android.os.Bundle;
+import android.provider.ContactsContract;
+import android.provider.ContactsContract.CommonDataKinds.Event;
import android.text.TextUtils;
import android.util.AttributeSet;
import android.view.View;
@@ -268,4 +270,24 @@
final String column = getKind().fieldList.get(0).column;
onFieldChanged(column, "");
}
+
+ /**
+ * Sets the typeColumn of entry as TYPE_BIRTHDAY and calls rebuildValues() to refresh the view.
+ */
+ public void restoreBirthday() {
+ saveValue(getKind().typeColumn, Integer.toString(Event.TYPE_BIRTHDAY));
+ rebuildValues();
+ }
+
+ /**
+ * EventEditType Birthday:
+ * rawValue=3 labelRes=17039911 secondary=false specificMax=1 customColumn=null
+ * mYearOptional=true
+ */
+ public boolean isBirthdayType(){
+ final EventEditType eventType = getType();
+ return eventType.rawValue == Event.TYPE_BIRTHDAY && !eventType.secondary
+ && eventType.specificMax == 1 && eventType.customColumn == null
+ && eventType.isYearOptional();
+ }
}
diff --git a/src/com/android/contacts/editor/KindSectionData.java b/src/com/android/contacts/editor/KindSectionData.java
index d46001a..33aeed2 100644
--- a/src/com/android/contacts/editor/KindSectionData.java
+++ b/src/com/android/contacts/editor/KindSectionData.java
@@ -24,6 +24,7 @@
import android.provider.ContactsContract.CommonDataKinds.Nickname;
import android.provider.ContactsContract.CommonDataKinds.StructuredName;
+import android.provider.ContactsContract.CommonDataKinds.Event;
import android.text.TextUtils;
import java.util.Collections;
@@ -105,6 +106,10 @@
return Nickname.CONTENT_ITEM_TYPE.equals(mDataKind.mimeType);
}
+ public boolean isEventDataKind() {
+ return Event.CONTENT_ITEM_TYPE.equals(mDataKind.mimeType);
+ }
+
public RawContactDelta getRawContactDelta() {
return mRawContactDelta;
}