Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 25f9694f authored by Walter Jang's avatar Walter Jang
Browse files

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
parent 0299c1d4
Loading
Loading
Loading
Loading
+18 −12
Original line number Diff line number Diff line
@@ -212,23 +212,29 @@ public class StructuredNameEditorView extends TextFieldsEditorView {
     */
    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;
                }
        // The name may have been passed to the compact editor and not written to the underlying
        // data structure.
            } else {
                final String displayName = valuesDelta.getDisplayName();
                if (!TextUtils.isEmpty(displayName)) {
                    return displayName;
                }
            }
        }
        return valuesDelta.getDisplayName();
    }

    @Override
    public boolean isEmpty() {
        return TextUtils.isEmpty(getDisplayName());
    }

    @Override
    protected Parcelable onSaveInstanceState() {
        SavedState state = new SavedState(super.onSaveInstanceState());