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.recyclerview.widget.RecyclerView;
import c.f.l.t;

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

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

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

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

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

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

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

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

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

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

    /* JADX INFO: renamed from: k, reason: collision with root package name */
    int f1138k;
    int l;
    float m;
    int n;
    int o;
    float p;
    private RecyclerView s;
    private int q = 0;
    private int r = 0;
    private boolean t = false;
    private boolean u = false;
    private int v = 0;
    private int w = 0;
    private final int[] x = new int[2];
    private final int[] y = new int[2];
    final ValueAnimator z = ValueAnimator.ofFloat(0.0f, 1.0f);
    int A = 0;
    private final Runnable B = new a();
    private final RecyclerView.t C = new b();

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

        @Override // java.lang.Runnable
        public void run() {
            d.this.k(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 i2, int i3) {
            d.this.v(recyclerView.computeHorizontalScrollOffset(), recyclerView.computeVerticalScrollOffset());
        }
    }

    /* JADX INFO: compiled from: FastScroller.java */
    private class c extends AnimatorListenerAdapter {
        private boolean a = false;

        c() {
        }

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

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

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

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

    d(RecyclerView recyclerView, StateListDrawable stateListDrawable, Drawable drawable, StateListDrawable stateListDrawable2, Drawable drawable2, int i2, int i3, int i4) {
        this.f1130c = stateListDrawable;
        this.f1131d = drawable;
        this.f1134g = stateListDrawable2;
        this.f1135h = drawable2;
        this.f1132e = Math.max(i2, stateListDrawable.getIntrinsicWidth());
        this.f1133f = Math.max(i2, drawable.getIntrinsicWidth());
        this.f1136i = Math.max(i2, stateListDrawable2.getIntrinsicWidth());
        this.f1137j = Math.max(i2, drawable2.getIntrinsicWidth());
        this.a = i3;
        this.f1129b = i4;
        this.f1130c.setAlpha(255);
        this.f1131d.setAlpha(255);
        this.z.addListener(new c());
        this.z.addUpdateListener(new C0018d());
        d(recyclerView);
    }

    private void e() {
        this.s.removeCallbacks(this.B);
    }

    private void f() {
        this.s.V0(this);
        this.s.W0(this);
        this.s.X0(this.C);
        e();
    }

    private void g(Canvas canvas) {
        int i2 = this.r;
        int i3 = this.f1136i;
        int i4 = this.o;
        int i5 = this.n;
        this.f1134g.setBounds(0, 0, i5, i3);
        this.f1135h.setBounds(0, 0, this.q, this.f1137j);
        canvas.translate(0.0f, i2 - i3);
        this.f1135h.draw(canvas);
        canvas.translate(i4 - (i5 / 2), 0.0f);
        this.f1134g.draw(canvas);
        canvas.translate(-r2, -r0);
    }

    private void h(Canvas canvas) {
        int i2 = this.q;
        int i3 = this.f1132e;
        int i4 = i2 - i3;
        int i5 = this.l;
        int i6 = this.f1138k;
        int i7 = i5 - (i6 / 2);
        this.f1130c.setBounds(0, 0, i3, i6);
        this.f1131d.setBounds(0, 0, this.f1133f, this.r);
        if (!m()) {
            canvas.translate(i4, 0.0f);
            this.f1131d.draw(canvas);
            canvas.translate(0.0f, i7);
            this.f1130c.draw(canvas);
            canvas.translate(-i4, -i7);
            return;
        }
        this.f1131d.draw(canvas);
        canvas.translate(this.f1132e, i7);
        canvas.scale(-1.0f, 1.0f);
        this.f1130c.draw(canvas);
        canvas.scale(-1.0f, 1.0f);
        canvas.translate(-this.f1132e, -i7);
    }

    private int[] i() {
        int[] iArr = this.y;
        int i2 = this.f1129b;
        iArr[0] = i2;
        iArr[1] = this.q - i2;
        return iArr;
    }

    private int[] j() {
        int[] iArr = this.x;
        int i2 = this.f1129b;
        iArr[0] = i2;
        iArr[1] = this.r - i2;
        return iArr;
    }

    private void l(float f2) {
        int[] iArrI = i();
        float fMax = Math.max(iArrI[0], Math.min(iArrI[1], f2));
        if (Math.abs(this.o - fMax) < 2.0f) {
            return;
        }
        int iR = r(this.p, fMax, iArrI, this.s.computeHorizontalScrollRange(), this.s.computeHorizontalScrollOffset(), this.q);
        if (iR != 0) {
            this.s.scrollBy(iR, 0);
        }
        this.p = fMax;
    }

    private boolean m() {
        return t.u(this.s) == 1;
    }

    private void q(int i2) {
        e();
        this.s.postDelayed(this.B, i2);
    }

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

    private void t() {
        this.s.i(this);
        this.s.k(this);
        this.s.l(this.C);
    }

    private void w(float f2) {
        int[] iArrJ = j();
        float fMax = Math.max(iArrJ[0], Math.min(iArrJ[1], f2));
        if (Math.abs(this.l - fMax) < 2.0f) {
            return;
        }
        int iR = r(this.m, fMax, iArrJ, this.s.computeVerticalScrollRange(), this.s.computeVerticalScrollOffset(), this.r);
        if (iR != 0) {
            this.s.scrollBy(0, iR);
        }
        this.m = fMax;
    }

    @Override // androidx.recyclerview.widget.RecyclerView.s
    public boolean a(RecyclerView recyclerView, MotionEvent motionEvent) {
        int i2 = this.v;
        if (i2 == 1) {
            boolean zO = o(motionEvent.getX(), motionEvent.getY());
            boolean zN = n(motionEvent.getX(), motionEvent.getY());
            if (motionEvent.getAction() != 0) {
                return false;
            }
            if (!zO && !zN) {
                return false;
            }
            if (zN) {
                this.w = 1;
                this.p = (int) motionEvent.getX();
            } else if (zO) {
                this.w = 2;
                this.m = (int) motionEvent.getY();
            }
            s(2);
        } else if (i2 != 2) {
            return false;
        }
        return true;
    }

    @Override // androidx.recyclerview.widget.RecyclerView.s
    public void b(RecyclerView recyclerView, MotionEvent motionEvent) {
        if (this.v == 0) {
            return;
        }
        if (motionEvent.getAction() == 0) {
            boolean zO = o(motionEvent.getX(), motionEvent.getY());
            boolean zN = n(motionEvent.getX(), motionEvent.getY());
            if (zO || zN) {
                if (zN) {
                    this.w = 1;
                    this.p = (int) motionEvent.getX();
                } else if (zO) {
                    this.w = 2;
                    this.m = (int) motionEvent.getY();
                }
                s(2);
                return;
            }
            return;
        }
        if (motionEvent.getAction() == 1 && this.v == 2) {
            this.m = 0.0f;
            this.p = 0.0f;
            s(1);
            this.w = 0;
            return;
        }
        if (motionEvent.getAction() == 2 && this.v == 2) {
            u();
            if (this.w == 1) {
                l(motionEvent.getX());
            }
            if (this.w == 2) {
                w(motionEvent.getY());
            }
        }
    }

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

    public void d(RecyclerView recyclerView) {
        RecyclerView recyclerView2 = this.s;
        if (recyclerView2 == recyclerView) {
            return;
        }
        if (recyclerView2 != null) {
            f();
        }
        this.s = recyclerView;
        if (recyclerView != null) {
            t();
        }
    }

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

    boolean n(float f2, float f3) {
        if (f3 >= this.r - this.f1136i) {
            int i2 = this.o;
            int i3 = this.n;
            if (f2 >= i2 - (i3 / 2) && f2 <= i2 + (i3 / 2)) {
                return true;
            }
        }
        return false;
    }

    boolean o(float f2, float f3) {
        if (!m() ? f2 >= this.q - this.f1132e : f2 <= this.f1132e) {
            int i2 = this.l;
            int i3 = this.f1138k;
            if (f3 >= i2 - (i3 / 2) && f3 <= i2 + (i3 / 2)) {
                return true;
            }
        }
        return false;
    }

    @Override // androidx.recyclerview.widget.RecyclerView.o
    public void onDrawOver(Canvas canvas, RecyclerView recyclerView, RecyclerView.a0 a0Var) {
        if (this.q != this.s.getWidth() || this.r != this.s.getHeight()) {
            this.q = this.s.getWidth();
            this.r = this.s.getHeight();
            s(0);
        } else if (this.A != 0) {
            if (this.t) {
                h(canvas);
            }
            if (this.u) {
                g(canvas);
            }
        }
    }

    void p() {
        this.s.invalidate();
    }

    void s(int i2) {
        if (i2 == 2 && this.v != 2) {
            this.f1130c.setState(D);
            e();
        }
        if (i2 == 0) {
            p();
        } else {
            u();
        }
        if (this.v == 2 && i2 != 2) {
            this.f1130c.setState(E);
            q(1200);
        } else if (i2 == 1) {
            q(1500);
        }
        this.v = i2;
    }

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

    void v(int i2, int i3) {
        int iComputeVerticalScrollRange = this.s.computeVerticalScrollRange();
        int i4 = this.r;
        this.t = iComputeVerticalScrollRange - i4 > 0 && i4 >= this.a;
        int iComputeHorizontalScrollRange = this.s.computeHorizontalScrollRange();
        int i5 = this.q;
        boolean z = iComputeHorizontalScrollRange - i5 > 0 && i5 >= this.a;
        this.u = z;
        if (!this.t && !z) {
            if (this.v != 0) {
                s(0);
                return;
            }
            return;
        }
        if (this.t) {
            float f2 = i4;
            this.l = (int) ((f2 * (i3 + (f2 / 2.0f))) / iComputeVerticalScrollRange);
            this.f1138k = Math.min(i4, (i4 * i4) / iComputeVerticalScrollRange);
        }
        if (this.u) {
            float f3 = i5;
            this.o = (int) ((f3 * (i2 + (f3 / 2.0f))) / iComputeHorizontalScrollRange);
            this.n = Math.min(i5, (i5 * i5) / iComputeHorizontalScrollRange);
        }
        int i6 = this.v;
        if (i6 == 0 || i6 == 1) {
            s(1);
        }
    }
}
