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

Commit 50c6e498 authored by Selim Cinek's avatar Selim Cinek
Browse files

Fixed a bug where the media header wasn't indented

We need to remeasure in case we change the params.

Bug: 27494315
Change-Id: I8a4a0213db75f866a87a5c117f98d80fe80641c9
parent c317933a
Loading
Loading
Loading
Loading
+27 −13
Original line number Diff line number Diff line
@@ -89,36 +89,50 @@ public class MediaNotificationView extends FrameLayout {
        int topMargin = getMeasuredHeight() - mRightIcon.getMeasuredHeight()
                - iconParams.bottomMargin;
        // If the topMargin is high enough we can also remove the header constraint!
        boolean reMeasure = false;
        if (!hasIcon || topMargin >= mImageMinTopMargin) {
            resetHeaderIndention();
            reMeasure = resetHeaderIndention();
        } else {
            int paddingEnd = mNotificationContentImageMarginEnd;
            ViewGroup.MarginLayoutParams headerParams =
                    (MarginLayoutParams) mHeader.getLayoutParams();
            headerParams.setMarginEnd(mRightIcon.getMeasuredWidth() + iconParams.getMarginEnd());
            int newMarginEnd = mRightIcon.getMeasuredWidth() + iconParams.getMarginEnd();
            if (headerParams.getMarginEnd() != newMarginEnd) {
                headerParams.setMarginEnd(newMarginEnd);
                mHeader.setLayoutParams(headerParams);
                reMeasure = true;
            }
            if (mHeader.getPaddingEnd() != paddingEnd) {
                mHeader.setPadding(
                        isLayoutRtl() ? paddingEnd : mHeader.getPaddingLeft(),
                mHeader.setPaddingRelative(mHeader.getPaddingStart(),
                        mHeader.getPaddingTop(),
                        isLayoutRtl() ? mHeader.getPaddingLeft() : paddingEnd,
                        paddingEnd,
                        mHeader.getPaddingBottom());
                mHeader.setLayoutParams(headerParams);
                reMeasure = true;
            }
        }
        if (reMeasure) {
            measureChildWithMargins(mHeader, widthMeasureSpec, 0, heightMeasureSpec, 0);
        }
    }

    private void resetHeaderIndention() {
    private boolean resetHeaderIndention() {
        boolean remeasure = false;
        if (mHeader.getPaddingEnd() != mNotificationContentMarginEnd) {
            mHeader.setPaddingRelative(mHeader.getPaddingStart(),
                    mHeader.getPaddingTop(),
                    mNotificationContentMarginEnd,
                    mHeader.getPaddingBottom());
            remeasure = true;
        }
        ViewGroup.MarginLayoutParams headerParams =
                (MarginLayoutParams) mHeader.getLayoutParams();
        headerParams.setMarginEnd(0);
            mHeader.setPadding(
                    isLayoutRtl() ? mNotificationContentMarginEnd : mHeader.getPaddingLeft(),
                    mHeader.getPaddingTop(),
                    isLayoutRtl() ? mHeader.getPaddingLeft() : mNotificationContentMarginEnd,
                    mHeader.getPaddingBottom());
        if (headerParams.getMarginEnd() != 0) {
            headerParams.setMarginEnd(0);
            mHeader.setLayoutParams(headerParams);
            remeasure = true;
        }
        return remeasure;
    }

    public MediaNotificationView(Context context, AttributeSet attrs, int defStyleAttr,