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

Commit 9fc52c9f authored by Walter Jang's avatar Walter Jang Committed by android-build-merger
Browse files

Merge "Set read only display name as primary in fragment not view (DN 2/2)"...

Merge "Set read only display name as primary in fragment not view (DN 2/2)" into ub-contactsdialer-a-dev
am: d26051e0

* commit 'd26051e0':
  Set read only display name as primary in fragment not view (DN 2/2)
parents c4119385 d26051e0
Loading
Loading
Loading
Loading
+4 −2
Original line number Diff line number Diff line
@@ -30,6 +30,7 @@ import android.content.Intent;
import android.graphics.Bitmap;
import android.net.Uri;
import android.os.Bundle;
import android.text.TextUtils;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.MenuItem;
@@ -98,9 +99,10 @@ public class CompactContactEditorFragment extends ContactEditorBaseFragment impl
        final CompactRawContactsEditorView editorView = getContent();
        editorView.setListener(this);
        editorView.setState(mState, getMaterialPalette(), mViewIdGenerator, mPhotoId,
                mReadOnlyDisplayName, mHasNewContact, mIsUserProfile, mAccountWithDataSet);
        if (mReadOnlyDisplayName != null) {
                mHasNewContact, mIsUserProfile, mAccountWithDataSet);
        if (mHasNewContact && !TextUtils.isEmpty(mReadOnlyDisplayName)) {
            mReadOnlyNameEditorView = editorView.getPrimaryNameEditorView();
            editorView.maybeSetReadOnlyDisplayNameAsPrimary(mReadOnlyDisplayName);
        }

        // Set up the photo widget
+18 −18
Original line number Diff line number Diff line
@@ -324,7 +324,6 @@ public class CompactRawContactsEditorView extends LinearLayout implements View.O
    private ViewIdGenerator mViewIdGenerator;
    private MaterialColorMapUtils.MaterialPalette mMaterialPalette;
    private long mPhotoId = -1;
    private String mReadOnlyDisplayName;
    private boolean mHasNewContact;
    private boolean mIsUserProfile;
    private AccountWithDataSet mPrimaryAccount;
@@ -357,7 +356,6 @@ public class CompactRawContactsEditorView extends LinearLayout implements View.O
    private ValuesDelta mPhotoValuesDelta;

    private Pair<KindSectionData, ValuesDelta> mPrimaryNameKindSectionData;
    private StructuredNameEditorView mPrimaryNameEditorView;

    public CompactRawContactsEditorView(Context context) {
        super(context);
@@ -515,7 +513,9 @@ public class CompactRawContactsEditorView extends LinearLayout implements View.O
    }

    public StructuredNameEditorView getPrimaryNameEditorView() {
        return mPrimaryNameEditorView;
        final CompactKindSectionView primaryNameKindSectionView = getPrimaryNameKindSectionView();
        return primaryNameKindSectionView == null
                ? null : primaryNameKindSectionView.getPrimaryNameEditorView();
    }

    /**
@@ -614,8 +614,8 @@ public class CompactRawContactsEditorView extends LinearLayout implements View.O

    public void setState(RawContactDeltaList rawContactDeltas,
            MaterialColorMapUtils.MaterialPalette materialPalette, ViewIdGenerator viewIdGenerator,
            long photoId, String readOnlyDisplayName, boolean hasNewContact,
            boolean isUserProfile, AccountWithDataSet primaryAccount) {
            long photoId, boolean hasNewContact, boolean isUserProfile,
            AccountWithDataSet primaryAccount) {
        mKindSectionDataMap.clear();
        mKindSectionViews.removeAllViews();
        mMoreFields.setVisibility(View.VISIBLE);
@@ -623,7 +623,6 @@ public class CompactRawContactsEditorView extends LinearLayout implements View.O
        mMaterialPalette = materialPalette;
        mViewIdGenerator = viewIdGenerator;
        mPhotoId = photoId;
        mReadOnlyDisplayName = readOnlyDisplayName;

        mHasNewContact = hasNewContact;
        mIsUserProfile = isUserProfile;
@@ -667,9 +666,7 @@ public class CompactRawContactsEditorView extends LinearLayout implements View.O
        addAccountInfo(rawContactDeltas);
        addPhotoView();
        addKindSectionViews();
        if (mHasNewContact) {
            maybeCopyPrimaryDisplayName();
        }

        if (mIsExpanded) showAllFields();

        if (mListener != null) mListener.onEditorsBound();
@@ -1055,19 +1052,22 @@ public class CompactRawContactsEditorView extends LinearLayout implements View.O
        return kindSectionView;
    }

    private void maybeCopyPrimaryDisplayName() {
        if (TextUtils.isEmpty(mReadOnlyDisplayName)) return;
        final List<CompactKindSectionView> kindSectionViews
                = mKindSectionViewsMap.get(StructuredName.CONTENT_ITEM_TYPE);
        if (kindSectionViews == null || kindSectionViews.isEmpty()) return;
        final CompactKindSectionView primaryNameKindSectionView = kindSectionViews.get(0);
        if (primaryNameKindSectionView.isEmptyName()) {
    void maybeSetReadOnlyDisplayNameAsPrimary(String readOnlyDisplayName) {
        if (TextUtils.isEmpty(readOnlyDisplayName)) return;
        final CompactKindSectionView primaryNameKindSectionView = getPrimaryNameKindSectionView();
        if (primaryNameKindSectionView != null && primaryNameKindSectionView.isEmptyName()) {
            vlog("name: using read only display name as primary name");
            primaryNameKindSectionView.setName(mReadOnlyDisplayName);
            mPrimaryNameEditorView = primaryNameKindSectionView.getPrimaryNameEditorView();
            primaryNameKindSectionView.setName(readOnlyDisplayName);
        }
    }

    private CompactKindSectionView getPrimaryNameKindSectionView() {
        final List<CompactKindSectionView> kindSectionViews
                = mKindSectionViewsMap.get(StructuredName.CONTENT_ITEM_TYPE);
        return kindSectionViews == null || kindSectionViews.isEmpty()
                ? null : kindSectionViews.get(0);
    }

    private void showAllFields() {
        // Stop hiding empty editors and allow the user to enter values for all kinds now
        for (int i = 0; i < mKindSectionViews.getChildCount(); i++) {
+24 −25
Original line number Diff line number Diff line
@@ -65,6 +65,7 @@ import android.provider.ContactsContract.CommonDataKinds.Email;
import android.provider.ContactsContract.CommonDataKinds.Event;
import android.provider.ContactsContract.CommonDataKinds.Organization;
import android.provider.ContactsContract.CommonDataKinds.Phone;
import android.provider.ContactsContract.CommonDataKinds.StructuredName;
import android.provider.ContactsContract.CommonDataKinds.StructuredPostal;
import android.provider.ContactsContract.Contacts;
import android.provider.ContactsContract.Intents;
@@ -83,7 +84,9 @@ import android.widget.ListPopupWindow;
import android.widget.Toast;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

/**
 * Base Fragment for contact editors.
@@ -145,6 +148,8 @@ abstract public class ContactEditorBaseFragment extends Fragment implements
    // Join Activity
    private static final String KEY_CONTACT_ID_FOR_JOIN = "contactidforjoin";

    private static final String KEY_READ_ONLY_DISPLAY_NAME = "readOnlyDisplayName";

    protected static final int REQUEST_CODE_JOIN = 0;
    protected static final int REQUEST_CODE_ACCOUNTS_CHANGED = 1;
    protected static final int REQUEST_CODE_PICK_RINGTONE = 2;
@@ -380,13 +385,13 @@ abstract public class ContactEditorBaseFragment extends Fragment implements
    // Join Activity
    protected long mContactIdForJoin;

    // Used to pre-populate the editor with a display name when a user edits a read-only contact.
    protected String mReadOnlyDisplayName;

    //
    // Not saved/restored on rotates
    //

    // Used to pre-populate the editor with a display name when a user edits a read-only contact.
    protected String mReadOnlyDisplayName;

    // The name editor view for the new raw contact that was created so that the user can
    // edit a read-only contact (to which the new raw contact was joined)
    protected StructuredNameEditorView mReadOnlyNameEditorView;
@@ -515,6 +520,8 @@ abstract public class ContactEditorBaseFragment extends Fragment implements

            // Join Activity
            mContactIdForJoin = savedState.getLong(KEY_CONTACT_ID_FOR_JOIN);

            mReadOnlyDisplayName = savedState.getString(KEY_READ_ONLY_DISPLAY_NAME);
        }

        // mState can still be null because it may not have have finished loading before
@@ -634,6 +641,8 @@ abstract public class ContactEditorBaseFragment extends Fragment implements
        // Join Activity
        outState.putLong(KEY_CONTACT_ID_FOR_JOIN, mContactIdForJoin);

        outState.putString(KEY_READ_ONLY_DISPLAY_NAME, mReadOnlyDisplayName);

        super.onSaveInstanceState(outState);
    }

@@ -972,9 +981,9 @@ abstract public class ContactEditorBaseFragment extends Fragment implements
     * Return true if there are any edits to the current contact which need to
     * be saved.
     */
    protected boolean hasPendingRawContactChanges() {
    protected boolean hasPendingRawContactChanges(Set<String> excludedMimeTypes) {
        final AccountTypeManager accountTypes = AccountTypeManager.getInstance(mContext);
        return RawContactModifier.hasChanges(mState, accountTypes);
        return RawContactModifier.hasChanges(mState, accountTypes, excludedMimeTypes);
    }

    /**
@@ -996,29 +1005,19 @@ abstract public class ContactEditorBaseFragment extends Fragment implements
     * See go/editing-read-only-contacts
     */
    protected boolean hasPendingChanges() {
        if (mReadOnlyNameEditorView == null || mReadOnlyDisplayName == null) {
            return hasPendingRawContactChanges();
        }
        if (mReadOnlyNameEditorView != null && mReadOnlyDisplayName != null) {
            // We created a new raw contact delta with a default display name.
            // We must test for pending changes while ignoring the default display name.
            final String displayName = mReadOnlyNameEditorView.getDisplayName();
            if (mReadOnlyDisplayName.equals(displayName)) {
            // The user did not modify the default display name, erase it and
            // check if the user made any other changes
            mReadOnlyNameEditorView.clearAllFields();
            if (hasPendingRawContactChanges()) {
                // Other changes were made to the aggregate contact, restore
                // the display name and proceed.
                mReadOnlyNameEditorView.setDisplayName(displayName);
                return true;
            } else {
                // No other changes were made to the aggregate contact. Don't add back
                // the displayName so that a "bogus" contact is not created.
                return false;
            }
                final Set<String> excludedMimeTypes = new HashSet<>();
                excludedMimeTypes.add(StructuredName.CONTENT_ITEM_TYPE);
                return hasPendingRawContactChanges(excludedMimeTypes);
            }
            return true;
        }
        return hasPendingRawContactChanges(/* excludedMimeTypes =*/ null);
    }

    /**
     * Whether editor inputs and the options menu should be enabled.