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

Commit 398cd4b1 authored by Walter Jang's avatar Walter Jang
Browse files

Pass the preferred name ID into the contact editor

Bug 21870691

Change-Id: I99cc6bf8d90f32469ca7cf105567dcc3edf48e9f
parent fbe232ef
Loading
Loading
Loading
Loading
+4 −2
Original line number Diff line number Diff line
@@ -165,7 +165,8 @@ abstract public class ContactEditorBaseActivity extends ContactsActivity
         * Invoked after the contact is saved.
         */
        void onSaveCompleted(boolean hadChanges, int saveMode, boolean saveSucceeded,
                Uri contactLookupUri, Bundle updatedPhotos, boolean backPressed, long photoId);
                Uri contactLookupUri, Bundle updatedPhotos, boolean backPressed, long photoId,
                long nameId);

        /**
         * Invoked after the contact is joined.
@@ -256,7 +257,8 @@ abstract public class ContactEditorBaseActivity extends ContactsActivity
                    (Bundle) intent.getParcelableExtra(ContactSaveService.EXTRA_UPDATED_PHOTOS),
                    intent.getBooleanExtra(ContactEditorFragment.INTENT_EXTRA_SAVE_BACK_PRESSED,
                            false),
                    intent.getLongExtra(ContactEditorFragment.INTENT_EXTRA_PHOTO_ID, -1));
                    intent.getLongExtra(ContactEditorFragment.INTENT_EXTRA_PHOTO_ID, -1),
                    intent.getLongExtra(ContactEditorFragment.INTENT_EXTRA_NAME_ID, -1));
        } else if (ACTION_JOIN_COMPLETED.equals(action)) {
            mFragment.onJoinCompleted(intent.getData());
        }
+2 −1
Original line number Diff line number Diff line
@@ -427,7 +427,8 @@ public class ContactSelectionActivity extends ContactsActivity
            } else {
                // Otherwise launch the full contact editor.
                startActivityAndForwardResult(EditorIntents.createEditContactIntent(
                        contactLookupUri, /* materialPalette =*/ null, /* photoId =*/ -1));
                        contactLookupUri, /* materialPalette =*/ null, /* photoId =*/ -1,
                        /* nameId =*/ -1));
            }
        }

+2 −2
Original line number Diff line number Diff line
@@ -201,7 +201,7 @@ public class CompactContactEditorFragment extends ContactEditorBaseFragment impl
        // Add input fields for the loaded Contact
        final CompactRawContactsEditorView editorView = getContent();
        editorView.setListener(this);
        editorView.setState(mState, getMaterialPalette(), mViewIdGenerator, mPhotoId);
        editorView.setState(mState, getMaterialPalette(), mViewIdGenerator, mPhotoId, mNameId);

        // Set up the photo widget
        mPhotoHandler = createPhotoHandler();
@@ -355,7 +355,7 @@ public class CompactContactEditorFragment extends ContactEditorBaseFragment impl
                ? EditorIntents.createInsertContactIntent(
                        mState, getDisplayName(), getPhoneticName(), mUpdatedPhotos)
                : EditorIntents.createEditContactIntent(mLookupUri, getMaterialPalette(),
                        mPhotoId);
                        mPhotoId, mNameId);
        ImplicitIntentsUtil.startActivityInApp(getActivity(), intent);

        getActivity().finish();
+26 −4
Original line number Diff line number Diff line
@@ -256,7 +256,7 @@ public class CompactRawContactsEditorView extends LinearLayout implements View.O

    public void setState(RawContactDeltaList rawContactDeltas,
            MaterialColorMapUtils.MaterialPalette materialPalette,
            ViewIdGenerator viewIdGenerator, long photoId) {
            ViewIdGenerator viewIdGenerator, long photoId, long nameId) {
        mNames.removeAllViews();
        mPhoneticNames.removeAllViews();
        mNicknames.removeAllViews();
@@ -275,7 +275,7 @@ public class CompactRawContactsEditorView extends LinearLayout implements View.O

        vlog("Setting compact editor state from " + rawContactDeltas);
        addPhotoView(rawContactDeltas, viewIdGenerator, photoId);
        addStructuredNameView(rawContactDeltas);
        addStructuredNameView(rawContactDeltas, nameId);
        addEditorViews(rawContactDeltas);
        removeExtraEmptyTextFields(mPhoneNumbers);
        removeExtraEmptyTextFields(mEmails);
@@ -292,7 +292,6 @@ public class CompactRawContactsEditorView extends LinearLayout implements View.O
            RawContactModifier.ensureKindExists(
                    rawContactDelta, accountType, Photo.CONTENT_ITEM_TYPE);

            // Look for a non-empty super primary photo
            final DataKind dataKind = accountType.getKindForMimetype(Photo.CONTENT_ITEM_TYPE);
            if (dataKind != null) {
                for (ValuesDelta valuesDelta
@@ -365,7 +364,8 @@ public class CompactRawContactsEditorView extends LinearLayout implements View.O
        mPhoto.setVisibility(View.GONE);
    }

    private void addStructuredNameView(RawContactDeltaList rawContactDeltas) {
    private void addStructuredNameView(RawContactDeltaList rawContactDeltas, long nameId) {
        // Look for a match for the photo ID that was passed in
        for (RawContactDelta rawContactDelta : rawContactDeltas) {
            if (!rawContactDelta.isVisible()) continue;
            final AccountType accountType = rawContactDelta.getAccountType(mAccountTypeManager);
@@ -379,6 +379,28 @@ public class CompactRawContactsEditorView extends LinearLayout implements View.O
                    DataKind.PSEUDO_MIME_TYPE_DISPLAY_NAME);
            if (dataKind == null || !dataKind.editable) continue;

            for (ValuesDelta valuesDelta : rawContactDelta.getMimeEntries(
                    StructuredName.CONTENT_ITEM_TYPE)) {
                if (valuesDelta != null && valuesDelta.getId() != null
                        && valuesDelta.getId().equals(nameId)) {
                    mNameValuesDelta = valuesDelta;
                    final NameEditorListener nameEditorListener = new NameEditorListener(
                            mNameValuesDelta, rawContactDelta.getRawContactId(), mListener);
                    mNames.addView(inflateStructuredNameEditorView(mNames, accountType,
                            mNameValuesDelta, rawContactDelta, nameEditorListener));
                    return;
                }
            }
        }
        // Look for a super primary name
        for (RawContactDelta rawContactDelta : rawContactDeltas) {
            if (!rawContactDelta.isVisible()) continue;
            final AccountType accountType = rawContactDelta.getAccountType(mAccountTypeManager);

            final DataKind dataKind = accountType.getKindForMimetype(
                    DataKind.PSEUDO_MIME_TYPE_DISPLAY_NAME);
            if (dataKind == null || !dataKind.editable) continue;

            final ValuesDelta superPrimaryValuesDelta = getNonEmptySuperPrimaryValuesDeltas(
                    rawContactDelta, StructuredName.CONTENT_ITEM_TYPE, dataKind);
            if (superPrimaryValuesDelta != null) {
+16 −4
Original line number Diff line number Diff line
@@ -113,6 +113,7 @@ abstract public class ContactEditorBaseFragment extends Fragment implements
    private static final String KEY_NEW_LOCAL_PROFILE = "newLocalProfile";
    private static final String KEY_MATERIAL_PALETTE = "materialPalette";
    private static final String KEY_PHOTO_ID = "photoId";
    private static final String KEY_NAME_ID = "nameId";

    private static final String KEY_VIEW_ID_GENERATOR = "viewidgenerator";

@@ -178,6 +179,11 @@ abstract public class ContactEditorBaseFragment extends Fragment implements
     */
    public static final String INTENT_EXTRA_PHOTO_ID = "photo_id";

    /**
     * Intent key to pass the ID of the name to display on the editor.
     */
    public static final String INTENT_EXTRA_NAME_ID = "name_id";

    /**
     * Intent extra to specify a {@link ContactEditor.SaveMode}.
     */
@@ -315,6 +321,7 @@ abstract public class ContactEditorBaseFragment extends Fragment implements
    protected boolean mNewLocalProfile;
    protected MaterialColorMapUtils.MaterialPalette mMaterialPalette;
    protected long mPhotoId = -1;
    protected long mNameId = -1;

    //
    // Helpers
@@ -465,6 +472,7 @@ abstract public class ContactEditorBaseFragment extends Fragment implements
            mNewLocalProfile = savedState.getBoolean(KEY_NEW_LOCAL_PROFILE);
            mMaterialPalette = savedState.getParcelable(KEY_MATERIAL_PALETTE);
            mPhotoId = savedState.getLong(KEY_PHOTO_ID);
            mNameId = savedState.getLong(KEY_NAME_ID);

            mRawContacts = ImmutableList.copyOf(savedState.<RawContact>getParcelableArrayList(
                    KEY_RAW_CONTACTS));
@@ -586,6 +594,7 @@ abstract public class ContactEditorBaseFragment extends Fragment implements
            outState.putParcelable(KEY_MATERIAL_PALETTE, mMaterialPalette);
        }
        outState.putLong(KEY_PHOTO_ID, mPhotoId);
        outState.putLong(KEY_NAME_ID, mNameId);

        outState.putParcelable(KEY_VIEW_ID_GENERATOR, mViewIdGenerator);

@@ -917,7 +926,7 @@ abstract public class ContactEditorBaseFragment extends Fragment implements
            }
            onSaveCompleted(/* hadChanges =*/ false, saveMode,
                    /* saveSucceeded =*/ mLookupUri != null, mLookupUri,
                    /* updatedPhotos =*/ null, backPressed, mPhotoId);
                    /* updatedPhotos =*/ null, backPressed, mPhotoId, mNameId);
            return true;
        }

@@ -1308,6 +1317,7 @@ abstract public class ContactEditorBaseFragment extends Fragment implements
                mUpdatedPhotos = mIntentExtras.getParcelable(INTENT_EXTRA_UPDATED_PHOTOS);
            }
            mPhotoId = mIntentExtras.getLong(INTENT_EXTRA_PHOTO_ID);
            mNameId = mIntentExtras.getLong(INTENT_EXTRA_NAME_ID);
        }
    }

@@ -1331,12 +1341,13 @@ abstract public class ContactEditorBaseFragment extends Fragment implements
    @Override
    public void onJoinCompleted(Uri uri) {
        onSaveCompleted(false, SaveMode.RELOAD, uri != null, uri, /* updatedPhotos =*/ null,
                /* backPressed =*/ false, /* photoId =*/ mPhotoId);
                /* backPressed =*/ false, mPhotoId, mNameId);
    }

    @Override
    public void onSaveCompleted(boolean hadChanges, int saveMode, boolean saveSucceeded,
            Uri contactLookupUri, Bundle updatedPhotos, boolean backPressed, long photoId) {
            Uri contactLookupUri, Bundle updatedPhotos, boolean backPressed, long photoId,
            long nameId) {
        if (hadChanges) {
            if (saveSucceeded) {
                if (saveMode != SaveMode.JOIN) {
@@ -1373,7 +1384,8 @@ abstract public class ContactEditorBaseFragment extends Fragment implements
                            ? EditorIntents.createCompactInsertContactIntent(
                                    mState, getDisplayName(), getPhoneticName(), updatedPhotos)
                            : EditorIntents.createCompactEditContactIntent(
                                    lookupUri, getMaterialPalette(), updatedPhotos, photoId);
                                    lookupUri, getMaterialPalette(), updatedPhotos, photoId,
                                    nameId);
                    resultIntent.putExtra(INTENT_EXTRA_SAVE_BACK_PRESSED, true);
                    mStatus = Status.CLOSING;
                    if (mListener != null) mListener.onSaveFinished(resultIntent);
Loading