package com.lynx.tasm.behavior.ui.scroll;

import X.7tl;
import X.C3890QeN;
import X.C4398QmZ;
import X.C4480Qnt;
import X.C4502QoF;
import X.C4589Qpe;
import X.C4595Qpk;
import X.C4596Qpl;
import X.C4598Qpn;
import X.JuW;
import X.LC0;
import X.QNL;
import X.QWT;
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Rect;
import android.view.View;
import com.bytedance.covode.number.Covode;
import com.lynx.react.bridge.ReadableMap;
import com.lynx.tasm.base.LLog;
import com.lynx.tasm.behavior.ui.LynxBaseUI;
import com.lynx.tasm.behavior.ui.LynxFlattenUI;
import com.lynx.tasm.utils.DisplayMetricsHolder;
import java.util.Map;

public class UIScrollView extends AbsLynxUIScroll<C4589Qpe> implements C4480Qnt {
    public boolean LIZ;
    public boolean LIZIZ;
    public boolean LIZJ;
    public boolean LIZLLL;
    public boolean LJ;
    public boolean LJFF;
    public boolean LJI;
    public int LJII = 1;
    public boolean LJIIIIZZ;
    public boolean LJIIIZ;
    public int LJIIJ;
    public int LJIIJJI;
    public int LJIIL;
    public UIBounceView LJIILIIL;
    public boolean LJIILJJIL = true;

    static {
        Covode.recordClassIndex(46741);
    }

    public static boolean LIZ(int i) {
        return (i & 1) != 0;
    }

    public static boolean LIZIZ(int i) {
        return (i & 2) != 0;
    }

    public Rect getBoundRectForOverflow() {
        return null;
    }

    public int getOverflow() {
        return 0;
    }

    public boolean isScrollContainer() {
        return true;
    }

    public final void LIZ() {
        this.LJI = true;
        LIZLLL();
    }

    public final void LIZJ() {
        if (this.mView != null) {
            ((C4589Qpe) this.mView).fling(0);
        }
    }

    public View getRealParentView() {
        C4589Qpe qpe = (C4589Qpe) this.mView;
        if (qpe == null) {
            return null;
        }
        return qpe.getLinearLayout();
    }

    public int getScrollX() {
        return ((C4589Qpe) this.mView).getHScrollView().getScrollX();
    }

    public int getScrollY() {
        return ((C4589Qpe) this.mView).getScrollY();
    }

    private void LJFF() {
        if (this.LJIIIIZZ) {
            ((C4589Qpe) this.mView).setOrientation(1);
        } else {
            ((C4589Qpe) this.mView).setOrientation(0);
        }
    }

    public final void LIZIZ() {
        if (this.mView != null) {
            ((C4589Qpe) this.mView).getHScrollView().fling(0);
        }
    }

    public final void LIZLLL() {
        int scrollX = getScrollX();
        int scrollY = getScrollY();
        for (int i = 0; i < this.mChildren.size(); i++) {
            this.mChildren.get(i).checkStickyOnParentScroll(scrollX, scrollY);
        }
    }

    public void invalidate() {
        ((C4589Qpe) this.mView).getLinearLayout().invalidate();
        ((C4589Qpe) this.mView).invalidate();
    }

    public void onLayoutUpdated() {
        super.onLayoutUpdated();
        int i = this.mPaddingLeft + this.mBorderLeftWidth;
        int i2 = this.mPaddingRight + this.mBorderRightWidth;
        ((C4589Qpe) this.mView).setPadding(i, this.mPaddingTop + this.mBorderTopWidth, i2, this.mPaddingBottom + this.mBorderBottomWidth);
    }

    public void layout() {
        super.layout();
        int i = this.LJIIJ;
        if (i <= 0) {
            return;
        }
        if (this.LJIIIIZZ && i + getHeight() <= ((C4589Qpe) this.mView).getContentHeight()) {
            ((C4589Qpe) this.mView).LIZ(((C4589Qpe) this.mView).getRealScrollX(), this.LJIIJ, false);
            this.LJIIJ = 0;
        } else if (!this.LJIIIIZZ && this.LJIIJ + getWidth() <= ((C4589Qpe) this.mView).getContentWidth()) {
            ((C4589Qpe) this.mView).LIZ(this.LJIIJ, ((C4589Qpe) this.mView).getRealScrollY(), false);
            this.LJIIJ = 0;
        }
    }

    public final void LJ() {
        int width;
        int height;
        UIBounceView uIBounceView = this.LJIILIIL;
        if (uIBounceView == null) {
            return;
        }
        if (this.LJIIIIZZ) {
            if (uIBounceView.LIZ == 3 && this.LJIILIIL.getTop() < getScrollY() + getHeight()) {
                height = this.LJIILIIL.getTop() - getHeight();
            } else if (this.LJIILIIL.LIZ == 2 && this.LJIILIIL.getHeight() > getScrollY()) {
                height = this.LJIILIIL.getHeight();
            } else {
                return;
            }
            if (height > 0) {
                LIZJ();
                ((C4589Qpe) this.mView).LIZ(0, height, true);
                return;
            }
            return;
        }
        if (uIBounceView.LIZ == 0 && this.LJIILIIL.getLeft() < getScrollX() + getWidth()) {
            width = this.LJIILIIL.getLeft() - getWidth();
        } else if (this.LJIILIIL.LIZ == 1 && this.LJIILIIL.getWidth() > getScrollX()) {
            width = this.LJIILIIL.getWidth();
        } else {
            return;
        }
        if (width > 0) {
            LIZIZ();
            ((C4589Qpe) this.mView).LIZ(width, 0, true);
        }
    }

    public void measure() {
        boolean z;
        if (((C4589Qpe) this.mView).getOrientation() == 0) {
            z = true;
        } else {
            z = false;
        }
        int width = getWidth();
        int height = getHeight();
        for (int i = 0; i < getChildCount(); i++) {
            LynxBaseUI childAt = getChildAt(i);
            if (z) {
                width = Math.max(width, childAt.getWidth() + childAt.getLeft() + childAt.mMarginRight + this.mPaddingRight);
            } else {
                height = Math.max(height, childAt.getHeight() + childAt.getTop() + childAt.mMarginBottom);
            }
        }
        if (!(((C4589Qpe) this.mView).getContentWidth() == width && ((C4589Qpe) this.mView).getContentHeight() == height)) {
            float f = (float) width;
            float f2 = (float) height;
            if (this.LJIIIZ && DisplayMetricsHolder.LIZ() != null) {
                QWT qwt = new QWT(getSign(), "contentsizechanged");
                qwt.LIZ("scrollWidth", Float.valueOf(f / DisplayMetricsHolder.LIZ().density));
                qwt.LIZ("scrollHeight", Float.valueOf(f2 / DisplayMetricsHolder.LIZ().density));
                if (this.mContext != null) {
                    this.mContext.LJFF.LIZ((C4502QoF) qwt);
                }
            }
            C4589Qpe qpe = (C4589Qpe) this.mView;
            qpe.LJII = height;
            qpe.LJI = width;
            if (qpe.LIZIZ != null) {
                qpe.LIZIZ.requestLayout();
            }
        }
        super.measure();
    }

    public void setLowerThreshole(int i) {
        this.LJIIJJI = i;
    }

    public void setScrollTap(boolean z) {
        this.LJFF = z;
    }

    public void setUpperThreshole(int i) {
        this.LJIIL = i;
    }

    public UIScrollView(C4398QmZ qmZ) {
        super(qmZ);
    }

    public final void LIZIZ(boolean z) {
        this.LJIIIIZZ = !z;
        LJFF();
    }

    public /* synthetic */ View createView(Context context) {
        final C4589Qpe qpe = new C4589Qpe(context, this);
        qpe.setOnScrollListener(new C4598Qpn() {
            static {
                Covode.recordClassIndex(46744);
            }

            public final void LIZJ() {
                T t = UIScrollView.this.mView;
                if (t != null && UIScrollView.this.mEnableScrollMonitor) {
                    UIScrollView.this.mContext.LJIIJJI.LIZJ(new JuW(t, UIScrollView.this.getTagName(), UIScrollView.this.mScrollMonitorTag));
                }
            }

            public final void LIZ() {
                if (UIScrollView.this.LJ) {
                    UIScrollView uIScrollView = UIScrollView.this;
                    uIScrollView.LIZ(uIScrollView.getScrollX(), UIScrollView.this.getScrollY(), UIScrollView.this.getScrollX(), UIScrollView.this.getScrollY(), "scrollend");
                }
                if (UIScrollView.this.mEnableScrollMonitor) {
                    UIScrollView.this.mContext.LJIIJJI.LIZIZ(new JuW(qpe, UIScrollView.this.getTagName(), UIScrollView.this.mScrollMonitorTag));
                }
            }

            public final void LIZIZ() {
                if (UIScrollView.this.LJI) {
                    UIScrollView.this.LIZLLL();
                }
                if (UIScrollView.this.LIZLLL) {
                    UIScrollView uIScrollView = UIScrollView.this;
                    uIScrollView.LIZ(uIScrollView.getScrollX(), UIScrollView.this.getScrollY(), UIScrollView.this.getScrollX(), UIScrollView.this.getScrollY(), "scrollstart");
                }
                if (UIScrollView.this.mEnableScrollMonitor) {
                    UIScrollView.this.mContext.LJIIJJI.LIZ(new JuW(qpe, UIScrollView.this.getTagName(), UIScrollView.this.mScrollMonitorTag));
                }
            }

            public final void LIZ(int i) {
                LLog.LIZ(4, "LynxUIScrollView", "onScrollStateChanged: ".concat(String.valueOf(i)));
                if (!UIScrollView.this.LJFF) {
                    if (i != 0) {
                        UIScrollView.this.recognizeGesturere();
                    }
                } else if (i == 1) {
                    UIScrollView.this.recognizeGesturere();
                }
            }

            public final void LIZ(int i, int i2, int i3, int i4) {
                if (UIScrollView.this.LJI) {
                    UIScrollView.this.LIZLLL();
                }
                int i5 = i2;
                int i6 = i;
                if (UIScrollView.this.LIZJ) {
                    UIScrollView.this.LIZ(i6, i5, i3, i4, "scroll");
                }
                if (UIScrollView.this.LIZIZ || UIScrollView.this.LIZ) {
                    int LIZ2 = UIScrollView.this.LIZ(i6, i5);
                    if (UIScrollView.this.LIZIZ && UIScrollView.LIZIZ(LIZ2) && !UIScrollView.LIZIZ(UIScrollView.this.LJII)) {
                        UIScrollView uIScrollView = UIScrollView.this;
                        uIScrollView.LIZ(uIScrollView.getScrollX(), UIScrollView.this.getScrollY(), UIScrollView.this.getScrollX(), UIScrollView.this.getScrollY(), "scrolltolower");
                    } else if (UIScrollView.this.LIZ && UIScrollView.LIZ(LIZ2) && !UIScrollView.LIZ(UIScrollView.this.LJII)) {
                        UIScrollView uIScrollView2 = UIScrollView.this;
                        uIScrollView2.LIZ(uIScrollView2.getScrollX(), UIScrollView.this.getScrollY(), UIScrollView.this.getScrollX(), UIScrollView.this.getScrollY(), "scrolltoupper");
                    }
                    UIScrollView.this.LJII = LIZ2;
                }
            }
        });
        return qpe;
    }

    @QNL(LIZ = "enable-nested-scroll", LJFF = false)
    public void setEnableNestedScroll(boolean z) {
        if (this.mView != null) {
            ((C4589Qpe) this.mView).setNestedScrollingEnabled(z);
        }
    }

    public void setEnableScroll(boolean z) {
        if (this.mView != null) {
            ((C4589Qpe) this.mView).setEnableScroll(z);
        }
        this.LJIILJJIL = z;
    }

    public void setForbidFlingFocusChange(boolean z) {
        if (this.mView != null) {
            ((C4589Qpe) this.mView).LJIILL = true;
        }
    }

    public void setScrollBarEnable(boolean z) {
        try {
            ((C4589Qpe) this.mView).setScrollBarEnable(Boolean.valueOf(z).booleanValue());
        } catch (Exception e) {
            LLog.LIZ(6, "UIScrollView", e.getMessage());
        }
    }

    public void setScrollLeft(int i) {
        int realScrollY = ((C4589Qpe) this.mView).getRealScrollY();
        int LIZ2 = (int) C3890QeN.LIZ((float) i);
        if (getWidth() + LIZ2 <= ((C4589Qpe) this.mView).getContentWidth()) {
            ((C4589Qpe) this.mView).LIZ(LIZ2, realScrollY, false);
            this.LJIIJ = 0;
            return;
        }
        this.LJIIJ = LIZ2;
    }

    public void setScrollTop(int i) {
        int realScrollX = ((C4589Qpe) this.mView).getRealScrollX();
        int LIZ2 = (int) C3890QeN.LIZ((float) i);
        if (getHeight() + LIZ2 <= ((C4589Qpe) this.mView).getContentHeight()) {
            ((C4589Qpe) this.mView).LIZ(realScrollX, LIZ2, false);
            this.LJIIJ = 0;
            return;
        }
        this.LJIIJ = LIZ2;
    }

    @7tl
    public void autoScroll(ReadableMap readableMap) {
        if (this.LJIILJJIL) {
            C4589Qpe qpe = (C4589Qpe) this.mView;
            double d = readableMap.getDouble("rate", 0.0d);
            if (!readableMap.getBoolean("start", true)) {
                qpe.LJIILIIL = false;
                qpe.LJIILJJIL = 0;
            } else if (d > 0.0d && !qpe.LJIILIIL) {
                qpe.LJIILIIL = true;
                qpe.LJIILJJIL = (int) Math.max((double) C3890QeN.LIZ((float) (d / 60.0d)), 1.0d);
                qpe.LJIIL = new C4595Qpk(qpe, (byte) 0);
                qpe.post(qpe.LJIIL);
            }
        }
    }

    @7tl
    public void scrollTo(ReadableMap readableMap) {
        if (this.LJIILJJIL) {
            double d = readableMap.getDouble("offset", 0.0d);
            int i = readableMap.getInt("index", -1);
            double d2 = d * ((double) DisplayMetricsHolder.LIZ().density);
            boolean z = readableMap.getBoolean("smooth", false);
            if (this.LJIIIIZZ) {
                if (i >= 0 && i < this.mChildren.size()) {
                    d2 += (double) this.mChildren.get(i).getTop();
                }
                ((C4589Qpe) this.mView).LIZ(0, (int) d2, z);
                return;
            }
            if (i >= 0 && i < this.mChildren.size()) {
                d2 += (double) this.mChildren.get(i).getLeft();
            }
            ((C4589Qpe) this.mView).LIZ((int) d2, 0, z);
        }
    }

    public void scrollToIndex(int i) {
        if (i >= 0 && i < this.mChildren.size()) {
            if (this.LJIIIIZZ) {
                ((C4589Qpe) this.mView).LIZ(((C4589Qpe) this.mView).getRealScrollX(), this.mChildren.get(i).getTop(), false);
                return;
            }
            int realScrollY = ((C4589Qpe) this.mView).getRealScrollY();
            ((C4589Qpe) this.mView).LIZ(this.mChildren.get(i).getLeft(), realScrollY, false);
        }
    }

    public void setEvents(Map<String, LC0> map) {
        super.setEvents(map);
        if (map != null) {
            this.LIZ = false;
            this.LIZIZ = false;
            this.LIZJ = false;
            this.LJ = false;
            if (map.containsKey("scrolltolower")) {
                this.LIZIZ = true;
            }
            if (map.containsKey("scrolltoupper")) {
                this.LIZ = true;
            }
            if (map.containsKey("scroll")) {
                this.LIZJ = true;
            }
            if (map.containsKey("scrollstart")) {
                this.LIZLLL = true;
            }
            if (map.containsKey("scrollend")) {
                this.LJ = true;
            }
            if (map.containsKey("contentsizechanged")) {
                this.LJIIIZ = true;
            }
        }
    }

    public void setLynxDirection(int i) {
        this.mLynxDirection = i;
        if (i == 2) {
            ((C4589Qpe) this.mView).setLayoutDirection(1);
            ((C4589Qpe) this.mView).getHScrollView().setLayoutDirection(1);
            ((C4589Qpe) this.mView).getLinearLayout().setLayoutDirection(1);
            return;
        }
        ((C4589Qpe) this.mView).setLayoutDirection(0);
        ((C4589Qpe) this.mView).getHScrollView().setLayoutDirection(0);
        ((C4589Qpe) this.mView).getLinearLayout().setLayoutDirection(0);
    }

    public final void LIZ(boolean z) {
        this.LJIIIIZZ = z;
        LJFF();
    }

    public void drawChild(LynxFlattenUI lynxFlattenUI, Canvas canvas) {
        super.drawChild(lynxFlattenUI, canvas);
    }

    public void insertChild(LynxBaseUI lynxBaseUI, int i) {
        super.insertChild(lynxBaseUI, i);
        if (lynxBaseUI instanceof UIBounceView) {
            this.LJIILIIL = (UIBounceView) lynxBaseUI;
        }
    }

    public final int LIZ(int i, int i2) {
        if (this.LJIIIIZZ) {
            return LIZ(i2, this.LJIIL, this.LJIIJJI, 1, 2);
        }
        int i3 = i;
        if (this.mLynxDirection == 2) {
            return LIZ(i3, this.LJIIJJI, this.LJIIL, 2, 1);
        }
        return LIZ(i3, this.LJIIL, this.LJIIJJI, 1, 2);
    }

    public final void LIZ(LynxBaseUI lynxBaseUI, boolean z, String str, String str2) {
        LIZ(lynxBaseUI, z, str, str2, 0);
    }

    private int LIZ(int i, int i2, int i3, int i4, int i5) {
        int measuredWidth;
        int measuredWidth2;
        if (i <= i2) {
            return 0 | i4;
        }
        if (((C4589Qpe) this.mView).getHScrollView() == null) {
            return 0;
        }
        View childAt = ((C4589Qpe) this.mView).getHScrollView().getChildAt(0);
        if (this.LJIIIIZZ) {
            measuredWidth = childAt.getMeasuredHeight();
            measuredWidth2 = ((C4589Qpe) this.mView).getMeasuredHeight();
        } else {
            measuredWidth = childAt.getMeasuredWidth();
            measuredWidth2 = ((C4589Qpe) this.mView).getMeasuredWidth();
        }
        if (i >= (measuredWidth - measuredWidth2) - i3) {
            return 0 | i5;
        }
        return 0;
    }

    public final void LIZ(int i, int i2, int i3, int i4, String str) {
        C4596Qpl LIZ2 = C4596Qpl.LIZ(getSign(), str);
        int i5 = i;
        int i6 = i2;
        LIZ2.LIZ(i5, i6, ((C4589Qpe) this.mView).getContentHeight(), ((C4589Qpe) this.mView).getContentWidth(), i5 - i3, i6 - i4);
        if (this.mContext != null) {
            this.mContext.LJFF.LIZ((C4502QoF) LIZ2);
        }
    }

    /* JADX WARNING: Removed duplicated region for block: B:27:0x0097  */
    /* Code decompiled incorrectly, please refer to instructions dump. */
    public final void LIZ(com.lynx.tasm.behavior.ui.LynxBaseUI r6, boolean r7, java.lang.String r8, java.lang.String r9, int r10) {
        /*
            r5 = this;
            boolean r4 = r5.LJIIIIZZ
            java.lang.String r3 = "end"
            java.lang.String r1 = "center"
            java.lang.String r0 = "nearest"
            r2 = 0
            if (r4 == 0) goto L_0x0077
            boolean r0 = r0.equals(r8)
            if (r0 == 0) goto L_0x0012
            return
        L_0x0012:
            boolean r0 = r1.equals(r8)
            if (r0 == 0) goto L_0x003d
            T r0 = r5.mView
            X.Qpe r0 = (X.C4589Qpe) r0
            int r1 = r0.getHeight()
            int r0 = r6.getHeight()
            int r1 = r1 - r0
            int r0 = r1 / 2
            int r3 = 0 - r0
        L_0x0029:
            if (r6 == r5) goto L_0x0056
            int r0 = r6.getTop()
            int r3 = r3 + r0
            X.Qnk r6 = r6.mParent
            com.lynx.tasm.behavior.ui.LynxBaseUI r6 = (com.lynx.tasm.behavior.ui.LynxBaseUI) r6
        L_0x0034:
            boolean r0 = r6 instanceof com.lynx.tasm.behavior.ui.LynxFlattenUI
            if (r0 == 0) goto L_0x0029
            X.Qnk r6 = r6.mParent
            com.lynx.tasm.behavior.ui.LynxBaseUI r6 = (com.lynx.tasm.behavior.ui.LynxBaseUI) r6
            goto L_0x0034
        L_0x003d:
            boolean r0 = r3.equals(r8)
            if (r0 == 0) goto L_0x0054
            T r0 = r5.mView
            X.Qpe r0 = (X.C4589Qpe) r0
            int r1 = r0.getHeight()
            int r0 = r6.getHeight()
            int r1 = r1 - r0
            int r3 = 0 - r1
            int r3 = r3 + r10
            goto L_0x0029
        L_0x0054:
            r3 = 0
            goto L_0x0029
        L_0x0056:
            T r0 = r5.mView
            X.Qpe r0 = (X.C4589Qpe) r0
            int r1 = r0.getContentHeight()
            T r0 = r5.mView
            X.Qpe r0 = (X.C4589Qpe) r0
            int r0 = r0.getHeight()
            int r1 = r1 - r0
            int r0 = java.lang.Math.min(r3, r1)
            int r1 = java.lang.Math.max(r2, r0)
            T r0 = r5.mView
            X.Qpe r0 = (X.C4589Qpe) r0
            r0.LIZ((int) r2, (int) r1, (boolean) r7)
            return
        L_0x0077:
            boolean r0 = r0.equals(r9)
            if (r0 == 0) goto L_0x007e
            return
        L_0x007e:
            boolean r0 = r1.equals(r9)
            if (r0 == 0) goto L_0x00a9
            T r0 = r5.mView
            X.Qpe r0 = (X.C4589Qpe) r0
            int r1 = r0.getWidth()
            int r0 = r6.getWidth()
            int r1 = r1 - r0
            int r1 = r1 / 2
        L_0x0093:
            int r3 = 0 - r1
        L_0x0095:
            if (r6 == r5) goto L_0x00bf
            int r0 = r6.getLeft()
            int r3 = r3 + r0
            X.Qnk r6 = r6.mParent
            com.lynx.tasm.behavior.ui.LynxBaseUI r6 = (com.lynx.tasm.behavior.ui.LynxBaseUI) r6
        L_0x00a0:
            boolean r0 = r6 instanceof com.lynx.tasm.behavior.ui.LynxFlattenUI
            if (r0 == 0) goto L_0x0095
            X.Qnk r6 = r6.mParent
            com.lynx.tasm.behavior.ui.LynxBaseUI r6 = (com.lynx.tasm.behavior.ui.LynxBaseUI) r6
            goto L_0x00a0
        L_0x00a9:
            boolean r0 = r3.equals(r9)
            if (r0 == 0) goto L_0x00bd
            T r0 = r5.mView
            X.Qpe r0 = (X.C4589Qpe) r0
            int r1 = r0.getWidth()
            int r0 = r6.getWidth()
            int r1 = r1 - r0
            goto L_0x0093
        L_0x00bd:
            r3 = 0
            goto L_0x0095
        L_0x00bf:
            T r0 = r5.mView
            X.Qpe r0 = (X.C4589Qpe) r0
            int r1 = r0.getContentWidth()
            T r0 = r5.mView
            X.Qpe r0 = (X.C4589Qpe) r0
            int r0 = r0.getWidth()
            int r1 = r1 - r0
            int r0 = java.lang.Math.min(r3, r1)
            int r1 = java.lang.Math.max(r2, r0)
            T r0 = r5.mView
            X.Qpe r0 = (X.C4589Qpe) r0
            r0.LIZ((int) r1, (int) r2, (boolean) r7)
            return
        */
        throw new UnsupportedOperationException("Method not decompiled: com.lynx.tasm.behavior.ui.scroll.UIScrollView.LIZ(com.lynx.tasm.behavior.ui.LynxBaseUI, boolean, java.lang.String, java.lang.String, int):void");
    }
}
