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

Commit 0299c1d4 authored by Walter Jang's avatar Walter Jang Committed by Android (Google) Code Review
Browse files

Merge "Don't allow read-only photos to be changed in compact editor" into mnc-dev

parents dd83ffe6 ab50e6f5
Loading
Loading
Loading
Loading
+11 −1
Original line number Original line Diff line number Diff line
@@ -73,7 +73,9 @@ public class CompactPhotoEditorView extends RelativeLayout implements View.OnCli
    private MaterialPalette mMaterialPalette;
    private MaterialPalette mMaterialPalette;


    private QuickContactImageView mPhotoImageView;
    private QuickContactImageView mPhotoImageView;
    private View mPhotoIcon;
    private View mPhotoIconOverlay;
    private View mPhotoIconOverlay;
    private View mPhotoTouchInterceptOverlay;


    public CompactPhotoEditorView(Context context) {
    public CompactPhotoEditorView(Context context) {
        this(context, null);
        this(context, null);
@@ -107,8 +109,9 @@ public class CompactPhotoEditorView extends RelativeLayout implements View.OnCli
        mContactPhotoManager = ContactPhotoManager.getInstance(getContext());
        mContactPhotoManager = ContactPhotoManager.getInstance(getContext());


        mPhotoImageView = (QuickContactImageView) findViewById(R.id.photo);
        mPhotoImageView = (QuickContactImageView) findViewById(R.id.photo);
        mPhotoIcon = findViewById(R.id.photo_icon);
        mPhotoIconOverlay = findViewById(R.id.photo_icon_overlay);
        mPhotoIconOverlay = findViewById(R.id.photo_icon_overlay);
        findViewById(R.id.photo_touch_intercept_overlay).setOnClickListener(this);
        mPhotoTouchInterceptOverlay = findViewById(R.id.photo_touch_intercept_overlay);
    }
    }


    public void setValues(DataKind dataKind, ValuesDelta valuesDelta,
    public void setValues(DataKind dataKind, ValuesDelta valuesDelta,
@@ -118,6 +121,13 @@ public class CompactPhotoEditorView extends RelativeLayout implements View.OnCli
        mReadOnly = readOnly;
        mReadOnly = readOnly;
        mMaterialPalette = materialPalette;
        mMaterialPalette = materialPalette;


        if (mReadOnly) {
            mPhotoIcon.setVisibility(View.GONE);
            mPhotoIconOverlay.setVisibility(View.GONE);
        } else {
            mPhotoTouchInterceptOverlay.setOnClickListener(this);
        }

        setId(viewIdGenerator.getId(rawContactDelta, dataKind, valuesDelta, /* viewIndex =*/ 0));
        setId(viewIdGenerator.getId(rawContactDelta, dataKind, valuesDelta, /* viewIndex =*/ 0));


        if (valuesDelta == null) {
        if (valuesDelta == null) {
+12 −15
Original line number Original line Diff line number Diff line
@@ -293,15 +293,15 @@ public class CompactRawContactsEditorView extends LinearLayout implements View.O
                    rawContactDelta, accountType, Photo.CONTENT_ITEM_TYPE);
                    rawContactDelta, accountType, Photo.CONTENT_ITEM_TYPE);


            final DataKind dataKind = accountType.getKindForMimetype(Photo.CONTENT_ITEM_TYPE);
            final DataKind dataKind = accountType.getKindForMimetype(Photo.CONTENT_ITEM_TYPE);
            if (dataKind != null) {
            if (dataKind != null && dataKind.editable) {
                for (ValuesDelta valuesDelta
                for (ValuesDelta valuesDelta
                        : rawContactDelta.getMimeEntries(Photo.CONTENT_ITEM_TYPE)) {
                        : rawContactDelta.getMimeEntries(Photo.CONTENT_ITEM_TYPE)) {
                    if (valuesDelta != null && valuesDelta.getId() != null
                    if (valuesDelta != null && valuesDelta.getId() != null
                            && valuesDelta.getId().equals(photoId)) {
                            && valuesDelta.getId().equals(photoId)) {
                        mPhotoRawContactId = rawContactDelta.getRawContactId();
                        mPhotoRawContactId = rawContactDelta.getRawContactId();
                        mPhoto.setValues(dataKind, valuesDelta, rawContactDelta,
                        mPhoto.setValues(dataKind, valuesDelta, rawContactDelta,
                                /* readOnly =*/ !dataKind.editable, mMaterialPalette,
                                !accountType.areContactsWritable(),
                                viewIdGenerator);
                                mMaterialPalette, viewIdGenerator);
                        return;
                        return;
                    }
                    }
                }
                }
@@ -313,13 +313,13 @@ public class CompactRawContactsEditorView extends LinearLayout implements View.O
            if (!rawContactDelta.isVisible()) continue;
            if (!rawContactDelta.isVisible()) continue;
            final AccountType accountType = rawContactDelta.getAccountType(mAccountTypeManager);
            final AccountType accountType = rawContactDelta.getAccountType(mAccountTypeManager);
            final DataKind dataKind = accountType.getKindForMimetype(Photo.CONTENT_ITEM_TYPE);
            final DataKind dataKind = accountType.getKindForMimetype(Photo.CONTENT_ITEM_TYPE);
            if (dataKind != null) {
            if (dataKind != null && dataKind.editable) {
                final ValuesDelta valuesDelta = getNonEmptySuperPrimaryValuesDeltas(
                final ValuesDelta valuesDelta = getNonEmptySuperPrimaryValuesDeltas(
                        rawContactDelta, Photo.CONTENT_ITEM_TYPE, dataKind);
                        rawContactDelta, Photo.CONTENT_ITEM_TYPE, dataKind);
                if (valuesDelta != null) {
                if (valuesDelta != null) {
                    mPhotoRawContactId = rawContactDelta.getRawContactId();
                    mPhotoRawContactId = rawContactDelta.getRawContactId();
                    mPhoto.setValues(dataKind, valuesDelta, rawContactDelta,
                    mPhoto.setValues(dataKind, valuesDelta, rawContactDelta,
                            /* readOnly =*/ !dataKind.editable, mMaterialPalette,
                            !accountType.areContactsWritable(), mMaterialPalette,
                            viewIdGenerator);
                            viewIdGenerator);
                    return;
                    return;
                }
                }
@@ -330,13 +330,13 @@ public class CompactRawContactsEditorView extends LinearLayout implements View.O
            if (!rawContactDelta.isVisible()) continue;
            if (!rawContactDelta.isVisible()) continue;
            final AccountType accountType = rawContactDelta.getAccountType(mAccountTypeManager);
            final AccountType accountType = rawContactDelta.getAccountType(mAccountTypeManager);
            final DataKind dataKind = accountType.getKindForMimetype(Photo.CONTENT_ITEM_TYPE);
            final DataKind dataKind = accountType.getKindForMimetype(Photo.CONTENT_ITEM_TYPE);
            if (dataKind != null) {
            if (dataKind != null && dataKind.editable) {
                final List<ValuesDelta> valuesDeltas = getNonEmptyValuesDeltas(
                final List<ValuesDelta> valuesDeltas = getNonEmptyValuesDeltas(
                        rawContactDelta, Photo.CONTENT_ITEM_TYPE, dataKind);
                        rawContactDelta, Photo.CONTENT_ITEM_TYPE, dataKind);
                if (valuesDeltas != null && !valuesDeltas.isEmpty()) {
                if (valuesDeltas != null && !valuesDeltas.isEmpty()) {
                    mPhotoRawContactId = rawContactDelta.getRawContactId();
                    mPhotoRawContactId = rawContactDelta.getRawContactId();
                    mPhoto.setValues(dataKind, valuesDeltas.get(0), rawContactDelta,
                    mPhoto.setValues(dataKind, valuesDeltas.get(0), rawContactDelta,
                            /* readOnly =*/ !dataKind.editable, mMaterialPalette,
                            !accountType.areContactsWritable(), mMaterialPalette,
                            viewIdGenerator);
                            viewIdGenerator);
                    return;
                    return;
                }
                }
@@ -347,13 +347,13 @@ public class CompactRawContactsEditorView extends LinearLayout implements View.O
            if (!rawContactDelta.isVisible()) continue;
            if (!rawContactDelta.isVisible()) continue;
            final AccountType accountType = rawContactDelta.getAccountType(mAccountTypeManager);
            final AccountType accountType = rawContactDelta.getAccountType(mAccountTypeManager);
            final DataKind dataKind = accountType.getKindForMimetype(Photo.CONTENT_ITEM_TYPE);
            final DataKind dataKind = accountType.getKindForMimetype(Photo.CONTENT_ITEM_TYPE);
            if (dataKind != null) {
            if (dataKind != null && dataKind.editable) {
                final ValuesDelta valuesDelta = rawContactDelta.getSuperPrimaryEntry(
                final ValuesDelta valuesDelta = rawContactDelta.getSuperPrimaryEntry(
                        dataKind.mimeType, /* forceSelection =*/ true);
                        dataKind.mimeType, /* forceSelection =*/ true);
                if (valuesDelta != null) {
                if (valuesDelta != null) {
                    mPhotoRawContactId = rawContactDelta.getRawContactId();
                    mPhotoRawContactId = rawContactDelta.getRawContactId();
                    mPhoto.setValues(dataKind, valuesDelta, rawContactDelta,
                    mPhoto.setValues(dataKind, valuesDelta, rawContactDelta,
                            /* readOnly =*/ !dataKind.editable, mMaterialPalette,
                            !accountType.areContactsWritable(), mMaterialPalette,
                            viewIdGenerator);
                            viewIdGenerator);
                    return;
                    return;
                }
                }
@@ -461,15 +461,12 @@ public class CompactRawContactsEditorView extends LinearLayout implements View.O


    private void addEditorViews(RawContactDeltaList rawContactDeltas) {
    private void addEditorViews(RawContactDeltaList rawContactDeltas) {
        for (RawContactDelta rawContactDelta : rawContactDeltas) {
        for (RawContactDelta rawContactDelta : rawContactDeltas) {
            if (!rawContactDelta.isVisible()) {
            if (!rawContactDelta.isVisible()) continue;
                continue;
            }
            final AccountType accountType = rawContactDelta.getAccountType(mAccountTypeManager);
            final AccountType accountType = rawContactDelta.getAccountType(mAccountTypeManager);


            for (DataKind dataKind : accountType.getSortedDataKinds()) {
            for (DataKind dataKind : accountType.getSortedDataKinds()) {
                if (!dataKind.editable) {
                if (!dataKind.editable) continue;
                    continue;

                }
                final String mimeType = dataKind.mimeType;
                final String mimeType = dataKind.mimeType;
                vlog(mimeType + " " + dataKind.fieldList.size() + " field(s)");
                vlog(mimeType + " " + dataKind.fieldList.size() + " field(s)");
                if (Photo.CONTENT_ITEM_TYPE.equals(mimeType)
                if (Photo.CONTENT_ITEM_TYPE.equals(mimeType)