package N1;

import android.R;
import android.animation.ValueAnimator;
import android.graphics.Canvas;
import android.graphics.drawable.Drawable;
import android.graphics.drawable.StateListDrawable;
import androidx.recyclerview.widget.RecyclerView;
import java.util.ArrayList;

/* JADX INFO: renamed from: N1.y, reason: case insensitive filesystem */
/* JADX INFO: loaded from: classes.dex */
public final class C0223y extends AbstractC0197a0 {

    /* JADX INFO: renamed from: C, reason: collision with root package name */
    public static final int[] f4696C = {R.attr.state_pressed};
    public static final int[] D = new int[0];

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

    /* JADX INFO: renamed from: B, reason: collision with root package name */
    public final M4.k f4698B;

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    /* JADX INFO: renamed from: s, reason: collision with root package name */
    public final RecyclerView f4716s;

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

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

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

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

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

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

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

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

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

    public C0223y(RecyclerView recyclerView, StateListDrawable stateListDrawable, Drawable drawable, StateListDrawable stateListDrawable2, Drawable drawable2, int i, int i5, int i8) {
        ValueAnimator valueAnimatorOfFloat = ValueAnimator.ofFloat(0.0f, 1.0f);
        this.f4723z = valueAnimatorOfFloat;
        this.f4697A = 0;
        M4.k kVar = new M4.k(1, this);
        this.f4698B = kVar;
        C0220v c0220v = new C0220v(0, this);
        this.f4701c = stateListDrawable;
        this.f4702d = drawable;
        this.f4705g = stateListDrawable2;
        this.f4706h = drawable2;
        this.f4703e = Math.max(i, stateListDrawable.getIntrinsicWidth());
        this.f4704f = Math.max(i, drawable.getIntrinsicWidth());
        this.i = Math.max(i, stateListDrawable2.getIntrinsicWidth());
        this.f4707j = Math.max(i, drawable2.getIntrinsicWidth());
        this.f4699a = i5;
        this.f4700b = i8;
        stateListDrawable.setAlpha(255);
        drawable.setAlpha(255);
        valueAnimatorOfFloat.addListener(new C0221w(this));
        valueAnimatorOfFloat.addUpdateListener(new C0222x(0, this));
        RecyclerView recyclerView2 = this.f4716s;
        if (recyclerView2 == recyclerView) {
            return;
        }
        if (recyclerView2 != null) {
            recyclerView2.g0(this);
            RecyclerView recyclerView3 = this.f4716s;
            recyclerView3.H.remove(this);
            if (recyclerView3.f9029I == this) {
                recyclerView3.f9029I = null;
            }
            ArrayList arrayList = this.f4716s.f9016A0;
            if (arrayList != null) {
                arrayList.remove(c0220v);
            }
            this.f4716s.removeCallbacks(kVar);
        }
        this.f4716s = recyclerView;
        if (recyclerView != null) {
            recyclerView.h(this);
            this.f4716s.H.add(this);
            this.f4716s.i(c0220v);
        }
    }

    public static int f(float f3, float f7, int[] iArr, int i, int i5, int i8) {
        int i9 = iArr[1] - iArr[0];
        if (i9 != 0) {
            int i10 = i - i8;
            int i11 = (int) (((f7 - f3) / i9) * i10);
            int i12 = i5 + i11;
            if (i12 < i10 && i12 >= 0) {
                return i11;
            }
        }
        return 0;
    }

    @Override // N1.AbstractC0197a0
    public final void c(Canvas canvas) {
        if (this.f4714q != this.f4716s.getWidth() || this.f4715r != this.f4716s.getHeight()) {
            this.f4714q = this.f4716s.getWidth();
            this.f4715r = this.f4716s.getHeight();
            g(0);
            return;
        }
        if (this.f4697A != 0) {
            if (this.f4717t) {
                int i = this.f4714q;
                int i5 = this.f4703e;
                int i8 = i - i5;
                int i9 = this.f4709l;
                int i10 = this.f4708k;
                int i11 = i9 - (i10 / 2);
                StateListDrawable stateListDrawable = this.f4701c;
                stateListDrawable.setBounds(0, 0, i5, i10);
                int i12 = this.f4715r;
                int i13 = this.f4704f;
                Drawable drawable = this.f4702d;
                drawable.setBounds(0, 0, i13, i12);
                if (this.f4716s.getLayoutDirection() == 1) {
                    drawable.draw(canvas);
                    canvas.translate(i5, i11);
                    canvas.scale(-1.0f, 1.0f);
                    stateListDrawable.draw(canvas);
                    canvas.scale(-1.0f, 1.0f);
                    canvas.translate(-i5, -i11);
                } else {
                    canvas.translate(i8, 0.0f);
                    drawable.draw(canvas);
                    canvas.translate(0.0f, i11);
                    stateListDrawable.draw(canvas);
                    canvas.translate(-i8, -i11);
                }
            }
            if (this.f4718u) {
                int i14 = this.f4715r;
                int i15 = this.i;
                int i16 = i14 - i15;
                int i17 = this.f4712o;
                int i18 = this.f4711n;
                int i19 = i17 - (i18 / 2);
                StateListDrawable stateListDrawable2 = this.f4705g;
                stateListDrawable2.setBounds(0, 0, i18, i15);
                int i20 = this.f4714q;
                int i21 = this.f4707j;
                Drawable drawable2 = this.f4706h;
                drawable2.setBounds(0, 0, i20, i21);
                canvas.translate(0.0f, i16);
                drawable2.draw(canvas);
                canvas.translate(i19, 0.0f);
                stateListDrawable2.draw(canvas);
                canvas.translate(-i19, -i16);
            }
        }
    }

    public final boolean d(float f3, float f7) {
        if (f7 < this.f4715r - this.i) {
            return false;
        }
        int i = this.f4712o;
        int i5 = this.f4711n;
        return f3 >= ((float) (i - (i5 / 2))) && f3 <= ((float) ((i5 / 2) + i));
    }

    public final boolean e(float f3, float f7) {
        boolean z8 = this.f4716s.getLayoutDirection() == 1;
        int i = this.f4703e;
        if (!z8 ? f3 >= this.f4714q - i : f3 <= i) {
            int i5 = this.f4709l;
            int i8 = this.f4708k / 2;
            if (f7 >= i5 - i8 && f7 <= i8 + i5) {
                return true;
            }
        }
        return false;
    }

    public final void g(int i) {
        M4.k kVar = this.f4698B;
        StateListDrawable stateListDrawable = this.f4701c;
        if (i == 2 && this.f4719v != 2) {
            stateListDrawable.setState(f4696C);
            this.f4716s.removeCallbacks(kVar);
        }
        if (i == 0) {
            this.f4716s.invalidate();
        } else {
            h();
        }
        if (this.f4719v == 2 && i != 2) {
            stateListDrawable.setState(D);
            this.f4716s.removeCallbacks(kVar);
            this.f4716s.postDelayed(kVar, 1200);
        } else if (i == 1) {
            this.f4716s.removeCallbacks(kVar);
            this.f4716s.postDelayed(kVar, 1500);
        }
        this.f4719v = i;
    }

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