package d.p.b;

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 d.h.j.y;
import io.netty.handler.codec.dns.DnsRecord;
import java.util.List;
import java.util.concurrent.atomic.AtomicInteger;

/* JADX INFO: loaded from: classes.dex */
public class l extends RecyclerView.k implements RecyclerView.o {
    public static final int[] a = {R.attr.state_pressed};

    /* JADX INFO: renamed from: b, reason: collision with root package name */
    public static final int[] f3288b = new int[0];
    public final ValueAnimator B;
    public int C;
    public final Runnable D;
    public final RecyclerView.p E;

    /* JADX INFO: renamed from: c, reason: collision with root package name */
    public final int f3289c;

    /* JADX INFO: renamed from: d, reason: collision with root package name */
    public final int f3290d;

    /* JADX INFO: renamed from: e, reason: collision with root package name */
    public final StateListDrawable f3291e;

    /* JADX INFO: renamed from: f, reason: collision with root package name */
    public final Drawable f3292f;

    /* JADX INFO: renamed from: g, reason: collision with root package name */
    public final int f3293g;

    /* JADX INFO: renamed from: h, reason: collision with root package name */
    public final int f3294h;

    /* JADX INFO: renamed from: i, reason: collision with root package name */
    public final StateListDrawable f3295i;

    /* JADX INFO: renamed from: j, reason: collision with root package name */
    public final Drawable f3296j;

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

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

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

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

    /* JADX INFO: renamed from: o, reason: collision with root package name */
    public float f3301o;

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

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

    /* JADX INFO: renamed from: r, reason: collision with root package name */
    public float f3304r;

    /* JADX INFO: renamed from: u, reason: collision with root package name */
    public RecyclerView f3307u;

    /* JADX INFO: renamed from: s, reason: collision with root package name */
    public int f3305s = 0;

    /* JADX INFO: renamed from: t, reason: collision with root package name */
    public int f3306t = 0;

    /* JADX INFO: renamed from: v, reason: collision with root package name */
    public boolean f3308v = false;

    /* JADX INFO: renamed from: w, reason: collision with root package name */
    public boolean f3309w = false;

    /* JADX INFO: renamed from: x, reason: collision with root package name */
    public int f3310x = 0;

    /* JADX INFO: renamed from: y, reason: collision with root package name */
    public int f3311y = 0;

    /* JADX INFO: renamed from: z, reason: collision with root package name */
    public final int[] f3312z = new int[2];
    public final int[] A = new int[2];

    public class a implements Runnable {
        public a() {
        }

        @Override // java.lang.Runnable
        public void run() {
            l lVar = l.this;
            int i2 = lVar.C;
            if (i2 == 1) {
                lVar.B.cancel();
            } else if (i2 != 2) {
                return;
            }
            lVar.C = 3;
            ValueAnimator valueAnimator = lVar.B;
            valueAnimator.setFloatValues(((Float) valueAnimator.getAnimatedValue()).floatValue(), 0.0f);
            lVar.B.setDuration(500);
            lVar.B.start();
        }
    }

    public class b extends RecyclerView.p {
        public b() {
        }

        @Override // androidx.recyclerview.widget.RecyclerView.p
        public void b(RecyclerView recyclerView, int i2, int i3) {
            l lVar = l.this;
            int iComputeHorizontalScrollOffset = recyclerView.computeHorizontalScrollOffset();
            int iComputeVerticalScrollOffset = recyclerView.computeVerticalScrollOffset();
            int iComputeVerticalScrollRange = lVar.f3307u.computeVerticalScrollRange();
            int i4 = lVar.f3306t;
            lVar.f3308v = iComputeVerticalScrollRange - i4 > 0 && i4 >= lVar.f3289c;
            int iComputeHorizontalScrollRange = lVar.f3307u.computeHorizontalScrollRange();
            int i5 = lVar.f3305s;
            boolean z2 = iComputeHorizontalScrollRange - i5 > 0 && i5 >= lVar.f3289c;
            lVar.f3309w = z2;
            boolean z3 = lVar.f3308v;
            if (!z3 && !z2) {
                if (lVar.f3310x != 0) {
                    lVar.j(0);
                    return;
                }
                return;
            }
            if (z3) {
                float f2 = i4;
                lVar.f3300n = (int) ((((f2 / 2.0f) + iComputeVerticalScrollOffset) * f2) / iComputeVerticalScrollRange);
                lVar.f3299m = Math.min(i4, (i4 * i4) / iComputeVerticalScrollRange);
            }
            if (lVar.f3309w) {
                float f3 = iComputeHorizontalScrollOffset;
                float f4 = i5;
                lVar.f3303q = (int) ((((f4 / 2.0f) + f3) * f4) / iComputeHorizontalScrollRange);
                lVar.f3302p = Math.min(i5, (i5 * i5) / iComputeHorizontalScrollRange);
            }
            int i6 = lVar.f3310x;
            if (i6 == 0 || i6 == 1) {
                lVar.j(1);
            }
        }
    }

    public class c extends AnimatorListenerAdapter {
        public boolean a = false;

        public 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) l.this.B.getAnimatedValue()).floatValue() == 0.0f) {
                l lVar = l.this;
                lVar.C = 0;
                lVar.j(0);
            } else {
                l lVar2 = l.this;
                lVar2.C = 2;
                lVar2.f3307u.invalidate();
            }
        }
    }

    public class d implements ValueAnimator.AnimatorUpdateListener {
        public d() {
        }

        @Override // android.animation.ValueAnimator.AnimatorUpdateListener
        public void onAnimationUpdate(ValueAnimator valueAnimator) {
            int iFloatValue = (int) (((Float) valueAnimator.getAnimatedValue()).floatValue() * 255.0f);
            l.this.f3291e.setAlpha(iFloatValue);
            l.this.f3292f.setAlpha(iFloatValue);
            l.this.f3307u.invalidate();
        }
    }

    public l(RecyclerView recyclerView, StateListDrawable stateListDrawable, Drawable drawable, StateListDrawable stateListDrawable2, Drawable drawable2, int i2, int i3, int i4) {
        ValueAnimator valueAnimatorOfFloat = ValueAnimator.ofFloat(0.0f, 1.0f);
        this.B = valueAnimatorOfFloat;
        this.C = 0;
        this.D = new a();
        b bVar = new b();
        this.E = bVar;
        this.f3291e = stateListDrawable;
        this.f3292f = drawable;
        this.f3295i = stateListDrawable2;
        this.f3296j = drawable2;
        this.f3293g = Math.max(i2, stateListDrawable.getIntrinsicWidth());
        this.f3294h = Math.max(i2, drawable.getIntrinsicWidth());
        this.f3297k = Math.max(i2, stateListDrawable2.getIntrinsicWidth());
        this.f3298l = Math.max(i2, drawable2.getIntrinsicWidth());
        this.f3289c = i3;
        this.f3290d = i4;
        stateListDrawable.setAlpha(DnsRecord.CLASS_ANY);
        drawable.setAlpha(DnsRecord.CLASS_ANY);
        valueAnimatorOfFloat.addListener(new c());
        valueAnimatorOfFloat.addUpdateListener(new d());
        RecyclerView recyclerView2 = this.f3307u;
        if (recyclerView2 == recyclerView) {
            return;
        }
        if (recyclerView2 != null) {
            RecyclerView.l lVar = recyclerView2.f757z;
            if (lVar != null) {
                lVar.d("Cannot remove item decoration during a scroll  or layout");
            }
            recyclerView2.B.remove(this);
            if (recyclerView2.B.isEmpty()) {
                recyclerView2.setWillNotDraw(recyclerView2.getOverScrollMode() == 2);
            }
            recyclerView2.Q();
            recyclerView2.requestLayout();
            RecyclerView recyclerView3 = this.f3307u;
            recyclerView3.C.remove(this);
            if (recyclerView3.D == this) {
                recyclerView3.D = null;
            }
            List<RecyclerView.p> list = this.f3307u.u0;
            if (list != null) {
                list.remove(bVar);
            }
            f();
        }
        this.f3307u = recyclerView;
        recyclerView.g(this);
        this.f3307u.C.add(this);
        this.f3307u.h(bVar);
    }

    @Override // androidx.recyclerview.widget.RecyclerView.o
    public void a(RecyclerView recyclerView, MotionEvent motionEvent) {
        if (this.f3310x == 0) {
            return;
        }
        if (motionEvent.getAction() == 0) {
            boolean zH = h(motionEvent.getX(), motionEvent.getY());
            boolean zG = g(motionEvent.getX(), motionEvent.getY());
            if (zH || zG) {
                if (zG) {
                    this.f3311y = 1;
                    this.f3304r = (int) motionEvent.getX();
                } else if (zH) {
                    this.f3311y = 2;
                    this.f3301o = (int) motionEvent.getY();
                }
                j(2);
                return;
            }
            return;
        }
        if (motionEvent.getAction() == 1 && this.f3310x == 2) {
            this.f3301o = 0.0f;
            this.f3304r = 0.0f;
            j(1);
            this.f3311y = 0;
            return;
        }
        if (motionEvent.getAction() == 2 && this.f3310x == 2) {
            k();
            if (this.f3311y == 1) {
                float x2 = motionEvent.getX();
                int[] iArr = this.A;
                int i2 = this.f3290d;
                iArr[0] = i2;
                iArr[1] = this.f3305s - i2;
                float fMax = Math.max(iArr[0], Math.min(iArr[1], x2));
                if (Math.abs(this.f3303q - fMax) >= 2.0f) {
                    int i3 = i(this.f3304r, fMax, iArr, this.f3307u.computeHorizontalScrollRange(), this.f3307u.computeHorizontalScrollOffset(), this.f3305s);
                    if (i3 != 0) {
                        this.f3307u.scrollBy(i3, 0);
                    }
                    this.f3304r = fMax;
                }
            }
            if (this.f3311y == 2) {
                float y2 = motionEvent.getY();
                int[] iArr2 = this.f3312z;
                int i4 = this.f3290d;
                iArr2[0] = i4;
                iArr2[1] = this.f3306t - i4;
                float fMax2 = Math.max(iArr2[0], Math.min(iArr2[1], y2));
                if (Math.abs(this.f3300n - fMax2) < 2.0f) {
                    return;
                }
                int i5 = i(this.f3301o, fMax2, iArr2, this.f3307u.computeVerticalScrollRange(), this.f3307u.computeVerticalScrollOffset(), this.f3306t);
                if (i5 != 0) {
                    this.f3307u.scrollBy(0, i5);
                }
                this.f3301o = fMax2;
            }
        }
    }

    @Override // androidx.recyclerview.widget.RecyclerView.o
    public boolean b(RecyclerView recyclerView, MotionEvent motionEvent) {
        int i2 = this.f3310x;
        if (i2 == 1) {
            boolean zH = h(motionEvent.getX(), motionEvent.getY());
            boolean zG = g(motionEvent.getX(), motionEvent.getY());
            if (motionEvent.getAction() == 0 && (zH || zG)) {
                if (zG) {
                    this.f3311y = 1;
                    this.f3304r = (int) motionEvent.getX();
                } else if (zH) {
                    this.f3311y = 2;
                    this.f3301o = (int) motionEvent.getY();
                }
                j(2);
                return true;
            }
        } else if (i2 == 2) {
            return true;
        }
        return false;
    }

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

    @Override // androidx.recyclerview.widget.RecyclerView.k
    public void e(Canvas canvas, RecyclerView recyclerView, RecyclerView.w wVar) {
        if (this.f3305s != this.f3307u.getWidth() || this.f3306t != this.f3307u.getHeight()) {
            this.f3305s = this.f3307u.getWidth();
            this.f3306t = this.f3307u.getHeight();
            j(0);
            return;
        }
        if (this.C != 0) {
            if (this.f3308v) {
                int i2 = this.f3305s;
                int i3 = this.f3293g;
                int i4 = i2 - i3;
                int i5 = this.f3300n;
                int i6 = this.f3299m;
                int i7 = i5 - (i6 / 2);
                this.f3291e.setBounds(0, 0, i3, i6);
                this.f3292f.setBounds(0, 0, this.f3294h, this.f3306t);
                RecyclerView recyclerView2 = this.f3307u;
                AtomicInteger atomicInteger = d.h.j.y.a;
                if (y.d.d(recyclerView2) == 1) {
                    this.f3292f.draw(canvas);
                    canvas.translate(this.f3293g, i7);
                    canvas.scale(-1.0f, 1.0f);
                    this.f3291e.draw(canvas);
                    canvas.scale(1.0f, 1.0f);
                    i4 = this.f3293g;
                } else {
                    canvas.translate(i4, 0.0f);
                    this.f3292f.draw(canvas);
                    canvas.translate(0.0f, i7);
                    this.f3291e.draw(canvas);
                }
                canvas.translate(-i4, -i7);
            }
            if (this.f3309w) {
                int i8 = this.f3306t;
                int i9 = this.f3297k;
                int i10 = this.f3303q;
                int i11 = this.f3302p;
                this.f3295i.setBounds(0, 0, i11, i9);
                this.f3296j.setBounds(0, 0, this.f3305s, this.f3298l);
                canvas.translate(0.0f, i8 - i9);
                this.f3296j.draw(canvas);
                canvas.translate(i10 - (i11 / 2), 0.0f);
                this.f3295i.draw(canvas);
                canvas.translate(-r2, -r7);
            }
        }
    }

    public final void f() {
        this.f3307u.removeCallbacks(this.D);
    }

    public boolean g(float f2, float f3) {
        if (f3 >= this.f3306t - this.f3297k) {
            int i2 = this.f3303q;
            int i3 = this.f3302p;
            if (f2 >= i2 - (i3 / 2) && f2 <= (i3 / 2) + i2) {
                return true;
            }
        }
        return false;
    }

    public boolean h(float f2, float f3) {
        RecyclerView recyclerView = this.f3307u;
        AtomicInteger atomicInteger = d.h.j.y.a;
        if (y.d.d(recyclerView) == 1) {
            if (f2 > this.f3293g / 2) {
                return false;
            }
        } else if (f2 < this.f3305s - this.f3293g) {
            return false;
        }
        int i2 = this.f3300n;
        int i3 = this.f3299m / 2;
        return f3 >= ((float) (i2 - i3)) && f3 <= ((float) (i3 + i2));
    }

    public final int i(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;
    }

    public void j(int i2) {
        int i3;
        if (i2 == 2 && this.f3310x != 2) {
            this.f3291e.setState(a);
            f();
        }
        if (i2 == 0) {
            this.f3307u.invalidate();
        } else {
            k();
        }
        if (this.f3310x != 2 || i2 == 2) {
            i3 = i2 == 1 ? 1500 : 1200;
            this.f3310x = i2;
        }
        this.f3291e.setState(f3288b);
        f();
        this.f3307u.postDelayed(this.D, i3);
        this.f3310x = i2;
    }

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