package androidx.leanback.widget;

import android.content.Context;
import android.graphics.PointF;
import android.util.DisplayMetrics;
import android.util.Log;
import android.view.View;
import android.view.animation.DecelerateInterpolator;
import android.view.animation.LinearInterpolator;
import androidx.recyclerview.widget.RecyclerView;
import androidx.recyclerview.widget.Z;

/* JADX INFO: renamed from: androidx.leanback.widget.l, reason: case insensitive filesystem */
/* JADX INFO: loaded from: classes.dex */
public abstract class AbstractC1080l {

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

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

    /* JADX INFO: renamed from: c, reason: collision with root package name */
    public C1084p f11994c;

    /* JADX INFO: renamed from: d, reason: collision with root package name */
    public boolean f11995d;

    /* JADX INFO: renamed from: e, reason: collision with root package name */
    public boolean f11996e;

    /* JADX INFO: renamed from: f, reason: collision with root package name */
    public View f11997f;

    /* JADX INFO: renamed from: g, reason: collision with root package name */
    public final androidx.recyclerview.widget.U f11998g;

    /* JADX INFO: renamed from: h, reason: collision with root package name */
    public boolean f11999h;

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

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

    /* JADX INFO: renamed from: k, reason: collision with root package name */
    public final DisplayMetrics f12002k;
    public boolean l;

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

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

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

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

    /* JADX INFO: renamed from: q, reason: collision with root package name */
    public final /* synthetic */ C1084p f12007q;

    public AbstractC1080l(C1084p c1084p) {
        this.f12007q = c1084p;
        Context context = c1084p.f12048q.getContext();
        this.f11992a = -1;
        androidx.recyclerview.widget.U u6 = new androidx.recyclerview.widget.U();
        u6.f12993d = -1;
        u6.f12995f = false;
        u6.f12996g = 0;
        u6.f12990a = 0;
        u6.f12991b = 0;
        u6.f12992c = Integer.MIN_VALUE;
        u6.f12994e = null;
        this.f11998g = u6;
        this.f12000i = new LinearInterpolator();
        this.f12001j = new DecelerateInterpolator();
        this.l = false;
        this.f12004n = 0;
        this.f12005o = 0;
        this.f12002k = context.getResources().getDisplayMetrics();
    }

    public final int a(int i6) {
        float fAbs = Math.abs(i6);
        if (!this.l) {
            this.f12003m = 25.0f / this.f12002k.densityDpi;
            this.l = true;
        }
        int iCeil = (int) Math.ceil(fAbs * this.f12003m);
        int i7 = ((X) this.f12007q.f12041U.f535d).f11973i;
        if (i7 > 0) {
            float f6 = (30.0f / i7) * i6;
            if (iCeil < f6) {
                return (int) f6;
            }
        }
        return iCeil;
    }

    public abstract PointF b(int i6);

    public final void c(int i6, int i7) {
        int i8;
        int i9;
        PointF pointFB;
        RecyclerView recyclerView = this.f11993b;
        if (this.f11992a == -1 || recyclerView == null) {
            e();
        }
        if (this.f11995d && this.f11997f == null && this.f11994c != null && (pointFB = b(this.f11992a)) != null) {
            float f6 = pointFB.x;
            if (f6 != 0.0f || pointFB.y != 0.0f) {
                recyclerView.a0((int) Math.signum(f6), (int) Math.signum(pointFB.y), null);
            }
        }
        this.f11995d = false;
        View view = this.f11997f;
        androidx.recyclerview.widget.U u6 = this.f11998g;
        if (view != null) {
            this.f11993b.getClass();
            Z zG = RecyclerView.G(view);
            if ((zG != null ? zG.getLayoutPosition() : -1) == this.f11992a) {
                View view2 = this.f11997f;
                androidx.recyclerview.widget.V v3 = recyclerView.f12934j0;
                int[] iArr = C1084p.f12020d0;
                C1084p c1084p = this.f12007q;
                if (c1084p.W0(view2, null, iArr)) {
                    if (c1084p.f12049r == 0) {
                        i8 = iArr[0];
                        i9 = iArr[1];
                    } else {
                        i8 = iArr[1];
                        i9 = iArr[0];
                    }
                    int iCeil = (int) Math.ceil(((double) a((int) Math.sqrt((i9 * i9) + (i8 * i8)))) / 0.3356d);
                    DecelerateInterpolator decelerateInterpolator = this.f12001j;
                    u6.f12990a = i8;
                    u6.f12991b = i9;
                    u6.f12992c = iCeil;
                    u6.f12994e = decelerateInterpolator;
                    u6.f12995f = true;
                }
                u6.a(recyclerView);
                e();
            } else {
                Log.e("RecyclerView", "Passed over target position while smooth scrolling.");
                this.f11997f = null;
            }
        }
        if (this.f11996e) {
            androidx.recyclerview.widget.V v6 = recyclerView.f12934j0;
            if (this.f11993b.f12946q.w() == 0) {
                e();
            } else {
                int i10 = this.f12004n;
                int i11 = i10 - i6;
                if (i10 * i11 <= 0) {
                    i11 = 0;
                }
                this.f12004n = i11;
                int i12 = this.f12005o;
                int i13 = i12 - i7;
                if (i12 * i13 <= 0) {
                    i13 = 0;
                }
                this.f12005o = i13;
                if (i11 == 0 && i13 == 0) {
                    f(u6);
                }
            }
            boolean z6 = u6.f12993d >= 0;
            u6.a(recyclerView);
            if (z6 && this.f11996e) {
                this.f11995d = true;
                recyclerView.g0.b();
            }
        }
    }

    public void d() {
        View viewR = this.f11993b.f12946q.r(this.f11992a);
        C1084p c1084p = this.f12007q;
        if (viewR == null) {
            int i6 = this.f11992a;
            if (i6 >= 0) {
                c1084p.m1(i6, false);
                return;
            }
            return;
        }
        int i7 = c1084p.f12022B;
        int i8 = this.f11992a;
        if (i7 != i8) {
            c1084p.f12022B = i8;
        }
        if (c1084p.P()) {
            c1084p.f12057z |= 32;
            viewR.requestFocus();
            c1084p.f12057z &= -33;
        }
        c1084p.N0();
        c1084p.O0();
    }

    public final void e() {
        if (this.f11996e) {
            this.f11996e = false;
            this.f12005o = 0;
            this.f12004n = 0;
            if (!this.f12006p) {
                d();
            }
            C1084p c1084p = this.f12007q;
            if (c1084p.f12023C == this) {
                c1084p.f12023C = null;
            }
            if (c1084p.f12024D == this) {
                c1084p.f12024D = null;
            }
            this.f11993b.f12934j0.f12997a = -1;
            this.f11997f = null;
            this.f11992a = -1;
            this.f11995d = false;
            C1084p c1084p2 = this.f11994c;
            if (c1084p2.f12846e == this) {
                c1084p2.f12846e = null;
            }
            this.f11994c = null;
            this.f11993b = null;
        }
    }

    public void f(androidx.recyclerview.widget.U u6) {
        PointF pointFB = b(this.f11992a);
        if (pointFB != null) {
            if (pointFB.x != 0.0f || pointFB.y != 0.0f) {
                float f6 = pointFB.y;
                float fSqrt = (float) Math.sqrt((f6 * f6) + (r1 * r1));
                float f7 = pointFB.x / fSqrt;
                pointFB.x = f7;
                float f8 = pointFB.y / fSqrt;
                pointFB.y = f8;
                this.f12004n = (int) (f7 * 10000.0f);
                this.f12005o = (int) (f8 * 10000.0f);
                int iA = a(10000);
                LinearInterpolator linearInterpolator = this.f12000i;
                u6.f12990a = (int) (this.f12004n * 1.2f);
                u6.f12991b = (int) (this.f12005o * 1.2f);
                u6.f12992c = (int) (iA * 1.2f);
                u6.f12994e = linearInterpolator;
                u6.f12995f = true;
                return;
            }
        }
        u6.f12993d = this.f11992a;
        e();
    }
}
