package androidx.recyclerview.widget;

import android.view.animation.Interpolator;
import android.widget.OverScroller;
import androidx.annotation.Nullable;
import java.util.Arrays;
import java.util.WeakHashMap;

/* JADX INFO: loaded from: classes.dex */
public class i2 implements Runnable {

    /* JADX INFO: renamed from: a, reason: collision with root package name */
    public int f3729a;

    /* JADX INFO: renamed from: b, reason: collision with root package name */
    public int f3730b;

    /* JADX INFO: renamed from: c, reason: collision with root package name */
    public OverScroller f3731c;

    /* JADX INFO: renamed from: d, reason: collision with root package name */
    public Interpolator f3732d;

    /* JADX INFO: renamed from: e, reason: collision with root package name */
    public boolean f3733e;

    /* JADX INFO: renamed from: f, reason: collision with root package name */
    public boolean f3734f;

    /* JADX INFO: renamed from: g, reason: collision with root package name */
    public final /* synthetic */ RecyclerView f3735g;

    public i2(RecyclerView recyclerView) {
        this.f3735g = recyclerView;
        Interpolator interpolator = RecyclerView.sQuinticInterpolator;
        this.f3732d = interpolator;
        this.f3733e = false;
        this.f3734f = false;
        this.f3731c = new OverScroller(recyclerView.getContext(), interpolator);
    }

    public final void a(int i10, int i11) {
        RecyclerView recyclerView = this.f3735g;
        recyclerView.setScrollState(2);
        this.f3730b = 0;
        this.f3729a = 0;
        Interpolator interpolator = this.f3732d;
        Interpolator interpolator2 = RecyclerView.sQuinticInterpolator;
        if (interpolator != interpolator2) {
            this.f3732d = interpolator2;
            this.f3731c = new OverScroller(recyclerView.getContext(), interpolator2);
        }
        this.f3731c.fling(0, 0, i10, i11, Integer.MIN_VALUE, Integer.MAX_VALUE, Integer.MIN_VALUE, Integer.MAX_VALUE);
        b();
    }

    public final void b() {
        if (this.f3733e) {
            this.f3734f = true;
            return;
        }
        RecyclerView recyclerView = this.f3735g;
        recyclerView.removeCallbacks(this);
        WeakHashMap weakHashMap = androidx.core.view.s1.f1815a;
        recyclerView.postOnAnimation(this);
    }

    @Override // java.lang.Runnable
    public final void run() {
        int i10;
        int i11;
        int i12;
        int i13;
        RecyclerView recyclerView = this.f3735g;
        if (recyclerView.mLayout == null) {
            recyclerView.removeCallbacks(this);
            this.f3731c.abortAnimation();
            return;
        }
        this.f3734f = false;
        this.f3733e = true;
        recyclerView.consumePendingUpdateOperations();
        OverScroller overScroller = this.f3731c;
        if (overScroller.computeScrollOffset()) {
            int currX = overScroller.getCurrX();
            int currY = overScroller.getCurrY();
            int i14 = currX - this.f3729a;
            int i15 = currY - this.f3730b;
            this.f3729a = currX;
            this.f3730b = currY;
            int iConsumeFlingInHorizontalStretch = recyclerView.consumeFlingInHorizontalStretch(i14);
            int iConsumeFlingInVerticalStretch = recyclerView.consumeFlingInVerticalStretch(i15);
            int[] iArr = recyclerView.mReusableIntPair;
            iArr[0] = 0;
            iArr[1] = 0;
            if (recyclerView.dispatchNestedPreScroll(iConsumeFlingInHorizontalStretch, iConsumeFlingInVerticalStretch, iArr, null, 1)) {
                int[] iArr2 = recyclerView.mReusableIntPair;
                iConsumeFlingInHorizontalStretch -= iArr2[0];
                iConsumeFlingInVerticalStretch -= iArr2[1];
            }
            if (recyclerView.getOverScrollMode() != 2) {
                recyclerView.considerReleasingGlowsOnScroll(iConsumeFlingInHorizontalStretch, iConsumeFlingInVerticalStretch);
            }
            if (recyclerView.mAdapter != null) {
                int[] iArr3 = recyclerView.mReusableIntPair;
                iArr3[0] = 0;
                iArr3[1] = 0;
                recyclerView.scrollStep(iConsumeFlingInHorizontalStretch, iConsumeFlingInVerticalStretch, iArr3);
                int[] iArr4 = recyclerView.mReusableIntPair;
                int i16 = iArr4[0];
                int i17 = iArr4[1];
                int i18 = iConsumeFlingInHorizontalStretch - i16;
                int i19 = iConsumeFlingInVerticalStretch - i17;
                e2 e2Var = recyclerView.mLayout.mSmoothScroller;
                if (e2Var != null && !e2Var.isPendingInitialRun() && e2Var.isRunning()) {
                    int iB = recyclerView.mState.b();
                    if (iB == 0) {
                        e2Var.stop();
                    } else if (e2Var.getTargetPosition() >= iB) {
                        e2Var.setTargetPosition(iB - 1);
                        e2Var.onAnimation(i16, i17);
                    } else {
                        e2Var.onAnimation(i16, i17);
                    }
                }
                i12 = i17;
                i13 = i16;
                i10 = i18;
                i11 = i19;
            } else {
                i10 = iConsumeFlingInHorizontalStretch;
                i11 = iConsumeFlingInVerticalStretch;
                i12 = 0;
                i13 = 0;
            }
            if (!recyclerView.mItemDecorations.isEmpty()) {
                recyclerView.invalidate();
            }
            int[] iArr5 = recyclerView.mReusableIntPair;
            iArr5[0] = 0;
            iArr5[1] = 0;
            recyclerView.dispatchNestedScroll(i13, i12, i10, i11, null, 1, iArr5);
            int[] iArr6 = recyclerView.mReusableIntPair;
            int i20 = i10 - iArr6[0];
            int i21 = i11 - iArr6[1];
            if (i13 != 0 || i12 != 0) {
                recyclerView.dispatchOnScrolled(i13, i12);
            }
            if (!recyclerView.awakenScrollBars()) {
                recyclerView.invalidate();
            }
            boolean z10 = overScroller.isFinished() || (((overScroller.getCurrX() == overScroller.getFinalX()) || i20 != 0) && ((overScroller.getCurrY() == overScroller.getFinalY()) || i21 != 0));
            e2 e2Var2 = recyclerView.mLayout.mSmoothScroller;
            if ((e2Var2 == null || !e2Var2.isPendingInitialRun()) && z10) {
                if (recyclerView.getOverScrollMode() != 2) {
                    int currVelocity = (int) overScroller.getCurrVelocity();
                    int i22 = i20 < 0 ? -currVelocity : i20 > 0 ? currVelocity : 0;
                    if (i21 < 0) {
                        currVelocity = -currVelocity;
                    } else if (i21 <= 0) {
                        currVelocity = 0;
                    }
                    recyclerView.absorbGlows(i22, currVelocity);
                }
                if (RecyclerView.ALLOW_THREAD_GAP_WORK) {
                    x xVar = recyclerView.mPrefetchRegistry;
                    int[] iArr7 = xVar.f3951c;
                    if (iArr7 != null) {
                        Arrays.fill(iArr7, -1);
                    }
                    xVar.f3952d = 0;
                }
            } else {
                b();
                z zVar = recyclerView.mGapWorker;
                if (zVar != null) {
                    zVar.a(recyclerView, i13, i12);
                }
            }
        }
        e2 e2Var3 = recyclerView.mLayout.mSmoothScroller;
        if (e2Var3 != null && e2Var3.isPendingInitialRun()) {
            e2Var3.onAnimation(0, 0);
        }
        this.f3733e = false;
        if (!this.f3734f) {
            recyclerView.setScrollState(0);
            recyclerView.stopNestedScroll(1);
        } else {
            recyclerView.removeCallbacks(this);
            WeakHashMap weakHashMap = androidx.core.view.s1.f1815a;
            recyclerView.postOnAnimation(this);
        }
    }

    public void smoothScrollBy(int i10, int i11, int i12, @Nullable Interpolator interpolator) {
        RecyclerView recyclerView = this.f3735g;
        if (i12 == Integer.MIN_VALUE) {
            int iAbs = Math.abs(i10);
            int iAbs2 = Math.abs(i11);
            boolean z10 = iAbs > iAbs2;
            int width = z10 ? recyclerView.getWidth() : recyclerView.getHeight();
            if (!z10) {
                iAbs = iAbs2;
            }
            i12 = Math.min((int) (((iAbs / width) + 1.0f) * 300.0f), 2000);
        }
        int i13 = i12;
        if (interpolator == null) {
            interpolator = RecyclerView.sQuinticInterpolator;
        }
        if (this.f3732d != interpolator) {
            this.f3732d = interpolator;
            this.f3731c = new OverScroller(recyclerView.getContext(), interpolator);
        }
        this.f3730b = 0;
        this.f3729a = 0;
        recyclerView.setScrollState(2);
        this.f3731c.startScroll(0, 0, i10, i11, i13);
        b();
    }
}
