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

Commit 18724188 authored by Gary Mai's avatar Gary Mai
Browse files

Write null into file ID when removing photo

Writing null into the file ID of the photos value delta
'after' will prevent the editor from trying to read it after a
rotation.
Have the photo editor view hold on to the MaterialPalette so we
use the same color for the default once a photo is removed.

Test: Manual usage of removing a photo from a contact with one and
rotating.

Bug: 25978539

Change-Id: I84c4b22c4064de1d788b08921a5c0164475865af
parent d5aebc59
Loading
Loading
Loading
Loading
+8 −5
Original line number Diff line number Diff line
@@ -65,6 +65,7 @@ public class CompactPhotoEditorView extends RelativeLayout implements View.OnCli
    private View mPhotoIcon;
    private View mPhotoIconOverlay;
    private View mPhotoTouchInterceptOverlay;
    private MaterialPalette mMaterialPalette;

    private boolean mReadOnly;
    private boolean mIsNonDefaultPhotoBound;
@@ -122,12 +123,16 @@ public class CompactPhotoEditorView extends RelativeLayout implements View.OnCli
        }
    }

    public void setPalette(MaterialPalette palette) {
        mMaterialPalette = palette;
    }

    /**
     * Tries to bind a full size photo or a bitmap loaded from the given ValuesDelta,
     * and falls back to the default avatar, tinted using the given MaterialPalette (if it's not
     * null);
     */
    public void setPhoto(ValuesDelta valuesDelta, MaterialPalette materialPalette) {
    public void setPhoto(ValuesDelta valuesDelta) {
        // Check if we can update to the full size photo immediately
        final Long photoFileId = EditorUiUtils.getPhotoFileId(valuesDelta);
        if (photoFileId != null) {
@@ -146,7 +151,7 @@ public class CompactPhotoEditorView extends RelativeLayout implements View.OnCli
            return;
        }

        setDefaultPhoto(materialPalette);
        setDefaultPhoto(mMaterialPalette);
        adjustDimensions();
    }

@@ -223,9 +228,7 @@ public class CompactPhotoEditorView extends RelativeLayout implements View.OnCli
     * Removes the current bound photo bitmap.
     */
    public void removePhoto() {
        mPhotoImageView.setImageBitmap(/* bitmap =*/ null);
        mIsNonDefaultPhotoBound = false;
        setDefaultPhoto(/* materialPalette =*/ null);
        setDefaultPhoto(mMaterialPalette);
    }

    @Override
+3 −1
Original line number Diff line number Diff line
@@ -384,6 +384,7 @@ public class CompactRawContactsEditorView extends LinearLayout implements View.O
    public void removePhoto() {
        mPhotoValuesDelta.setFromTemplate(true);
        mPhotoValuesDelta.put(Photo.PHOTO, (byte[]) null);
        mPhotoValuesDelta.put(Photo.PHOTO_FILE_ID, (String) null);

        mPhotoView.removePhoto();
    }
@@ -940,7 +941,8 @@ public class CompactRawContactsEditorView extends LinearLayout implements View.O
            return;
        }
        // Set the photo view
        mPhotoView.setPhoto(superPrimaryDelta, mMaterialPalette);
        mPhotoView.setPalette(mMaterialPalette);
        mPhotoView.setPhoto(superPrimaryDelta);

        if (isReadOnlyRawContact()) {
            mPhotoView.setReadOnly(true);