package androidx.recyclerview.widget;

import android.R;
import android.animation.ValueAnimator;
import android.graphics.Canvas;
import android.graphics.drawable.Drawable;
import android.graphics.drawable.StateListDrawable;
import android.view.MotionEvent;
import androidx.annotation.Nullable;
import com.bytedance.sdk.openadsdk.TTAdConstant;
import java.util.WeakHashMap;

/* JADX INFO: loaded from: classes.dex */
public final class w extends m1 implements u1 {
    public static final int[] D = {R.attr.state_pressed};
    public static final int[] E = new int[0];
    public int A;
    public final s B;
    public final t C;

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    public w(RecyclerView recyclerView, StateListDrawable stateListDrawable, Drawable drawable, StateListDrawable stateListDrawable2, Drawable drawable2, int i10, int i11, int i12) {
        ValueAnimator valueAnimatorOfFloat = ValueAnimator.ofFloat(0.0f, 1.0f);
        this.f3941z = valueAnimatorOfFloat;
        this.A = 0;
        this.B = new s(this, 0);
        this.C = new t(this, 0);
        this.f3918c = stateListDrawable;
        this.f3919d = drawable;
        this.f3922g = stateListDrawable2;
        this.f3923h = drawable2;
        this.f3920e = Math.max(i10, stateListDrawable.getIntrinsicWidth());
        this.f3921f = Math.max(i10, drawable.getIntrinsicWidth());
        this.f3924i = Math.max(i10, stateListDrawable2.getIntrinsicWidth());
        this.f3925j = Math.max(i10, drawable2.getIntrinsicWidth());
        this.f3916a = i11;
        this.f3917b = i12;
        stateListDrawable.setAlpha(255);
        drawable.setAlpha(255);
        valueAnimatorOfFloat.addListener(new u(this));
        valueAnimatorOfFloat.addUpdateListener(new v(this));
        attachToRecyclerView(recyclerView);
    }

    public static int h(float f10, float f11, int[] iArr, int i10, int i11, int i12) {
        int i13 = iArr[1] - iArr[0];
        if (i13 == 0) {
            return 0;
        }
        int i14 = i10 - i12;
        int i15 = (int) (((f11 - f10) / i13) * i14);
        int i16 = i11 + i15;
        if (i16 >= i14 || i16 < 0) {
            return 0;
        }
        return i15;
    }

    @Override // androidx.recyclerview.widget.u1
    public final void a(MotionEvent motionEvent) {
        if (this.f3937v == 0) {
            return;
        }
        if (motionEvent.getAction() == 0) {
            boolean zG = g(motionEvent.getX(), motionEvent.getY());
            boolean zF = f(motionEvent.getX(), motionEvent.getY());
            if (zG || zF) {
                if (zF) {
                    this.f3938w = 1;
                    this.f3931p = (int) motionEvent.getX();
                } else if (zG) {
                    this.f3938w = 2;
                    this.f3928m = (int) motionEvent.getY();
                }
                i(2);
                return;
            }
            return;
        }
        if (motionEvent.getAction() == 1 && this.f3937v == 2) {
            this.f3928m = 0.0f;
            this.f3931p = 0.0f;
            i(1);
            this.f3938w = 0;
            return;
        }
        if (motionEvent.getAction() == 2 && this.f3937v == 2) {
            j();
            int i10 = this.f3938w;
            int i11 = this.f3917b;
            if (i10 == 1) {
                float x10 = motionEvent.getX();
                int[] iArr = this.f3940y;
                iArr[0] = i11;
                int i12 = this.f3932q - i11;
                iArr[1] = i12;
                float fMax = Math.max(i11, Math.min(i12, x10));
                if (Math.abs(this.f3930o - fMax) >= 2.0f) {
                    int iH = h(this.f3931p, fMax, iArr, this.f3934s.computeHorizontalScrollRange(), this.f3934s.computeHorizontalScrollOffset(), this.f3932q);
                    if (iH != 0) {
                        this.f3934s.scrollBy(iH, 0);
                    }
                    this.f3931p = fMax;
                }
            }
            if (this.f3938w == 2) {
                float y10 = motionEvent.getY();
                int[] iArr2 = this.f3939x;
                iArr2[0] = i11;
                int i13 = this.f3933r - i11;
                iArr2[1] = i13;
                float fMax2 = Math.max(i11, Math.min(i13, y10));
                if (Math.abs(this.f3927l - fMax2) < 2.0f) {
                    return;
                }
                int iH2 = h(this.f3928m, fMax2, iArr2, this.f3934s.computeVerticalScrollRange(), this.f3934s.computeVerticalScrollOffset(), this.f3933r);
                if (iH2 != 0) {
                    this.f3934s.scrollBy(0, iH2);
                }
                this.f3928m = fMax2;
            }
        }
    }

    public void attachToRecyclerView(@Nullable RecyclerView recyclerView) {
        RecyclerView recyclerView2 = this.f3934s;
        if (recyclerView2 == recyclerView) {
            return;
        }
        t tVar = this.C;
        if (recyclerView2 != null) {
            recyclerView2.removeItemDecoration(this);
            this.f3934s.removeOnItemTouchListener(this);
            this.f3934s.removeOnScrollListener(tVar);
            this.f3934s.removeCallbacks(this.B);
        }
        this.f3934s = recyclerView;
        if (recyclerView != null) {
            recyclerView.addItemDecoration(this);
            this.f3934s.addOnItemTouchListener(this);
            this.f3934s.addOnScrollListener(tVar);
        }
    }

    @Override // androidx.recyclerview.widget.u1
    public final boolean d(MotionEvent motionEvent) {
        int i10 = this.f3937v;
        if (i10 == 1) {
            boolean zG = g(motionEvent.getX(), motionEvent.getY());
            boolean zF = f(motionEvent.getX(), motionEvent.getY());
            if (motionEvent.getAction() != 0) {
                return false;
            }
            if (!zG && !zF) {
                return false;
            }
            if (zF) {
                this.f3938w = 1;
                this.f3931p = (int) motionEvent.getX();
            } else if (zG) {
                this.f3938w = 2;
                this.f3928m = (int) motionEvent.getY();
            }
            i(2);
        } else if (i10 != 2) {
            return false;
        }
        return true;
    }

    @Override // androidx.recyclerview.widget.u1
    public final void e(boolean z10) {
    }

    public final boolean f(float f10, float f11) {
        if (f11 >= this.f3933r - this.f3924i) {
            int i10 = this.f3930o;
            int i11 = this.f3929n;
            if (f10 >= i10 - (i11 / 2) && f10 <= (i11 / 2) + i10) {
                return true;
            }
        }
        return false;
    }

    public final boolean g(float f10, float f11) {
        RecyclerView recyclerView = this.f3934s;
        WeakHashMap weakHashMap = androidx.core.view.s1.f1815a;
        boolean z10 = recyclerView.getLayoutDirection() == 1;
        int i10 = this.f3920e;
        if (z10) {
            if (f10 > i10) {
                return false;
            }
        } else if (f10 < this.f3932q - i10) {
            return false;
        }
        int i11 = this.f3927l;
        int i12 = this.f3926k / 2;
        return f11 >= ((float) (i11 - i12)) && f11 <= ((float) (i12 + i11));
    }

    public final void i(int i10) {
        s sVar = this.B;
        StateListDrawable stateListDrawable = this.f3918c;
        if (i10 == 2 && this.f3937v != 2) {
            stateListDrawable.setState(D);
            this.f3934s.removeCallbacks(sVar);
        }
        if (i10 == 0) {
            this.f3934s.invalidate();
        } else {
            j();
        }
        if (this.f3937v == 2 && i10 != 2) {
            stateListDrawable.setState(E);
            this.f3934s.removeCallbacks(sVar);
            this.f3934s.postDelayed(sVar, 1200);
        } else if (i10 == 1) {
            this.f3934s.removeCallbacks(sVar);
            this.f3934s.postDelayed(sVar, TTAdConstant.STYLE_SIZE_RADIO_3_2);
        }
        this.f3937v = i10;
    }

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

    @Override // androidx.recyclerview.widget.m1
    public final void onDrawOver(Canvas canvas, RecyclerView recyclerView, f2 f2Var) {
        if (this.f3932q != this.f3934s.getWidth() || this.f3933r != this.f3934s.getHeight()) {
            this.f3932q = this.f3934s.getWidth();
            this.f3933r = this.f3934s.getHeight();
            i(0);
            return;
        }
        if (this.A != 0) {
            if (this.f3935t) {
                int i10 = this.f3932q;
                int i11 = this.f3920e;
                int i12 = i10 - i11;
                int i13 = this.f3927l;
                int i14 = this.f3926k;
                int i15 = i13 - (i14 / 2);
                StateListDrawable stateListDrawable = this.f3918c;
                stateListDrawable.setBounds(0, 0, i11, i14);
                int i16 = this.f3933r;
                int i17 = this.f3921f;
                Drawable drawable = this.f3919d;
                drawable.setBounds(0, 0, i17, i16);
                RecyclerView recyclerView2 = this.f3934s;
                WeakHashMap weakHashMap = androidx.core.view.s1.f1815a;
                if (recyclerView2.getLayoutDirection() == 1) {
                    drawable.draw(canvas);
                    canvas.translate(i11, i15);
                    canvas.scale(-1.0f, 1.0f);
                    stateListDrawable.draw(canvas);
                    canvas.scale(-1.0f, 1.0f);
                    canvas.translate(-i11, -i15);
                } else {
                    canvas.translate(i12, 0.0f);
                    drawable.draw(canvas);
                    canvas.translate(0.0f, i15);
                    stateListDrawable.draw(canvas);
                    canvas.translate(-i12, -i15);
                }
            }
            if (this.f3936u) {
                int i18 = this.f3933r;
                int i19 = this.f3924i;
                int i20 = i18 - i19;
                int i21 = this.f3930o;
                int i22 = this.f3929n;
                int i23 = i21 - (i22 / 2);
                StateListDrawable stateListDrawable2 = this.f3922g;
                stateListDrawable2.setBounds(0, 0, i22, i19);
                int i24 = this.f3932q;
                int i25 = this.f3925j;
                Drawable drawable2 = this.f3923h;
                drawable2.setBounds(0, 0, i24, i25);
                canvas.translate(0.0f, i20);
                drawable2.draw(canvas);
                canvas.translate(i23, 0.0f);
                stateListDrawable2.draw(canvas);
                canvas.translate(-i23, -i20);
            }
        }
    }
}
