package com.lynx.tasm.image;

import X.C3264QMj;
import X.C3275QMu;
import X.C4398QmZ;
import X.LC0;
import X.QMA;
import X.QMT;
import X.QMW;
import X.QMY;
import X.QNZ;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.Rect;
import com.bytedance.covode.number.Covode;
import com.lynx.tasm.behavior.ui.LynxFlattenUI;
import java.util.Map;

public class LynxFlattenImageUI extends LynxFlattenUI {
    public QMY LIZIZ;
    public QMY LIZJ;
    public QMA<Bitmap> LIZLLL;
    public QMA<Bitmap> LJ;
    public boolean LJFF;
    public boolean LJI;
    public final C3264QMj LJII;
    public final QMW LJIIIIZZ;
    public final Paint LJIIIZ;
    public final Rect LJIIJ = new Rect();
    public final Rect LJIIJJI = new Rect();

    static {
        Covode.recordClassIndex(46920);
    }

    public void destroy() {
        QMA<Bitmap> qma = this.LJ;
        if (qma != null) {
            qma.LIZJ();
            this.LJ = null;
        }
        QMA<Bitmap> qma2 = this.LIZLLL;
        if (qma2 != null) {
            qma2.LIZJ();
            this.LIZLLL = null;
        }
        this.LJII.LIZJ();
        QMY qmy = this.LIZIZ;
        if (qmy != null) {
            qmy.LIZIZ();
            this.LIZIZ = null;
        }
        QMY qmy2 = this.LIZJ;
        if (qmy2 != null) {
            qmy2.LIZIZ();
            this.LIZJ = null;
        }
        super.destroy();
    }

    public void onLayoutUpdated() {
        super.onLayoutUpdated();
        this.LJII.LIZ(getWidth(), getHeight(), this.mPaddingLeft, this.mPaddingTop, this.mPaddingRight, this.mPaddingBottom, this.mBorderLeftWidth, this.mBorderTopWidth, this.mBorderRightWidth, this.mBorderBottomWidth);
    }

    public void afterPropsUpdated(QNZ qnz) {
        super.afterPropsUpdated(qnz);
        this.LJII.LIZ(qnz);
    }

    public void setEvents(Map<String, LC0> map) {
        super.setEvents(map);
        this.LJII.LIZ(map);
    }

    public void updateAttributes(QNZ qnz) {
        super.updateAttributes(qnz);
        this.LJII.LIZ(qnz);
    }

    public LynxFlattenImageUI(C4398QmZ qmZ) {
        super(qmZ);
        Paint paint = new Paint(1);
        this.LJIIIZ = paint;
        paint.setFilterBitmap(true);
        C3264QMj qMj = new C3264QMj(qmZ, this, new C3275QMu() {
            static {
                Covode.recordClassIndex(46923);
            }

            public final void LIZ(String str, QMA<Bitmap> qma, boolean z) {
                LynxFlattenImageUI.this.LJFF = z;
                if (z && LynxFlattenImageUI.this.LIZIZ != null) {
                    LynxFlattenImageUI.this.LIZIZ.LIZ();
                }
                LynxFlattenImageUI.this.LIZLLL = qma;
                LynxFlattenImageUI.this.invalidate();
            }

            public final void LIZIZ(String str, QMA<Bitmap> qma, boolean z) {
                LynxFlattenImageUI.this.LJI = z;
                if (z && LynxFlattenImageUI.this.LIZJ != null) {
                    LynxFlattenImageUI.this.LIZJ.LIZ();
                }
                LynxFlattenImageUI.this.LJ = qma;
                LynxFlattenImageUI.this.invalidate();
            }
        });
        this.LJII = qMj;
        this.LJIIIIZZ = qMj.LIZ;
    }

    public final void LIZJ(Canvas canvas) {
        Bitmap LIZIZ2;
        QMA<Bitmap> qma;
        Bitmap LIZIZ3;
        QMA<Bitmap> qma2;
        super.LIZJ(canvas);
        if (!this.LJFF || (qma2 = this.LIZLLL) == null || qma2.LIZIZ() == null) {
            QMA<Bitmap> qma3 = this.LIZLLL;
            if (qma3 != null && (LIZIZ3 = qma3.LIZIZ()) != null) {
                LIZ(LIZIZ3, getWidth(), getHeight());
                canvas.drawBitmap(LIZIZ3, this.LJIIJ, this.LJIIJJI, this.LJIIIZ);
            } else if (!this.LJI || (qma = this.LJ) == null || qma.LIZIZ() == null) {
                QMA<Bitmap> qma4 = this.LJ;
                if (qma4 != null && (LIZIZ2 = qma4.LIZIZ()) != null) {
                    LIZ(LIZIZ2, getWidth(), getHeight());
                    canvas.drawBitmap(LIZIZ2, this.LJIIJ, this.LJIIJJI, this.LJIIIZ);
                }
            } else {
                if (this.LIZJ == null) {
                    this.LIZJ = QMT.LIZIZ();
                }
                this.LIZJ.LIZ(canvas, this.LJ, this.LJIIIIZZ);
            }
        } else {
            if (this.LIZIZ == null) {
                this.LIZIZ = QMT.LIZ();
            }
            this.LIZIZ.LIZ(canvas, this.LIZLLL, this.LJIIIIZZ);
        }
    }

    public void setBorderRadius(int i, float f, float f2) {
        super.setBorderRadius(i, f, f2);
        this.LJII.LIZ(i, f, f2);
    }

    private void LIZ(Bitmap bitmap, int i, int i2) {
        this.LJIIJ.left = 0;
        this.LJIIJ.top = 0;
        this.LJIIJ.right = bitmap.getWidth();
        this.LJIIJ.bottom = bitmap.getHeight();
        this.LJIIJJI.left = 0;
        this.LJIIJJI.top = 0;
        this.LJIIJJI.right = i;
        this.LJIIJJI.bottom = i2;
    }
}
