package o;

import android.view.animation.Interpolator;
import android.widget.OverScroller;
import androidx.recyclerview.widget.RecyclerView;
import java.util.Arrays;
import java.util.WeakHashMap;

/* compiled from: r8-map-id-3b7cc9102578c509342fa2f0fabed2bfc72239cd258d579fc679bfcbc198b048 */
/* renamed from: o.s10, reason: case insensitive filesystem */
/* loaded from: classes.dex */
public final class RunnableC2393s10 implements Runnable {
    public int l;
    public int m;
    public OverScroller n;

    /* renamed from: o, reason: collision with root package name */
    public Interpolator f710o;
    public boolean p;
    public boolean q;
    public final /* synthetic */ RecyclerView r;

    public RunnableC2393s10(RecyclerView recyclerView) {
        this.r = recyclerView;
        V00 v00 = RecyclerView.F0;
        this.f710o = v00;
        this.p = false;
        this.q = false;
        this.n = new OverScroller(recyclerView.getContext(), v00);
    }

    public final void a() {
        if (this.p) {
            this.q = true;
            return;
        }
        RecyclerView recyclerView = this.r;
        recyclerView.removeCallbacks(this);
        WeakHashMap weakHashMap = Oj0.a;
        recyclerView.postOnAnimation(this);
    }

    public final void b(int i, int i2, int i3, Interpolator interpolator) {
        int iRound;
        RecyclerView recyclerView = this.r;
        if (i3 == Integer.MIN_VALUE) {
            int iAbs = Math.abs(i);
            int iAbs2 = Math.abs(i2);
            boolean z = iAbs > iAbs2;
            int iSqrt = (int) Math.sqrt(0);
            int iSqrt2 = (int) Math.sqrt((i2 * i2) + (i * i));
            int width = z ? recyclerView.getWidth() : recyclerView.getHeight();
            int i4 = width / 2;
            float f = width;
            float f2 = i4;
            float fSin = (((float) Math.sin((Math.min(1.0f, (iSqrt2 * 1.0f) / f) - 0.5f) * 0.47123894f)) * f2) + f2;
            if (iSqrt > 0) {
                iRound = Math.round(Math.abs(fSin / iSqrt) * 1000.0f) * 4;
            } else {
                if (!z) {
                    iAbs = iAbs2;
                }
                iRound = (int) (((iAbs / f) + 1.0f) * 300.0f);
            }
            i3 = Math.min(iRound, 2000);
        }
        int i5 = i3;
        if (interpolator == null) {
            interpolator = RecyclerView.F0;
        }
        if (this.f710o != interpolator) {
            this.f710o = interpolator;
            this.n = new OverScroller(recyclerView.getContext(), interpolator);
        }
        this.m = 0;
        this.l = 0;
        recyclerView.setScrollState(2);
        this.n.startScroll(0, 0, i, i2, i5);
        a();
    }

    @Override // java.lang.Runnable
    public final void run() {
        int i;
        int i2;
        int i3;
        int i4;
        RecyclerView recyclerView = this.r;
        int[] iArr = recyclerView.z0;
        if (recyclerView.w == null) {
            recyclerView.removeCallbacks(this);
            this.n.abortAnimation();
            return;
        }
        this.q = false;
        this.p = true;
        recyclerView.m();
        OverScroller overScroller = this.n;
        if (overScroller.computeScrollOffset()) {
            int currX = overScroller.getCurrX();
            int currY = overScroller.getCurrY();
            int i5 = currX - this.l;
            int i6 = currY - this.m;
            this.l = currX;
            this.m = currY;
            int[] iArr2 = recyclerView.z0;
            iArr2[0] = 0;
            iArr2[1] = 0;
            if (recyclerView.r(i5, i6, 1, iArr2, null)) {
                i = i5 - iArr[0];
                i2 = i6 - iArr[1];
            } else {
                i = i5;
                i2 = i6;
            }
            if (recyclerView.getOverScrollMode() != 2) {
                recyclerView.l(i, i2);
            }
            if (recyclerView.v != null) {
                iArr[0] = 0;
                iArr[1] = 0;
                recyclerView.X(i, i2, iArr);
                i3 = iArr[0];
                i4 = iArr[1];
                i -= i3;
                i2 -= i4;
                C2896xL c2896xL = recyclerView.w.e;
                if (c2896xL != null && !c2896xL.d && c2896xL.e) {
                    int iB = recyclerView.n0.b();
                    if (iB == 0) {
                        c2896xL.i();
                    } else if (c2896xL.a >= iB) {
                        c2896xL.a = iB - 1;
                        c2896xL.g(i3, i4);
                    } else {
                        c2896xL.g(i3, i4);
                    }
                }
            } else {
                i3 = 0;
                i4 = 0;
            }
            if (!recyclerView.x.isEmpty()) {
                recyclerView.invalidate();
            }
            int[] iArr3 = recyclerView.z0;
            iArr3[0] = 0;
            iArr3[1] = 0;
            recyclerView.s(i3, i4, i, i2, null, 1, iArr3);
            int i7 = i - iArr[0];
            int i8 = i2 - iArr[1];
            if (i3 != 0 || i4 != 0) {
                recyclerView.t(i3, i4);
            }
            if (!recyclerView.awakenScrollBars()) {
                recyclerView.invalidate();
            }
            boolean z = overScroller.isFinished() || (((overScroller.getCurrX() == overScroller.getFinalX()) || i7 != 0) && ((overScroller.getCurrY() == overScroller.getFinalY()) || i8 != 0));
            C2896xL c2896xL2 = recyclerView.w.e;
            if ((c2896xL2 == null || !c2896xL2.d) && z) {
                if (recyclerView.getOverScrollMode() != 2) {
                    int currVelocity = (int) overScroller.getCurrVelocity();
                    int i9 = i7 < 0 ? -currVelocity : i7 > 0 ? currVelocity : 0;
                    if (i8 < 0) {
                        currVelocity = -currVelocity;
                    } else if (i8 <= 0) {
                        currVelocity = 0;
                    }
                    if (i9 < 0) {
                        recyclerView.v();
                        if (recyclerView.O.isFinished()) {
                            recyclerView.O.onAbsorb(-i9);
                        }
                    } else if (i9 > 0) {
                        recyclerView.w();
                        if (recyclerView.Q.isFinished()) {
                            recyclerView.Q.onAbsorb(i9);
                        }
                    }
                    if (currVelocity < 0) {
                        recyclerView.x();
                        if (recyclerView.P.isFinished()) {
                            recyclerView.P.onAbsorb(-currVelocity);
                        }
                    } else if (currVelocity > 0) {
                        recyclerView.u();
                        if (recyclerView.R.isFinished()) {
                            recyclerView.R.onAbsorb(currVelocity);
                        }
                    }
                    if (i9 != 0 || currVelocity != 0) {
                        WeakHashMap weakHashMap = Oj0.a;
                        recyclerView.postInvalidateOnAnimation();
                    }
                }
                C2642ui c2642ui = recyclerView.m0;
                int[] iArr4 = (int[]) c2642ui.e;
                if (iArr4 != null) {
                    Arrays.fill(iArr4, -1);
                }
                c2642ui.d = 0;
            } else {
                a();
                RunnableC2983yD runnableC2983yD = recyclerView.l0;
                if (runnableC2983yD != null) {
                    runnableC2983yD.a(recyclerView, i3, i4);
                }
            }
        }
        C2896xL c2896xL3 = recyclerView.w.e;
        if (c2896xL3 != null && c2896xL3.d) {
            c2896xL3.g(0, 0);
        }
        this.p = false;
        if (!this.q) {
            recyclerView.setScrollState(0);
            recyclerView.c0(1);
        } else {
            recyclerView.removeCallbacks(this);
            WeakHashMap weakHashMap2 = Oj0.a;
            recyclerView.postOnAnimation(this);
        }
    }
}
