package androidx.recyclerview.widget;

import android.R;
import android.animation.Animator;
import android.animation.AnimatorListenerAdapter;
import android.animation.ValueAnimator;
import android.graphics.Canvas;
import android.graphics.drawable.Drawable;
import android.graphics.drawable.StateListDrawable;
import android.view.MotionEvent;
import androidx.core.view.y;
import androidx.recyclerview.widget.RecyclerView;

/* JADX INFO: compiled from: FastScroller.java */
/* JADX INFO: loaded from: classes.dex */
class d extends RecyclerView.n implements RecyclerView.s {
    private static final int[] D = {R.attr.state_pressed};
    private static final int[] E = new int[0];
    int A;
    private final Runnable B;
    private final RecyclerView.t C;

    /* JADX INFO: renamed from: a, reason: collision with root package name */
    private final int f2922a;

    /* JADX INFO: renamed from: b, reason: collision with root package name */
    private final int f2923b;

    /* JADX INFO: renamed from: c, reason: collision with root package name */
    final StateListDrawable f2924c;

    /* JADX INFO: renamed from: d, reason: collision with root package name */
    final Drawable f2925d;

    /* JADX INFO: renamed from: e, reason: collision with root package name */
    private final int f2926e;

    /* JADX INFO: renamed from: f, reason: collision with root package name */
    private final int f2927f;

    /* JADX INFO: renamed from: g, reason: collision with root package name */
    private final StateListDrawable f2928g;

    /* JADX INFO: renamed from: h, reason: collision with root package name */
    private final Drawable f2929h;

    /* JADX INFO: renamed from: i, reason: collision with root package name */
    private final int f2930i;

    /* JADX INFO: renamed from: j, reason: collision with root package name */
    private final int f2931j;

    /* JADX INFO: renamed from: k, reason: collision with root package name */
    int f2932k;

    /* JADX INFO: renamed from: l, reason: collision with root package name */
    int f2933l;

    /* JADX INFO: renamed from: m, reason: collision with root package name */
    float f2934m;

    /* JADX INFO: renamed from: n, reason: collision with root package name */
    int f2935n;

    /* JADX INFO: renamed from: o, reason: collision with root package name */
    int f2936o;

    /* JADX INFO: renamed from: p, reason: collision with root package name */
    float f2937p;

    /* JADX INFO: renamed from: s, reason: collision with root package name */
    private RecyclerView f2940s;

    /* JADX INFO: renamed from: z, reason: collision with root package name */
    final ValueAnimator f2947z;

    /* JADX INFO: renamed from: q, reason: collision with root package name */
    private int f2938q = 0;

    /* JADX INFO: renamed from: r, reason: collision with root package name */
    private int f2939r = 0;

    /* JADX INFO: renamed from: t, reason: collision with root package name */
    private boolean f2941t = false;

    /* JADX INFO: renamed from: u, reason: collision with root package name */
    private boolean f2942u = false;

    /* JADX INFO: renamed from: v, reason: collision with root package name */
    private int f2943v = 0;

    /* JADX INFO: renamed from: w, reason: collision with root package name */
    private int f2944w = 0;

    /* JADX INFO: renamed from: x, reason: collision with root package name */
    private final int[] f2945x = new int[2];

    /* JADX INFO: renamed from: y, reason: collision with root package name */
    private final int[] f2946y = new int[2];

    /* JADX INFO: compiled from: FastScroller.java */
    class a implements Runnable {
        a() {
        }

        @Override // java.lang.Runnable
        public void run() {
            d.this.q(500);
        }
    }

    /* JADX INFO: compiled from: FastScroller.java */
    class b extends RecyclerView.t {
        b() {
        }

        @Override // androidx.recyclerview.widget.RecyclerView.t
        public void b(RecyclerView recyclerView, int i3, int i4) {
            d.this.B(recyclerView.computeHorizontalScrollOffset(), recyclerView.computeVerticalScrollOffset());
        }
    }

    /* JADX INFO: compiled from: FastScroller.java */
    private class c extends AnimatorListenerAdapter {

        /* JADX INFO: renamed from: a, reason: collision with root package name */
        private boolean f2950a = false;

        c() {
        }

        @Override // android.animation.AnimatorListenerAdapter, android.animation.Animator.AnimatorListener
        public void onAnimationCancel(Animator animator) {
            this.f2950a = true;
        }

        @Override // android.animation.AnimatorListenerAdapter, android.animation.Animator.AnimatorListener
        public void onAnimationEnd(Animator animator) {
            if (this.f2950a) {
                this.f2950a = false;
                return;
            }
            if (((Float) d.this.f2947z.getAnimatedValue()).floatValue() == 0.0f) {
                d dVar = d.this;
                dVar.A = 0;
                dVar.y(0);
            } else {
                d dVar2 = d.this;
                dVar2.A = 2;
                dVar2.v();
            }
        }
    }

    /* JADX INFO: renamed from: androidx.recyclerview.widget.d$d, reason: collision with other inner class name */
    /* JADX INFO: compiled from: FastScroller.java */
    private class C0042d implements ValueAnimator.AnimatorUpdateListener {
        C0042d() {
        }

        @Override // android.animation.ValueAnimator.AnimatorUpdateListener
        public void onAnimationUpdate(ValueAnimator valueAnimator) {
            int iFloatValue = (int) (((Float) valueAnimator.getAnimatedValue()).floatValue() * 255.0f);
            d.this.f2924c.setAlpha(iFloatValue);
            d.this.f2925d.setAlpha(iFloatValue);
            d.this.v();
        }
    }

    d(RecyclerView recyclerView, StateListDrawable stateListDrawable, Drawable drawable, StateListDrawable stateListDrawable2, Drawable drawable2, int i3, int i4, int i5) {
        ValueAnimator valueAnimatorOfFloat = ValueAnimator.ofFloat(0.0f, 1.0f);
        this.f2947z = valueAnimatorOfFloat;
        this.A = 0;
        this.B = new a();
        this.C = new b();
        this.f2924c = stateListDrawable;
        this.f2925d = drawable;
        this.f2928g = stateListDrawable2;
        this.f2929h = drawable2;
        this.f2926e = Math.max(i3, stateListDrawable.getIntrinsicWidth());
        this.f2927f = Math.max(i3, drawable.getIntrinsicWidth());
        this.f2930i = Math.max(i3, stateListDrawable2.getIntrinsicWidth());
        this.f2931j = Math.max(i3, drawable2.getIntrinsicWidth());
        this.f2922a = i4;
        this.f2923b = i5;
        stateListDrawable.setAlpha(255);
        drawable.setAlpha(255);
        valueAnimatorOfFloat.addListener(new c());
        valueAnimatorOfFloat.addUpdateListener(new C0042d());
        j(recyclerView);
    }

    private void C(float f3) {
        int[] iArrP = p();
        float fMax = Math.max(iArrP[0], Math.min(iArrP[1], f3));
        if (Math.abs(this.f2933l - fMax) < 2.0f) {
            return;
        }
        int iX = x(this.f2934m, fMax, iArrP, this.f2940s.computeVerticalScrollRange(), this.f2940s.computeVerticalScrollOffset(), this.f2939r);
        if (iX != 0) {
            this.f2940s.scrollBy(0, iX);
        }
        this.f2934m = fMax;
    }

    private void k() {
        this.f2940s.removeCallbacks(this.B);
    }

    private void l() {
        this.f2940s.V0(this);
        this.f2940s.W0(this);
        this.f2940s.X0(this.C);
        k();
    }

    private void m(Canvas canvas) {
        int i3 = this.f2939r;
        int i4 = this.f2930i;
        int i5 = this.f2936o;
        int i6 = this.f2935n;
        this.f2928g.setBounds(0, 0, i6, i4);
        this.f2929h.setBounds(0, 0, this.f2938q, this.f2931j);
        canvas.translate(0.0f, i3 - i4);
        this.f2929h.draw(canvas);
        canvas.translate(i5 - (i6 / 2), 0.0f);
        this.f2928g.draw(canvas);
        canvas.translate(-r2, -r0);
    }

    private void n(Canvas canvas) {
        int i3 = this.f2938q;
        int i4 = this.f2926e;
        int i5 = i3 - i4;
        int i6 = this.f2933l;
        int i7 = this.f2932k;
        int i8 = i6 - (i7 / 2);
        this.f2924c.setBounds(0, 0, i4, i7);
        this.f2925d.setBounds(0, 0, this.f2927f, this.f2939r);
        if (!s()) {
            canvas.translate(i5, 0.0f);
            this.f2925d.draw(canvas);
            canvas.translate(0.0f, i8);
            this.f2924c.draw(canvas);
            canvas.translate(-i5, -i8);
            return;
        }
        this.f2925d.draw(canvas);
        canvas.translate(this.f2926e, i8);
        canvas.scale(-1.0f, 1.0f);
        this.f2924c.draw(canvas);
        canvas.scale(1.0f, 1.0f);
        canvas.translate(-this.f2926e, -i8);
    }

    private int[] o() {
        int[] iArr = this.f2946y;
        int i3 = this.f2923b;
        iArr[0] = i3;
        iArr[1] = this.f2938q - i3;
        return iArr;
    }

    private int[] p() {
        int[] iArr = this.f2945x;
        int i3 = this.f2923b;
        iArr[0] = i3;
        iArr[1] = this.f2939r - i3;
        return iArr;
    }

    private void r(float f3) {
        int[] iArrO = o();
        float fMax = Math.max(iArrO[0], Math.min(iArrO[1], f3));
        if (Math.abs(this.f2936o - fMax) < 2.0f) {
            return;
        }
        int iX = x(this.f2937p, fMax, iArrO, this.f2940s.computeHorizontalScrollRange(), this.f2940s.computeHorizontalScrollOffset(), this.f2938q);
        if (iX != 0) {
            this.f2940s.scrollBy(iX, 0);
        }
        this.f2937p = fMax;
    }

    private boolean s() {
        return y.E(this.f2940s) == 1;
    }

    private void w(int i3) {
        k();
        this.f2940s.postDelayed(this.B, i3);
    }

    private int x(float f3, float f4, int[] iArr, int i3, int i4, int i5) {
        int i6 = iArr[1] - iArr[0];
        if (i6 == 0) {
            return 0;
        }
        int i7 = i3 - i5;
        int i8 = (int) (((f4 - f3) / i6) * i7);
        int i9 = i4 + i8;
        if (i9 >= i7 || i9 < 0) {
            return 0;
        }
        return i8;
    }

    private void z() {
        this.f2940s.h(this);
        this.f2940s.j(this);
        this.f2940s.k(this.C);
    }

    public void A() {
        int i3 = this.A;
        if (i3 != 0) {
            if (i3 != 3) {
                return;
            } else {
                this.f2947z.cancel();
            }
        }
        this.A = 1;
        ValueAnimator valueAnimator = this.f2947z;
        valueAnimator.setFloatValues(((Float) valueAnimator.getAnimatedValue()).floatValue(), 1.0f);
        this.f2947z.setDuration(500L);
        this.f2947z.setStartDelay(0L);
        this.f2947z.start();
    }

    void B(int i3, int i4) {
        int iComputeVerticalScrollRange = this.f2940s.computeVerticalScrollRange();
        int i5 = this.f2939r;
        this.f2941t = iComputeVerticalScrollRange - i5 > 0 && i5 >= this.f2922a;
        int iComputeHorizontalScrollRange = this.f2940s.computeHorizontalScrollRange();
        int i6 = this.f2938q;
        boolean z2 = iComputeHorizontalScrollRange - i6 > 0 && i6 >= this.f2922a;
        this.f2942u = z2;
        boolean z3 = this.f2941t;
        if (!z3 && !z2) {
            if (this.f2943v != 0) {
                y(0);
                return;
            }
            return;
        }
        if (z3) {
            float f3 = i5;
            this.f2933l = (int) ((f3 * (i4 + (f3 / 2.0f))) / iComputeVerticalScrollRange);
            this.f2932k = Math.min(i5, (i5 * i5) / iComputeVerticalScrollRange);
        }
        if (this.f2942u) {
            float f4 = i6;
            this.f2936o = (int) ((f4 * (i3 + (f4 / 2.0f))) / iComputeHorizontalScrollRange);
            this.f2935n = Math.min(i6, (i6 * i6) / iComputeHorizontalScrollRange);
        }
        int i7 = this.f2943v;
        if (i7 == 0 || i7 == 1) {
            y(1);
        }
    }

    @Override // androidx.recyclerview.widget.RecyclerView.s
    public boolean a(RecyclerView recyclerView, MotionEvent motionEvent) {
        int i3 = this.f2943v;
        if (i3 == 1) {
            boolean zU = u(motionEvent.getX(), motionEvent.getY());
            boolean zT = t(motionEvent.getX(), motionEvent.getY());
            if (motionEvent.getAction() != 0) {
                return false;
            }
            if (!zU && !zT) {
                return false;
            }
            if (zT) {
                this.f2944w = 1;
                this.f2937p = (int) motionEvent.getX();
            } else if (zU) {
                this.f2944w = 2;
                this.f2934m = (int) motionEvent.getY();
            }
            y(2);
        } else if (i3 != 2) {
            return false;
        }
        return true;
    }

    @Override // androidx.recyclerview.widget.RecyclerView.s
    public void b(RecyclerView recyclerView, MotionEvent motionEvent) {
        if (this.f2943v == 0) {
            return;
        }
        if (motionEvent.getAction() == 0) {
            boolean zU = u(motionEvent.getX(), motionEvent.getY());
            boolean zT = t(motionEvent.getX(), motionEvent.getY());
            if (zU || zT) {
                if (zT) {
                    this.f2944w = 1;
                    this.f2937p = (int) motionEvent.getX();
                } else if (zU) {
                    this.f2944w = 2;
                    this.f2934m = (int) motionEvent.getY();
                }
                y(2);
                return;
            }
            return;
        }
        if (motionEvent.getAction() == 1 && this.f2943v == 2) {
            this.f2934m = 0.0f;
            this.f2937p = 0.0f;
            y(1);
            this.f2944w = 0;
            return;
        }
        if (motionEvent.getAction() == 2 && this.f2943v == 2) {
            A();
            if (this.f2944w == 1) {
                r(motionEvent.getX());
            }
            if (this.f2944w == 2) {
                C(motionEvent.getY());
            }
        }
    }

    @Override // androidx.recyclerview.widget.RecyclerView.s
    public void c(boolean z2) {
    }

    @Override // androidx.recyclerview.widget.RecyclerView.n
    public void i(Canvas canvas, RecyclerView recyclerView, RecyclerView.a0 a0Var) {
        if (this.f2938q != this.f2940s.getWidth() || this.f2939r != this.f2940s.getHeight()) {
            this.f2938q = this.f2940s.getWidth();
            this.f2939r = this.f2940s.getHeight();
            y(0);
        } else if (this.A != 0) {
            if (this.f2941t) {
                n(canvas);
            }
            if (this.f2942u) {
                m(canvas);
            }
        }
    }

    public void j(RecyclerView recyclerView) {
        RecyclerView recyclerView2 = this.f2940s;
        if (recyclerView2 == recyclerView) {
            return;
        }
        if (recyclerView2 != null) {
            l();
        }
        this.f2940s = recyclerView;
        if (recyclerView != null) {
            z();
        }
    }

    void q(int i3) {
        int i4 = this.A;
        if (i4 == 1) {
            this.f2947z.cancel();
        } else if (i4 != 2) {
            return;
        }
        this.A = 3;
        ValueAnimator valueAnimator = this.f2947z;
        valueAnimator.setFloatValues(((Float) valueAnimator.getAnimatedValue()).floatValue(), 0.0f);
        this.f2947z.setDuration(i3);
        this.f2947z.start();
    }

    boolean t(float f3, float f4) {
        if (f4 >= this.f2939r - this.f2930i) {
            int i3 = this.f2936o;
            int i4 = this.f2935n;
            if (f3 >= i3 - (i4 / 2) && f3 <= i3 + (i4 / 2)) {
                return true;
            }
        }
        return false;
    }

    boolean u(float f3, float f4) {
        if (!s() ? f3 >= this.f2938q - this.f2926e : f3 <= this.f2926e / 2) {
            int i3 = this.f2933l;
            int i4 = this.f2932k;
            if (f4 >= i3 - (i4 / 2) && f4 <= i3 + (i4 / 2)) {
                return true;
            }
        }
        return false;
    }

    void v() {
        this.f2940s.invalidate();
    }

    void y(int i3) {
        if (i3 == 2 && this.f2943v != 2) {
            this.f2924c.setState(D);
            k();
        }
        if (i3 == 0) {
            v();
        } else {
            A();
        }
        if (this.f2943v == 2 && i3 != 2) {
            this.f2924c.setState(E);
            w(1200);
        } else if (i3 == 1) {
            w(1500);
        }
        this.f2943v = i3;
    }
}
