package androidx.recyclerview.widget;

import android.R;
import android.animation.ValueAnimator;
import android.graphics.drawable.Drawable;
import android.graphics.drawable.StateListDrawable;
import com.google.android.gms.common.ConnectionResult;
import java.lang.reflect.Field;
import java.util.ArrayList;

/* JADX INFO: renamed from: androidx.recyclerview.widget.n, reason: case insensitive filesystem */
/* JADX INFO: loaded from: classes.dex */
public final class C1164n {

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

    /* JADX INFO: renamed from: D, reason: collision with root package name */
    public static final int[] f13118D = new int[0];

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

    /* JADX INFO: renamed from: B, reason: collision with root package name */
    public final RunnableC1160j f13120B;

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    public C1164n(RecyclerView recyclerView, StateListDrawable stateListDrawable, Drawable drawable, StateListDrawable stateListDrawable2, Drawable drawable2, int i6, int i7, int i8) {
        ValueAnimator valueAnimatorOfFloat = ValueAnimator.ofFloat(0.0f, 1.0f);
        this.f13145z = valueAnimatorOfFloat;
        this.f13119A = 0;
        RunnableC1160j runnableC1160j = new RunnableC1160j(this, 0);
        this.f13120B = runnableC1160j;
        C1161k c1161k = new C1161k(this);
        this.f13123c = stateListDrawable;
        this.f13124d = drawable;
        this.f13127g = stateListDrawable2;
        this.f13128h = drawable2;
        this.f13125e = Math.max(i6, stateListDrawable.getIntrinsicWidth());
        this.f13126f = Math.max(i6, drawable.getIntrinsicWidth());
        this.f13129i = Math.max(i6, stateListDrawable2.getIntrinsicWidth());
        this.f13130j = Math.max(i6, drawable2.getIntrinsicWidth());
        this.f13121a = i7;
        this.f13122b = i8;
        stateListDrawable.setAlpha(255);
        drawable.setAlpha(255);
        valueAnimatorOfFloat.addListener(new C1162l(this));
        valueAnimatorOfFloat.addUpdateListener(new C1163m(this));
        RecyclerView recyclerView2 = this.f13138s;
        if (recyclerView2 == recyclerView) {
            return;
        }
        if (recyclerView2 != null) {
            J j4 = recyclerView2.f12946q;
            if (j4 != null) {
                j4.b("Cannot remove item decoration during a scroll  or layout");
            }
            ArrayList arrayList = recyclerView2.f12952t;
            arrayList.remove(this);
            if (arrayList.isEmpty()) {
                recyclerView2.setWillNotDraw(recyclerView2.getOverScrollMode() == 2);
            }
            recyclerView2.M();
            recyclerView2.requestLayout();
            RecyclerView recyclerView3 = this.f13138s;
            recyclerView3.f12954u.remove(this);
            if (recyclerView3.f12956v == this) {
                recyclerView3.f12956v = null;
            }
            ArrayList arrayList2 = this.f13138s.f12937l0;
            if (arrayList2 != null) {
                arrayList2.remove(c1161k);
            }
            this.f13138s.removeCallbacks(runnableC1160j);
        }
        this.f13138s = recyclerView;
        if (recyclerView != null) {
            J j6 = recyclerView.f12946q;
            if (j6 != null) {
                j6.b("Cannot add item decoration during a scroll  or layout");
            }
            ArrayList arrayList3 = recyclerView.f12952t;
            if (arrayList3.isEmpty()) {
                recyclerView.setWillNotDraw(false);
            }
            arrayList3.add(this);
            recyclerView.M();
            recyclerView.requestLayout();
            this.f13138s.f12954u.add(this);
            RecyclerView recyclerView4 = this.f13138s;
            if (recyclerView4.f12937l0 == null) {
                recyclerView4.f12937l0 = new ArrayList();
            }
            recyclerView4.f12937l0.add(c1161k);
        }
    }

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

    public final boolean a(float f6, float f7) {
        if (f7 < this.f13137r - this.f13129i) {
            return false;
        }
        int i6 = this.f13134o;
        int i7 = this.f13133n;
        return f6 >= ((float) (i6 - (i7 / 2))) && f6 <= ((float) ((i7 / 2) + i6));
    }

    public final boolean b(float f6, float f7) {
        RecyclerView recyclerView = this.f13138s;
        Field field = F1.F.f1367a;
        boolean z6 = recyclerView.getLayoutDirection() == 1;
        int i6 = this.f13125e;
        if (!z6 ? f6 >= this.f13136q - i6 : f6 <= i6) {
            int i7 = this.l;
            int i8 = this.f13131k / 2;
            if (f7 >= i7 - i8 && f7 <= i8 + i7) {
                return true;
            }
        }
        return false;
    }

    public final void d(int i6) {
        RunnableC1160j runnableC1160j = this.f13120B;
        StateListDrawable stateListDrawable = this.f13123c;
        if (i6 == 2 && this.f13141v != 2) {
            stateListDrawable.setState(f13117C);
            this.f13138s.removeCallbacks(runnableC1160j);
        }
        if (i6 == 0) {
            this.f13138s.invalidate();
        } else {
            e();
        }
        if (this.f13141v == 2 && i6 != 2) {
            stateListDrawable.setState(f13118D);
            this.f13138s.removeCallbacks(runnableC1160j);
            this.f13138s.postDelayed(runnableC1160j, 1200);
        } else if (i6 == 1) {
            this.f13138s.removeCallbacks(runnableC1160j);
            this.f13138s.postDelayed(runnableC1160j, ConnectionResult.DRIVE_EXTERNAL_STORAGE_REQUIRED);
        }
        this.f13141v = i6;
    }

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