Fix detection of empty structured names
TextFieldEditorView.isEmpty does not do the right thing
for structured names because that methods just checks every
child of the fields ViewGroup and the view retains values
for fields that may have been erased by toggling the
name expansion. The result is that the FIELD_TURNED_EMPTY
EditorListener event is never fired.
Bug 21851290
Change-Id: Iaae3ba102a899de9dfd76d0469c9c2f1d094b0bd
diff --git a/src/com/android/contacts/editor/StructuredNameEditorView.java b/src/com/android/contacts/editor/StructuredNameEditorView.java
index 5f764f9..c0463b0 100644
--- a/src/com/android/contacts/editor/StructuredNameEditorView.java
+++ b/src/com/android/contacts/editor/StructuredNameEditorView.java
@@ -212,24 +212,30 @@
*/
public String getDisplayName() {
final ValuesDelta valuesDelta = getValues();
- if (hasShortAndLongForms() && areOptionalFieldsVisible()) {
- final String displayName = valuesDelta.getDisplayName();
- if (!TextUtils.isEmpty(displayName)) {
- return displayName;
+ if (hasShortAndLongForms()) {
+ if (areOptionalFieldsVisible()) {
+ final Map<String, String> structuredNameMap = valuesToStructuredNameMap(valuesDelta);
+ final String displayName = NameConverter.structuredNameToDisplayName(
+ getContext(), structuredNameMap);
+ if (!TextUtils.isEmpty(displayName)) {
+ return displayName;
+ }
+ } else {
+ final String displayName = valuesDelta.getDisplayName();
+ if (!TextUtils.isEmpty(displayName)) {
+ return displayName;
+ }
}
}
- final Map<String, String> structuredNameMap = valuesToStructuredNameMap(valuesDelta);
- final String displayName = NameConverter.structuredNameToDisplayName(
- getContext(), structuredNameMap);
- if (!TextUtils.isEmpty(displayName)) {
- return displayName;
- }
- // The name may have been passed to the compact editor and not written to the underlying
- // data structure.
return valuesDelta.getDisplayName();
}
@Override
+ public boolean isEmpty() {
+ return TextUtils.isEmpty(getDisplayName());
+ }
+
+ @Override
protected Parcelable onSaveInstanceState() {
SavedState state = new SavedState(super.onSaveInstanceState());
state.mChanged = mChanged;