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

Commit b05466a9 authored by Isaac Katzenelson's avatar Isaac Katzenelson
Browse files

Fix name editor data loss on rotation

Bug: 5290661 Edited name for a contact not saved

When the contact editor was recreated on screen rotation the
data on the name editor was updated incorrectly.
The problem was that a change to any of the fields in the name editor
was erasing the other fields. Instead of erasing the other fields, i changed
the code to sync between the display name and structured name so that on
rotation, the data is correctly stored and retrieved.

Change-Id: I644bfea2af4e759e1d7d94aa09840ed15efd079d
parent 6fc3aacd
Loading
Loading
Loading
Loading
+20 −4
Original line number Diff line number Diff line
@@ -77,18 +77,18 @@ public class StructuredNameEditorView extends TextFieldsEditorView {
        if (!isFieldChanged(column, value)) {
            return;
        }
        super.onFieldChanged(column, value);

        mChanged = true;

        // Make sure the display name and the structured name are synced
        if (hasShortAndLongForms()) {
            if (areOptionalFieldsVisible()) {
                eraseFullName(getValues());
                rebuildFullName(getValues());
            } else {
                eraseStructuredName(getValues());
                rebuildStructuredName(getValues());
            }
        }

        super.onFieldChanged(column, value);
    }

    @Override
@@ -165,12 +165,28 @@ public class StructuredNameEditorView extends TextFieldsEditorView {
        values.putNull(StructuredName.DISPLAY_NAME);
    }

    private void rebuildFullName(ValuesDelta values) {
        Map<String, String> structuredNameMap = valuesToStructuredNameMap(values);
        String displayName = NameConverter.structuredNameToDisplayName(getContext(),
                structuredNameMap);
        values.put(StructuredName.DISPLAY_NAME, displayName);
    }

    private void eraseStructuredName(ValuesDelta values) {
        for (String field : NameConverter.STRUCTURED_NAME_FIELDS) {
            values.putNull(field);
        }
    }

    private void rebuildStructuredName(ValuesDelta values) {
        String displayName = values.getAsString(StructuredName.DISPLAY_NAME);
        Map<String, String> structuredNameMap = NameConverter.displayNameToStructuredName(
                getContext(), displayName);
        for (String field : structuredNameMap.keySet()) {
            values.put(field, structuredNameMap.get(field));
        }
    }

    private static void appendQueryParameter(Uri.Builder builder, String field, String value) {
        if (!TextUtils.isEmpty(value)) {
            builder.appendQueryParameter(field, value);