package androidx.recyclerview.widget;

import A1.x;
import N.c;
import N.e;
import N1.AbstractC0200c;
import N1.C0201c0;
import N1.C0203d0;
import N1.C0224z;
import N1.E;
import N1.F;
import N1.G;
import N1.H;
import N1.M;
import N1.T;
import N1.i0;
import N1.o0;
import N1.p0;
import N1.t0;
import android.annotation.SuppressLint;
import android.content.Context;
import android.graphics.PointF;
import android.os.Bundle;
import android.os.Parcelable;
import android.util.AttributeSet;
import android.view.View;
import android.view.ViewGroup;
import android.view.accessibility.AccessibilityEvent;
import d5.AbstractC0844a;
import java.util.ArrayList;
import java.util.List;

/* JADX INFO: loaded from: classes.dex */
public class LinearLayoutManager extends a implements o0 {

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

    /* JADX INFO: renamed from: G, reason: collision with root package name */
    public F f8995G;
    public M H;

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

    /* JADX INFO: renamed from: J, reason: collision with root package name */
    public final boolean f8997J;

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

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

    /* JADX INFO: renamed from: M, reason: collision with root package name */
    public final boolean f9000M;

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

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

    /* JADX INFO: renamed from: P, reason: collision with root package name */
    public G f9003P;

    /* JADX INFO: renamed from: Q, reason: collision with root package name */
    public final x f9004Q;

    /* JADX INFO: renamed from: R, reason: collision with root package name */
    public final E f9005R;

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

    /* JADX INFO: renamed from: T, reason: collision with root package name */
    public final int[] f9007T;

    public LinearLayoutManager(int i) {
        this.f8994F = 1;
        this.f8997J = false;
        this.f8998K = false;
        this.f8999L = false;
        this.f9000M = true;
        this.f9001N = -1;
        this.f9002O = Integer.MIN_VALUE;
        this.f9003P = null;
        this.f9004Q = new x();
        this.f9005R = new E();
        this.f9006S = 2;
        this.f9007T = new int[2];
        B1(i);
        n(null);
        if (this.f8997J) {
            this.f8997J = false;
            M0();
        }
    }

    @Override // androidx.recyclerview.widget.a
    public int A(p0 p0Var) {
        return g1(p0Var);
    }

    @Override // androidx.recyclerview.widget.a
    public final void A0(Parcelable parcelable) {
        if (parcelable instanceof G) {
            G g8 = (G) parcelable;
            this.f9003P = g8;
            if (this.f9001N != -1) {
                g8.f4457q = -1;
            }
            M0();
        }
    }

    public final int A1(int i, i0 i0Var, p0 p0Var) {
        if (I() != 0 && i != 0) {
            i1();
            this.f8995G.f4446a = true;
            int i5 = i > 0 ? 1 : -1;
            int iAbs = Math.abs(i);
            D1(i5, iAbs, true, p0Var);
            F f3 = this.f8995G;
            int iJ1 = j1(i0Var, f3, p0Var, false) + f3.f4452g;
            if (iJ1 >= 0) {
                if (iAbs > iJ1) {
                    i = i5 * iJ1;
                }
                this.H.r(-i);
                this.f8995G.f4454j = i;
                return i;
            }
        }
        return 0;
    }

    @Override // androidx.recyclerview.widget.a
    public final Parcelable B0() {
        G g8 = this.f9003P;
        if (g8 != null) {
            G g9 = new G();
            g9.f4457q = g8.f4457q;
            g9.f4458r = g8.f4458r;
            g9.f4459s = g8.f4459s;
            return g9;
        }
        G g10 = new G();
        if (I() <= 0) {
            g10.f4457q = -1;
            return g10;
        }
        i1();
        boolean z8 = this.f8996I ^ this.f8998K;
        g10.f4459s = z8;
        if (z8) {
            View viewS1 = s1();
            g10.f4458r = this.H.i() - this.H.d(viewS1);
            g10.f4457q = a.T(viewS1);
            return g10;
        }
        View viewT1 = t1();
        g10.f4457q = a.T(viewT1);
        g10.f4458r = this.H.g(viewT1) - this.H.m();
        return g10;
    }

    public final void B1(int i) {
        if (i != 0 && i != 1) {
            throw new IllegalArgumentException(AbstractC0844a.j("invalid orientation:", i));
        }
        n(null);
        if (i != this.f8994F || this.H == null) {
            M mB = M.b(this, i);
            this.H = mB;
            this.f9004Q.f361f = mB;
            this.f8994F = i;
            M0();
        }
    }

    public void C1(boolean z8) {
        n(null);
        if (this.f8999L == z8) {
            return;
        }
        this.f8999L = z8;
        M0();
    }

    @Override // androidx.recyclerview.widget.a
    public final View D(int i) {
        int I7 = I();
        if (I7 == 0) {
            return null;
        }
        int iT = i - a.T(H(0));
        if (iT >= 0 && iT < I7) {
            View viewH = H(iT);
            if (a.T(viewH) == i) {
                return viewH;
            }
        }
        return super.D(i);
    }

    /* JADX WARN: Removed duplicated region for block: B:19:0x0048  */
    @Override // androidx.recyclerview.widget.a
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public boolean D0(int i, Bundle bundle) {
        int iMin;
        if (super.D0(i, bundle)) {
            return true;
        }
        if (i == 16908343 && bundle != null) {
            if (this.f8994F == 1) {
                int i5 = bundle.getInt("android.view.accessibility.action.ARGUMENT_ROW_INT", -1);
                if (i5 >= 0) {
                    RecyclerView recyclerView = this.f9115r;
                    iMin = Math.min(i5, V(recyclerView.f9074s, recyclerView.f9087y0) - 1);
                    if (iMin >= 0) {
                        this.f9001N = iMin;
                        this.f9002O = 0;
                        G g8 = this.f9003P;
                        if (g8 != null) {
                            g8.f4457q = -1;
                        }
                        M0();
                        return true;
                    }
                }
            } else {
                int i8 = bundle.getInt("android.view.accessibility.action.ARGUMENT_COLUMN_INT", -1);
                if (i8 >= 0) {
                    RecyclerView recyclerView2 = this.f9115r;
                    iMin = Math.min(i8, K(recyclerView2.f9074s, recyclerView2.f9087y0) - 1);
                    if (iMin >= 0) {
                    }
                }
            }
        }
        return false;
    }

    public final void D1(int i, int i5, boolean z8, p0 p0Var) {
        int iM;
        this.f8995G.f4456l = this.H.k() == 0 && this.H.h() == 0;
        this.f8995G.f4451f = i;
        int[] iArr = this.f9007T;
        iArr[0] = 0;
        iArr[1] = 0;
        c1(p0Var, iArr);
        int iMax = Math.max(0, iArr[0]);
        int iMax2 = Math.max(0, iArr[1]);
        boolean z9 = i == 1;
        F f3 = this.f8995G;
        int i8 = z9 ? iMax2 : iMax;
        f3.f4453h = i8;
        if (!z9) {
            iMax = iMax2;
        }
        f3.i = iMax;
        if (z9) {
            f3.f4453h = this.H.j() + i8;
            View viewS1 = s1();
            F f7 = this.f8995G;
            f7.f4450e = this.f8998K ? -1 : 1;
            int iT = a.T(viewS1);
            F f8 = this.f8995G;
            f7.f4449d = iT + f8.f4450e;
            f8.f4447b = this.H.d(viewS1);
            iM = this.H.d(viewS1) - this.H.i();
        } else {
            View viewT1 = t1();
            F f9 = this.f8995G;
            f9.f4453h = this.H.m() + f9.f4453h;
            F f10 = this.f8995G;
            f10.f4450e = this.f8998K ? 1 : -1;
            int iT2 = a.T(viewT1);
            F f11 = this.f8995G;
            f10.f4449d = iT2 + f11.f4450e;
            f11.f4447b = this.H.g(viewT1);
            iM = (-this.H.g(viewT1)) + this.H.m();
        }
        F f12 = this.f8995G;
        f12.f4448c = i5;
        if (z8) {
            f12.f4448c = i5 - iM;
        }
        f12.f4452g = iM;
    }

    @Override // androidx.recyclerview.widget.a
    public C0203d0 E() {
        return new C0203d0(-2, -2);
    }

    public final void E1(int i, int i5) {
        this.f8995G.f4448c = this.H.i() - i5;
        F f3 = this.f8995G;
        f3.f4450e = this.f8998K ? -1 : 1;
        f3.f4449d = i;
        f3.f4451f = 1;
        f3.f4447b = i5;
        f3.f4452g = Integer.MIN_VALUE;
    }

    public final void F1(int i, int i5) {
        this.f8995G.f4448c = i5 - this.H.m();
        F f3 = this.f8995G;
        f3.f4449d = i;
        f3.f4450e = this.f8998K ? 1 : -1;
        f3.f4451f = -1;
        f3.f4447b = i5;
        f3.f4452g = Integer.MIN_VALUE;
    }

    @Override // androidx.recyclerview.widget.a
    public int O0(int i, i0 i0Var, p0 p0Var) {
        if (this.f8994F == 1) {
            return 0;
        }
        return A1(i, i0Var, p0Var);
    }

    @Override // androidx.recyclerview.widget.a
    public final void P0(int i) {
        this.f9001N = i;
        this.f9002O = Integer.MIN_VALUE;
        G g8 = this.f9003P;
        if (g8 != null) {
            g8.f4457q = -1;
        }
        M0();
    }

    @Override // androidx.recyclerview.widget.a
    public int Q0(int i, i0 i0Var, p0 p0Var) {
        if (this.f8994F == 0) {
            return 0;
        }
        return A1(i, i0Var, p0Var);
    }

    @Override // androidx.recyclerview.widget.a
    public final boolean X0() {
        if (this.f9112C != 1073741824 && this.f9111B != 1073741824) {
            int I7 = I();
            for (int i = 0; i < I7; i++) {
                ViewGroup.LayoutParams layoutParams = H(i).getLayoutParams();
                if (layoutParams.width < 0 && layoutParams.height < 0) {
                    return true;
                }
            }
        }
        return false;
    }

    @Override // androidx.recyclerview.widget.a
    public final boolean Y() {
        return true;
    }

    @Override // androidx.recyclerview.widget.a
    public final boolean Z() {
        return this.f8997J;
    }

    @Override // androidx.recyclerview.widget.a
    public void Z0(RecyclerView recyclerView, p0 p0Var, int i) {
        H h8 = new H(recyclerView.getContext());
        h8.f4460a = i;
        a1(h8);
    }

    @Override // androidx.recyclerview.widget.a
    public boolean b1() {
        return this.f9003P == null && this.f8996I == this.f8999L;
    }

    public void c1(p0 p0Var, int[] iArr) {
        int i;
        int iN = p0Var.f4614a != -1 ? this.H.n() : 0;
        if (this.f8995G.f4451f == -1) {
            i = 0;
        } else {
            i = iN;
            iN = 0;
        }
        iArr[0] = iN;
        iArr[1] = i;
    }

    public void d1(p0 p0Var, F f3, C0224z c0224z) {
        int i = f3.f4449d;
        if (i < 0 || i >= p0Var.b()) {
            return;
        }
        c0224z.b(i, Math.max(0, f3.f4452g));
    }

    public final int e1(p0 p0Var) {
        if (I() == 0) {
            return 0;
        }
        i1();
        M m8 = this.H;
        boolean z8 = !this.f9000M;
        return AbstractC0200c.f(p0Var, m8, l1(z8), k1(z8), this, this.f9000M);
    }

    @Override // N1.o0
    public final PointF f(int i) {
        if (I() == 0) {
            return null;
        }
        int i5 = (i < a.T(H(0))) != this.f8998K ? -1 : 1;
        return this.f8994F == 0 ? new PointF(i5, 0.0f) : new PointF(0.0f, i5);
    }

    public final int f1(p0 p0Var) {
        if (I() == 0) {
            return 0;
        }
        i1();
        M m8 = this.H;
        boolean z8 = !this.f9000M;
        return AbstractC0200c.g(p0Var, m8, l1(z8), k1(z8), this, this.f9000M, this.f8998K);
    }

    public final int g1(p0 p0Var) {
        if (I() == 0) {
            return 0;
        }
        i1();
        M m8 = this.H;
        boolean z8 = !this.f9000M;
        return AbstractC0200c.h(p0Var, m8, l1(z8), k1(z8), this, this.f9000M);
    }

    public final int h1(int i) {
        return i != 1 ? i != 2 ? i != 17 ? i != 33 ? i != 66 ? (i == 130 && this.f8994F == 1) ? 1 : Integer.MIN_VALUE : this.f8994F == 0 ? 1 : Integer.MIN_VALUE : this.f8994F == 1 ? -1 : Integer.MIN_VALUE : this.f8994F == 0 ? -1 : Integer.MIN_VALUE : (this.f8994F != 1 && u1()) ? -1 : 1 : (this.f8994F != 1 && u1()) ? 1 : -1;
    }

    public final void i1() {
        if (this.f8995G == null) {
            F f3 = new F();
            f3.f4446a = true;
            f3.f4453h = 0;
            f3.i = 0;
            f3.f4455k = null;
            this.f8995G = f3;
        }
    }

    public final int j1(i0 i0Var, F f3, p0 p0Var, boolean z8) {
        int i;
        int i5 = f3.f4448c;
        int i8 = f3.f4452g;
        if (i8 != Integer.MIN_VALUE) {
            if (i5 < 0) {
                f3.f4452g = i8 + i5;
            }
            x1(i0Var, f3);
        }
        int i9 = f3.f4448c + f3.f4453h;
        while (true) {
            if ((!f3.f4456l && i9 <= 0) || (i = f3.f4449d) < 0 || i >= p0Var.b()) {
                break;
            }
            E e8 = this.f9005R;
            e8.f4442a = 0;
            e8.f4443b = false;
            e8.f4444c = false;
            e8.f4445d = false;
            v1(i0Var, p0Var, f3, e8);
            if (!e8.f4443b) {
                int i10 = f3.f4447b;
                int i11 = e8.f4442a;
                f3.f4447b = (f3.f4451f * i11) + i10;
                if (!e8.f4444c || f3.f4455k != null || !p0Var.f4620g) {
                    f3.f4448c -= i11;
                    i9 -= i11;
                }
                int i12 = f3.f4452g;
                if (i12 != Integer.MIN_VALUE) {
                    int i13 = i12 + i11;
                    f3.f4452g = i13;
                    int i14 = f3.f4448c;
                    if (i14 < 0) {
                        f3.f4452g = i13 + i14;
                    }
                    x1(i0Var, f3);
                }
                if (z8 && e8.f4445d) {
                    break;
                }
            } else {
                break;
            }
        }
        return i5 - f3.f4448c;
    }

    @Override // androidx.recyclerview.widget.a
    public View k0(View view, int i, i0 i0Var, p0 p0Var) {
        int iH1;
        z1();
        if (I() != 0 && (iH1 = h1(i)) != Integer.MIN_VALUE) {
            i1();
            D1(iH1, (int) (this.H.n() * 0.33333334f), false, p0Var);
            F f3 = this.f8995G;
            f3.f4452g = Integer.MIN_VALUE;
            f3.f4446a = false;
            j1(i0Var, f3, p0Var, true);
            View viewN1 = iH1 == -1 ? this.f8998K ? n1(I() - 1, -1) : n1(0, I()) : this.f8998K ? n1(0, I()) : n1(I() - 1, -1);
            View viewT1 = iH1 == -1 ? t1() : s1();
            if (!viewT1.hasFocusable()) {
                return viewN1;
            }
            if (viewN1 != null) {
                return viewT1;
            }
        }
        return null;
    }

    public final View k1(boolean z8) {
        return this.f8998K ? o1(0, I(), z8) : o1(I() - 1, -1, z8);
    }

    @Override // androidx.recyclerview.widget.a
    public final void l0(AccessibilityEvent accessibilityEvent) {
        super.l0(accessibilityEvent);
        if (I() > 0) {
            View viewO1 = o1(0, I(), false);
            accessibilityEvent.setFromIndex(viewO1 == null ? -1 : a.T(viewO1));
            accessibilityEvent.setToIndex(m1());
        }
    }

    public final View l1(boolean z8) {
        return this.f8998K ? o1(I() - 1, -1, z8) : o1(0, I(), z8);
    }

    @Override // androidx.recyclerview.widget.a
    public void m0(i0 i0Var, p0 p0Var, e eVar) {
        super.m0(i0Var, p0Var, eVar);
        T t6 = this.f9115r.f9019C;
        if (t6 == null || t6.a() <= 0) {
            return;
        }
        eVar.b(c.f4359k);
    }

    public final int m1() {
        View viewO1 = o1(I() - 1, -1, false);
        if (viewO1 == null) {
            return -1;
        }
        return a.T(viewO1);
    }

    @Override // androidx.recyclerview.widget.a
    public final void n(String str) {
        if (this.f9003P == null) {
            super.n(str);
        }
    }

    public final View n1(int i, int i5) {
        int i8;
        int i9;
        i1();
        if (i5 <= i && i5 >= i) {
            return H(i);
        }
        if (this.H.g(H(i)) < this.H.m()) {
            i8 = 16644;
            i9 = 16388;
        } else {
            i8 = 4161;
            i9 = 4097;
        }
        return this.f8994F == 0 ? this.f9116s.M(i, i5, i8, i9) : this.f9117t.M(i, i5, i8, i9);
    }

    public final View o1(int i, int i5, boolean z8) {
        i1();
        int i8 = z8 ? 24579 : 320;
        return this.f8994F == 0 ? this.f9116s.M(i, i5, i8, 320) : this.f9117t.M(i, i5, i8, 320);
    }

    @Override // androidx.recyclerview.widget.a
    public final boolean p() {
        return this.f8994F == 0;
    }

    /* JADX WARN: Removed duplicated region for block: B:33:0x0075  */
    /* JADX WARN: Removed duplicated region for block: B:35:0x0079  */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public View p1(i0 i0Var, p0 p0Var, boolean z8, boolean z9) {
        int i;
        int I7;
        int i5;
        i1();
        int I8 = I();
        if (z9) {
            I7 = I() - 1;
            i = -1;
            i5 = -1;
        } else {
            i = I8;
            I7 = 0;
            i5 = 1;
        }
        int iB = p0Var.b();
        int iM = this.H.m();
        int i8 = this.H.i();
        View view = null;
        View view2 = null;
        View view3 = null;
        while (I7 != i) {
            View viewH = H(I7);
            int iT = a.T(viewH);
            int iG = this.H.g(viewH);
            int iD = this.H.d(viewH);
            if (iT >= 0 && iT < iB) {
                if (!((C0203d0) viewH.getLayoutParams()).f4520q.j()) {
                    boolean z10 = iD <= iM && iG < iM;
                    boolean z11 = iG >= i8 && iD > i8;
                    if (!z10 && !z11) {
                        return viewH;
                    }
                    if (z8) {
                        if (z11) {
                            view2 = viewH;
                        } else if (view == null) {
                            view = viewH;
                        }
                    } else if (!z10) {
                        if (view == null) {
                        }
                    }
                } else if (view3 == null) {
                    view3 = viewH;
                }
            }
            I7 += i5;
        }
        return view != null ? view : view2 != null ? view2 : view3;
    }

    @Override // androidx.recyclerview.widget.a
    public final boolean q() {
        return this.f8994F == 1;
    }

    public final int q1(int i, i0 i0Var, p0 p0Var, boolean z8) {
        int i5;
        int i8 = this.H.i() - i;
        if (i8 <= 0) {
            return 0;
        }
        int i9 = -A1(-i8, i0Var, p0Var);
        int i10 = i + i9;
        if (!z8 || (i5 = this.H.i() - i10) <= 0) {
            return i9;
        }
        this.H.r(i5);
        return i5 + i9;
    }

    public final int r1(int i, i0 i0Var, p0 p0Var, boolean z8) {
        int iM;
        int iM2 = i - this.H.m();
        if (iM2 <= 0) {
            return 0;
        }
        int i5 = -A1(iM2, i0Var, p0Var);
        int i8 = i + i5;
        if (!z8 || (iM = i8 - this.H.m()) <= 0) {
            return i5;
        }
        this.H.r(-iM);
        return i5 - iM;
    }

    public final View s1() {
        return H(this.f8998K ? 0 : I() - 1);
    }

    @Override // androidx.recyclerview.widget.a
    public final void t(int i, int i5, p0 p0Var, C0224z c0224z) {
        if (this.f8994F != 0) {
            i = i5;
        }
        if (I() == 0 || i == 0) {
            return;
        }
        i1();
        D1(i > 0 ? 1 : -1, Math.abs(i), true, p0Var);
        d1(p0Var, this.f8995G, c0224z);
    }

    public final View t1() {
        return H(this.f8998K ? I() - 1 : 0);
    }

    @Override // androidx.recyclerview.widget.a
    public final void u(int i, C0224z c0224z) {
        boolean z8;
        int i5;
        G g8 = this.f9003P;
        if (g8 == null || (i5 = g8.f4457q) < 0) {
            z1();
            z8 = this.f8998K;
            i5 = this.f9001N;
            if (i5 == -1) {
                i5 = z8 ? i - 1 : 0;
            }
        } else {
            z8 = g8.f4459s;
        }
        int i8 = z8 ? -1 : 1;
        for (int i9 = 0; i9 < this.f9006S && i5 >= 0 && i5 < i; i9++) {
            c0224z.b(i5, 0);
            i5 += i8;
        }
    }

    public final boolean u1() {
        return this.f9115r.getLayoutDirection() == 1;
    }

    @Override // androidx.recyclerview.widget.a
    public final int v(p0 p0Var) {
        return e1(p0Var);
    }

    public void v1(i0 i0Var, p0 p0Var, F f3, E e8) {
        int paddingLeft;
        int i;
        int i5;
        int iF;
        View viewB = f3.b(i0Var);
        if (viewB == null) {
            e8.f4443b = true;
            return;
        }
        C0203d0 c0203d0 = (C0203d0) viewB.getLayoutParams();
        if (f3.f4455k == null) {
            if (this.f8998K == (f3.f4451f == -1)) {
                l(viewB);
            } else {
                m(viewB, 0, false);
            }
        } else {
            if (this.f8998K == (f3.f4451f == -1)) {
                m(viewB, -1, true);
            } else {
                m(viewB, 0, true);
            }
        }
        d0(viewB);
        e8.f4442a = this.H.e(viewB);
        if (this.f8994F == 1) {
            if (u1()) {
                iF = this.D - getPaddingRight();
                paddingLeft = iF - this.H.f(viewB);
            } else {
                paddingLeft = getPaddingLeft();
                iF = this.H.f(viewB) + paddingLeft;
            }
            if (f3.f4451f == -1) {
                i = f3.f4447b;
                i5 = i - e8.f4442a;
            } else {
                i5 = f3.f4447b;
                i = e8.f4442a + i5;
            }
        } else {
            int paddingTop = getPaddingTop();
            int iF2 = this.H.f(viewB) + paddingTop;
            if (f3.f4451f == -1) {
                int i8 = f3.f4447b;
                int i9 = i8 - e8.f4442a;
                iF = i8;
                i = iF2;
                paddingLeft = i9;
                i5 = paddingTop;
            } else {
                int i10 = f3.f4447b;
                int i11 = e8.f4442a + i10;
                paddingLeft = i10;
                i = iF2;
                i5 = paddingTop;
                iF = i11;
            }
        }
        a.c0(viewB, paddingLeft, i5, iF, i);
        if (c0203d0.f4520q.j() || c0203d0.f4520q.m()) {
            e8.f4444c = true;
        }
        e8.f4445d = viewB.hasFocusable();
    }

    @Override // androidx.recyclerview.widget.a
    public int w(p0 p0Var) {
        return f1(p0Var);
    }

    /* JADX WARN: Removed duplicated region for block: B:107:0x01d0  */
    /* JADX WARN: Removed duplicated region for block: B:131:0x0222  */
    /* JADX WARN: Removed duplicated region for block: B:91:0x018b  */
    @Override // androidx.recyclerview.widget.a
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public void w0(i0 i0Var, p0 p0Var) {
        View focusedChild;
        View focusedChild2;
        View viewP1;
        int i;
        int i5;
        int i8;
        List list;
        int i9;
        int i10;
        int iQ1;
        int i11;
        View viewD;
        int iG;
        int i12;
        int i13;
        int i14 = -1;
        if (!(this.f9003P == null && this.f9001N == -1) && p0Var.b() == 0) {
            G0(i0Var);
            return;
        }
        G g8 = this.f9003P;
        if (g8 != null && (i13 = g8.f4457q) >= 0) {
            this.f9001N = i13;
        }
        i1();
        this.f8995G.f4446a = false;
        z1();
        RecyclerView recyclerView = this.f9115r;
        if (recyclerView == null || (focusedChild = recyclerView.getFocusedChild()) == null || ((ArrayList) this.f9114q.f72u).contains(focusedChild)) {
            focusedChild = null;
        }
        x xVar = this.f9004Q;
        if (!xVar.f359d || this.f9001N != -1 || this.f9003P != null) {
            xVar.g();
            xVar.f357b = this.f8998K ^ this.f8999L;
            if (p0Var.f4620g || (i = this.f9001N) == -1) {
                if (I() != 0) {
                    RecyclerView recyclerView2 = this.f9115r;
                    if (recyclerView2 == null || (focusedChild2 = recyclerView2.getFocusedChild()) == null || ((ArrayList) this.f9114q.f72u).contains(focusedChild2)) {
                        focusedChild2 = null;
                    }
                    if (focusedChild2 != null) {
                        C0203d0 c0203d0 = (C0203d0) focusedChild2.getLayoutParams();
                        if (c0203d0.f4520q.j() || c0203d0.f4520q.d() < 0 || c0203d0.f4520q.d() >= p0Var.b()) {
                            boolean z8 = this.f8996I;
                            boolean z9 = this.f8999L;
                            if (z8 == z9 && (viewP1 = p1(i0Var, p0Var, xVar.f357b, z9)) != null) {
                                xVar.c(viewP1, a.T(viewP1));
                                if (!p0Var.f4620g && b1()) {
                                    int iG2 = this.H.g(viewP1);
                                    int iD = this.H.d(viewP1);
                                    int iM = this.H.m();
                                    int i15 = this.H.i();
                                    boolean z10 = iD <= iM && iG2 < iM;
                                    boolean z11 = iG2 >= i15 && iD > i15;
                                    if (z10 || z11) {
                                        if (xVar.f357b) {
                                            iM = i15;
                                        }
                                        xVar.f360e = iM;
                                    }
                                }
                            } else {
                                xVar.b();
                                xVar.f358c = this.f8999L ? p0Var.b() - 1 : 0;
                            }
                        } else {
                            xVar.d(focusedChild2, a.T(focusedChild2));
                        }
                        xVar.f359d = true;
                    }
                }
            } else if (i < 0 || i >= p0Var.b()) {
                this.f9001N = -1;
                this.f9002O = Integer.MIN_VALUE;
                if (I() != 0) {
                }
            } else {
                int i16 = this.f9001N;
                xVar.f358c = i16;
                G g9 = this.f9003P;
                if (g9 != null && g9.f4457q >= 0) {
                    boolean z12 = g9.f4459s;
                    xVar.f357b = z12;
                    if (z12) {
                        xVar.f360e = this.H.i() - this.f9003P.f4458r;
                    } else {
                        xVar.f360e = this.H.m() + this.f9003P.f4458r;
                    }
                } else if (this.f9002O == Integer.MIN_VALUE) {
                    View viewD2 = D(i16);
                    if (viewD2 == null) {
                        if (I() > 0) {
                            xVar.f357b = (this.f9001N < a.T(H(0))) == this.f8998K;
                        }
                        xVar.b();
                    } else if (this.H.e(viewD2) > this.H.n()) {
                        xVar.b();
                    } else if (this.H.g(viewD2) - this.H.m() < 0) {
                        xVar.f360e = this.H.m();
                        xVar.f357b = false;
                    } else if (this.H.i() - this.H.d(viewD2) < 0) {
                        xVar.f360e = this.H.i();
                        xVar.f357b = true;
                    } else {
                        xVar.f360e = xVar.f357b ? this.H.o() + this.H.d(viewD2) : this.H.g(viewD2);
                    }
                } else {
                    boolean z13 = this.f8998K;
                    xVar.f357b = z13;
                    if (z13) {
                        xVar.f360e = this.H.i() - this.f9002O;
                    } else {
                        xVar.f360e = this.H.m() + this.f9002O;
                    }
                }
                xVar.f359d = true;
            }
        } else if (focusedChild != null && (this.H.g(focusedChild) >= this.H.i() || this.H.d(focusedChild) <= this.H.m())) {
            xVar.d(focusedChild, a.T(focusedChild));
        }
        F f3 = this.f8995G;
        f3.f4451f = f3.f4454j >= 0 ? 1 : -1;
        int[] iArr = this.f9007T;
        iArr[0] = 0;
        iArr[1] = 0;
        c1(p0Var, iArr);
        int iM2 = this.H.m() + Math.max(0, iArr[0]);
        int iJ = this.H.j() + Math.max(0, iArr[1]);
        if (p0Var.f4620g && (i11 = this.f9001N) != -1 && this.f9002O != Integer.MIN_VALUE && (viewD = D(i11)) != null) {
            if (this.f8998K) {
                i12 = this.H.i() - this.H.d(viewD);
                iG = this.f9002O;
            } else {
                iG = this.H.g(viewD) - this.H.m();
                i12 = this.f9002O;
            }
            int i17 = i12 - iG;
            if (i17 > 0) {
                iM2 += i17;
            } else {
                iJ -= i17;
            }
        }
        if (!xVar.f357b ? !this.f8998K : this.f8998K) {
            i14 = 1;
        }
        w1(i0Var, p0Var, xVar, i14);
        B(i0Var);
        this.f8995G.f4456l = this.H.k() == 0 && this.H.h() == 0;
        this.f8995G.getClass();
        this.f8995G.i = 0;
        if (xVar.f357b) {
            F1(xVar.f358c, xVar.f360e);
            F f7 = this.f8995G;
            f7.f4453h = iM2;
            j1(i0Var, f7, p0Var, false);
            F f8 = this.f8995G;
            i8 = f8.f4447b;
            int i18 = f8.f4449d;
            int i19 = f8.f4448c;
            if (i19 > 0) {
                iJ += i19;
            }
            E1(xVar.f358c, xVar.f360e);
            F f9 = this.f8995G;
            f9.f4453h = iJ;
            f9.f4449d += f9.f4450e;
            j1(i0Var, f9, p0Var, false);
            F f10 = this.f8995G;
            i5 = f10.f4447b;
            int i20 = f10.f4448c;
            if (i20 > 0) {
                F1(i18, i8);
                F f11 = this.f8995G;
                f11.f4453h = i20;
                j1(i0Var, f11, p0Var, false);
                i8 = this.f8995G.f4447b;
            }
        } else {
            E1(xVar.f358c, xVar.f360e);
            F f12 = this.f8995G;
            f12.f4453h = iJ;
            j1(i0Var, f12, p0Var, false);
            F f13 = this.f8995G;
            i5 = f13.f4447b;
            int i21 = f13.f4449d;
            int i22 = f13.f4448c;
            if (i22 > 0) {
                iM2 += i22;
            }
            F1(xVar.f358c, xVar.f360e);
            F f14 = this.f8995G;
            f14.f4453h = iM2;
            f14.f4449d += f14.f4450e;
            j1(i0Var, f14, p0Var, false);
            F f15 = this.f8995G;
            int i23 = f15.f4447b;
            int i24 = f15.f4448c;
            if (i24 > 0) {
                E1(i21, i5);
                F f16 = this.f8995G;
                f16.f4453h = i24;
                j1(i0Var, f16, p0Var, false);
                i5 = this.f8995G.f4447b;
            }
            i8 = i23;
        }
        if (I() > 0) {
            if (this.f8998K ^ this.f8999L) {
                int iQ12 = q1(i5, i0Var, p0Var, true);
                i9 = i8 + iQ12;
                i10 = i5 + iQ12;
                iQ1 = r1(i9, i0Var, p0Var, false);
            } else {
                int iR1 = r1(i8, i0Var, p0Var, true);
                i9 = i8 + iR1;
                i10 = i5 + iR1;
                iQ1 = q1(i10, i0Var, p0Var, false);
            }
            i8 = i9 + iQ1;
            i5 = i10 + iQ1;
        }
        if (p0Var.f4623k && I() != 0 && !p0Var.f4620g && b1()) {
            List list2 = i0Var.f4558d;
            int size = list2.size();
            int iT = a.T(H(0));
            int iE = 0;
            int iE2 = 0;
            for (int i25 = 0; i25 < size; i25++) {
                t0 t0Var = (t0) list2.get(i25);
                if (!t0Var.j()) {
                    boolean z14 = t0Var.d() < iT;
                    boolean z15 = this.f8998K;
                    View view = t0Var.f4654a;
                    if (z14 != z15) {
                        iE += this.H.e(view);
                    } else {
                        iE2 += this.H.e(view);
                    }
                }
            }
            this.f8995G.f4455k = list2;
            if (iE > 0) {
                F1(a.T(t1()), i8);
                F f17 = this.f8995G;
                f17.f4453h = iE;
                f17.f4448c = 0;
                f17.a(null);
                j1(i0Var, this.f8995G, p0Var, false);
            }
            if (iE2 > 0) {
                E1(a.T(s1()), i5);
                F f18 = this.f8995G;
                f18.f4453h = iE2;
                f18.f4448c = 0;
                list = null;
                f18.a(null);
                j1(i0Var, this.f8995G, p0Var, false);
            } else {
                list = null;
            }
            this.f8995G.f4455k = list;
        }
        if (p0Var.f4620g) {
            xVar.g();
        } else {
            M m8 = this.H;
            m8.f4478a = m8.n();
        }
        this.f8996I = this.f8999L;
    }

    @Override // androidx.recyclerview.widget.a
    public int x(p0 p0Var) {
        return g1(p0Var);
    }

    @Override // androidx.recyclerview.widget.a
    public void x0(p0 p0Var) {
        this.f9003P = null;
        this.f9001N = -1;
        this.f9002O = Integer.MIN_VALUE;
        this.f9004Q.g();
    }

    public final void x1(i0 i0Var, F f3) {
        if (!f3.f4446a || f3.f4456l) {
            return;
        }
        int i = f3.f4452g;
        int i5 = f3.i;
        if (f3.f4451f == -1) {
            int I7 = I();
            if (i < 0) {
                return;
            }
            int iH = (this.H.h() - i) + i5;
            if (this.f8998K) {
                for (int i8 = 0; i8 < I7; i8++) {
                    View viewH = H(i8);
                    if (this.H.g(viewH) < iH || this.H.q(viewH) < iH) {
                        y1(i0Var, 0, i8);
                        return;
                    }
                }
                return;
            }
            int i9 = I7 - 1;
            for (int i10 = i9; i10 >= 0; i10--) {
                View viewH2 = H(i10);
                if (this.H.g(viewH2) < iH || this.H.q(viewH2) < iH) {
                    y1(i0Var, i9, i10);
                    return;
                }
            }
            return;
        }
        if (i < 0) {
            return;
        }
        int i11 = i - i5;
        int I8 = I();
        if (!this.f8998K) {
            for (int i12 = 0; i12 < I8; i12++) {
                View viewH3 = H(i12);
                if (this.H.d(viewH3) > i11 || this.H.p(viewH3) > i11) {
                    y1(i0Var, 0, i12);
                    return;
                }
            }
            return;
        }
        int i13 = I8 - 1;
        for (int i14 = i13; i14 >= 0; i14--) {
            View viewH4 = H(i14);
            if (this.H.d(viewH4) > i11 || this.H.p(viewH4) > i11) {
                y1(i0Var, i13, i14);
                return;
            }
        }
    }

    @Override // androidx.recyclerview.widget.a
    public final int y(p0 p0Var) {
        return e1(p0Var);
    }

    public final void y1(i0 i0Var, int i, int i5) {
        if (i == i5) {
            return;
        }
        if (i5 <= i) {
            while (i > i5) {
                J0(i, i0Var);
                i--;
            }
        } else {
            for (int i8 = i5 - 1; i8 >= i; i8--) {
                J0(i8, i0Var);
            }
        }
    }

    @Override // androidx.recyclerview.widget.a
    public int z(p0 p0Var) {
        return f1(p0Var);
    }

    public final void z1() {
        if (this.f8994F == 1 || !u1()) {
            this.f8998K = this.f8997J;
        } else {
            this.f8998K = !this.f8997J;
        }
    }

    @SuppressLint({"UnknownNullness"})
    public LinearLayoutManager(Context context, AttributeSet attributeSet, int i, int i5) {
        this.f8994F = 1;
        this.f8997J = false;
        this.f8998K = false;
        this.f8999L = false;
        this.f9000M = true;
        this.f9001N = -1;
        this.f9002O = Integer.MIN_VALUE;
        this.f9003P = null;
        this.f9004Q = new x();
        this.f9005R = new E();
        this.f9006S = 2;
        this.f9007T = new int[2];
        C0201c0 c0201c0U = a.U(context, attributeSet, i, i5);
        B1(c0201c0U.f4515a);
        boolean z8 = c0201c0U.f4517c;
        n(null);
        if (z8 != this.f8997J) {
            this.f8997J = z8;
            M0();
        }
        C1(c0201c0U.f4518d);
    }

    @Override // androidx.recyclerview.widget.a
    public final void j0(RecyclerView recyclerView, i0 i0Var) {
    }

    public void w1(i0 i0Var, p0 p0Var, x xVar, int i) {
    }
}
