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

Commit aec68d53 authored by Walter Jang's avatar Walter Jang Committed by Android Git Automerger
Browse files

am 0a7bc1c4: am ac679af9: Pass the preferred photo ID into the contact editor

* commit '0a7bc1c4':
  Pass the preferred photo ID into the contact editor
parents 82eafa6f 0a7bc1c4
Loading
Loading
Loading
Loading
+3 −2
Original line number Diff line number Diff line
@@ -163,7 +163,7 @@ 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);
                Uri contactLookupUri, Bundle updatedPhotos, boolean backPressed, long photoId);

        /**
         * Invoked after the contact is joined.
@@ -243,7 +243,8 @@ abstract public class ContactEditorBaseActivity extends ContactsActivity
                    intent.getData(),
                    (Bundle) intent.getParcelableExtra(ContactSaveService.EXTRA_UPDATED_PHOTOS),
                    intent.getBooleanExtra(ContactEditorFragment.INTENT_EXTRA_SAVE_BACK_PRESSED,
                            false));
                            false),
                    intent.getLongExtra(ContactEditorFragment.INTENT_EXTRA_PHOTO_ID, -1));
        } else if (ACTION_JOIN_COMPLETED.equals(action)) {
            mFragment.onJoinCompleted(intent.getData());
        }
+3 −1
Original line number Diff line number Diff line
@@ -47,6 +47,7 @@ import com.android.contacts.R;
import com.android.contacts.common.activity.RequestPermissionsActivity;
import com.android.contacts.common.list.ContactEntryListFragment;
import com.android.contacts.common.util.ImplicitIntentsUtil;
import com.android.contacts.editor.EditorIntents;
import com.android.contacts.list.ContactPickerFragment;
import com.android.contacts.list.ContactsIntentResolver;
import com.android.contacts.list.ContactsRequest;
@@ -425,7 +426,8 @@ public class ContactSelectionActivity extends ContactsActivity
                startActivityForResult(intent, SUBACTIVITY_ADD_TO_EXISTING_CONTACT);
            } else {
                // Otherwise launch the full contact editor.
                startActivityAndForwardResult(new Intent(Intent.ACTION_EDIT, contactLookupUri));
                startActivityAndForwardResult(EditorIntents.createEditContactIntent(
                        contactLookupUri, /* materialPalette =*/ null, /* photoId =*/ -1));
            }
        }

+3 −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);
        editorView.setState(mState, getMaterialPalette(), mViewIdGenerator, mPhotoId);

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

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

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

        vlog("Setting compact editor state from " + rawContactDeltas);
        addPhotoView(rawContactDeltas, viewIdGenerator);
        addPhotoView(rawContactDeltas, viewIdGenerator, photoId);
        addStructuredNameView(rawContactDeltas);
        addEditorViews(rawContactDeltas);
        removeExtraEmptyTextFields(mPhoneNumbers);
@@ -289,7 +289,8 @@ public class CompactRawContactsEditorView extends LinearLayout implements View.O
    }

    private void addPhotoView(RawContactDeltaList rawContactDeltas,
            ViewIdGenerator viewIdGenerator) {
            ViewIdGenerator viewIdGenerator, long photoId) {
        // 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);
@@ -300,6 +301,26 @@ public class CompactRawContactsEditorView extends LinearLayout implements View.O

            // Look for a non-empty super primary photo
            final DataKind dataKind = accountType.getKindForMimetype(Photo.CONTENT_ITEM_TYPE);
            if (dataKind != null) {
                for (ValuesDelta valuesDelta
                        : rawContactDelta.getMimeEntries(Photo.CONTENT_ITEM_TYPE)) {
                    if (valuesDelta != null && valuesDelta.getId() != null
                            && valuesDelta.getId().equals(photoId)) {
                        mPhotoRawContactId = rawContactDelta.getRawContactId();
                        mPhoto.setValues(dataKind, valuesDelta, rawContactDelta,
                                /* readOnly =*/ !dataKind.editable, mMaterialPalette,
                                viewIdGenerator);
                        return;
                    }
                }
            }
        }

        // Look for a non-empty super primary photo
        for (RawContactDelta rawContactDelta : rawContactDeltas) {
            if (!rawContactDelta.isVisible()) continue;
            final AccountType accountType = rawContactDelta.getAccountType(mAccountTypeManager);
            final DataKind dataKind = accountType.getKindForMimetype(Photo.CONTENT_ITEM_TYPE);
            if (dataKind != null) {
                final ValuesDelta valuesDelta = getNonEmptySuperPrimaryValuesDeltas(
                        rawContactDelta, Photo.CONTENT_ITEM_TYPE, dataKind);
+14 −4
Original line number Diff line number Diff line
@@ -112,6 +112,7 @@ abstract public class ContactEditorBaseFragment extends Fragment implements
    private static final String KEY_DISABLE_DELETE_MENU_OPTION = "disableDeleteMenuOption";
    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_VIEW_ID_GENERATOR = "viewidgenerator";

@@ -172,6 +173,11 @@ abstract public class ContactEditorBaseFragment extends Fragment implements
     */
    public static final String INTENT_EXTRA_UPDATED_PHOTOS = "updated_photos";

    /**
     * Intent key to pass the ID of the photo to display on the editor.
     */
    public static final String INTENT_EXTRA_PHOTO_ID = "photo_id";

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

    //
    // Helpers
@@ -464,6 +471,7 @@ abstract public class ContactEditorBaseFragment extends Fragment implements
            mDisableDeleteMenuOption = savedState.getBoolean(KEY_DISABLE_DELETE_MENU_OPTION);
            mNewLocalProfile = savedState.getBoolean(KEY_NEW_LOCAL_PROFILE);
            mMaterialPalette = savedState.getParcelable(KEY_MATERIAL_PALETTE);
            mPhotoId = savedState.getLong(KEY_PHOTO_ID);

            mRawContacts = ImmutableList.copyOf(savedState.<RawContact>getParcelableArrayList(
                    KEY_RAW_CONTACTS));
@@ -584,6 +592,7 @@ abstract public class ContactEditorBaseFragment extends Fragment implements
        if (mMaterialPalette != null) {
            outState.putParcelable(KEY_MATERIAL_PALETTE, mMaterialPalette);
        }
        outState.putLong(KEY_PHOTO_ID, mPhotoId);

        outState.putParcelable(KEY_VIEW_ID_GENERATOR, mViewIdGenerator);

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

@@ -1312,6 +1321,7 @@ abstract public class ContactEditorBaseFragment extends Fragment implements
            if (mIntentExtras.containsKey(INTENT_EXTRA_UPDATED_PHOTOS)) {
                mUpdatedPhotos = mIntentExtras.getParcelable(INTENT_EXTRA_UPDATED_PHOTOS);
            }
            mPhotoId = mIntentExtras.getLong(INTENT_EXTRA_PHOTO_ID);
        }
    }

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

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