package androidx.recyclerview.widget;

import V.C0629x;
import android.content.Context;
import android.graphics.Rect;
import android.os.Parcelable;
import android.util.AttributeSet;
import android.view.View;
import android.view.ViewGroup;
import android.view.accessibility.AccessibilityEvent;
import java.util.ArrayList;
import java.util.List;

/* JADX INFO: loaded from: classes.dex */
public class LinearLayoutManager extends J {

    /* JADX INFO: renamed from: A, reason: collision with root package name */
    public final C1168s f12860A;

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

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

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

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

    /* JADX INFO: renamed from: q, reason: collision with root package name */
    public C1170u f12865q;

    /* JADX INFO: renamed from: r, reason: collision with root package name */
    public T1.f f12866r;

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

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

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

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

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

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

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

    /* JADX INFO: renamed from: z, reason: collision with root package name */
    public C1171v f12874z;

    public LinearLayoutManager() {
        this.f12864p = 1;
        this.f12868t = false;
        this.f12869u = false;
        this.f12870v = false;
        this.f12871w = true;
        this.f12872x = -1;
        this.f12873y = Integer.MIN_VALUE;
        this.f12874z = null;
        this.f12860A = new C1168s();
        this.f12861B = new C1169t();
        this.f12862C = 2;
        this.f12863D = new int[2];
        j1(1);
        b(null);
        if (this.f12868t) {
            this.f12868t = false;
            y0();
        }
    }

    @Override // androidx.recyclerview.widget.J
    public int A0(int i6, P p6, V v3) {
        if (this.f12864p == 1) {
            return 0;
        }
        return i1(i6, p6, v3);
    }

    @Override // androidx.recyclerview.widget.J
    public final void B0(int i6) {
        this.f12872x = i6;
        this.f12873y = Integer.MIN_VALUE;
        C1171v c1171v = this.f12874z;
        if (c1171v != null) {
            c1171v.f13188a = -1;
        }
        y0();
    }

    @Override // androidx.recyclerview.widget.J
    public int C0(int i6, P p6, V v3) {
        if (this.f12864p == 0) {
            return 0;
        }
        return i1(i6, p6, v3);
    }

    @Override // androidx.recyclerview.widget.J
    public final boolean J0() {
        if (this.f12853m != 1073741824 && this.l != 1073741824) {
            int iW = w();
            for (int i6 = 0; i6 < iW; i6++) {
                ViewGroup.LayoutParams layoutParams = v(i6).getLayoutParams();
                if (layoutParams.width < 0 && layoutParams.height < 0) {
                    return true;
                }
            }
        }
        return false;
    }

    @Override // androidx.recyclerview.widget.J
    public boolean L0() {
        return this.f12874z == null && this.f12867s == this.f12870v;
    }

    public void M0(V v3, C1170u c1170u, C0629x c0629x) {
        int i6 = c1170u.f13180d;
        if (i6 < 0 || i6 >= v3.b()) {
            return;
        }
        c0629x.a(i6, Math.max(0, c1170u.f13183g));
    }

    public final int N0(V v3) {
        if (w() == 0) {
            return 0;
        }
        R0();
        T1.f fVar = this.f12866r;
        boolean z6 = !this.f12871w;
        return W0.e.k(v3, fVar, U0(z6), T0(z6), this, this.f12871w);
    }

    public final int O0(V v3) {
        if (w() == 0) {
            return 0;
        }
        R0();
        T1.f fVar = this.f12866r;
        boolean z6 = !this.f12871w;
        return W0.e.l(v3, fVar, U0(z6), T0(z6), this, this.f12871w, this.f12869u);
    }

    public final int P0(V v3) {
        if (w() == 0) {
            return 0;
        }
        R0();
        T1.f fVar = this.f12866r;
        boolean z6 = !this.f12871w;
        return W0.e.m(v3, fVar, U0(z6), T0(z6), this, this.f12871w);
    }

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

    public final int Q0(int i6) {
        return i6 != 1 ? i6 != 2 ? i6 != 17 ? i6 != 33 ? i6 != 66 ? (i6 == 130 && this.f12864p == 1) ? 1 : Integer.MIN_VALUE : this.f12864p == 0 ? 1 : Integer.MIN_VALUE : this.f12864p == 1 ? -1 : Integer.MIN_VALUE : this.f12864p == 0 ? -1 : Integer.MIN_VALUE : (this.f12864p != 1 && c1()) ? -1 : 1 : (this.f12864p != 1 && c1()) ? 1 : -1;
    }

    public final void R0() {
        if (this.f12865q == null) {
            C1170u c1170u = new C1170u();
            c1170u.f13177a = true;
            c1170u.f13184h = 0;
            c1170u.f13185i = 0;
            c1170u.f13187k = null;
            this.f12865q = c1170u;
        }
    }

    public final int S0(P p6, C1170u c1170u, V v3, boolean z6) {
        int i6;
        int i7 = c1170u.f13179c;
        int i8 = c1170u.f13183g;
        if (i8 != Integer.MIN_VALUE) {
            if (i7 < 0) {
                c1170u.f13183g = i8 + i7;
            }
            f1(p6, c1170u);
        }
        int i9 = c1170u.f13179c + c1170u.f13184h;
        while (true) {
            if ((!c1170u.l && i9 <= 0) || (i6 = c1170u.f13180d) < 0 || i6 >= v3.b()) {
                break;
            }
            C1169t c1169t = this.f12861B;
            c1169t.f13173a = 0;
            c1169t.f13174b = false;
            c1169t.f13175c = false;
            c1169t.f13176d = false;
            d1(p6, v3, c1170u, c1169t);
            if (!c1169t.f13174b) {
                int i10 = c1170u.f13178b;
                int i11 = c1169t.f13173a;
                c1170u.f13178b = (c1170u.f13182f * i11) + i10;
                if (!c1169t.f13175c || c1170u.f13187k != null || !v3.f13003g) {
                    c1170u.f13179c -= i11;
                    i9 -= i11;
                }
                int i12 = c1170u.f13183g;
                if (i12 != Integer.MIN_VALUE) {
                    int i13 = i12 + i11;
                    c1170u.f13183g = i13;
                    int i14 = c1170u.f13179c;
                    if (i14 < 0) {
                        c1170u.f13183g = i13 + i14;
                    }
                    f1(p6, c1170u);
                }
                if (z6 && c1169t.f13176d) {
                    break;
                }
            } else {
                break;
            }
        }
        return i7 - c1170u.f13179c;
    }

    public final View T0(boolean z6) {
        return this.f12869u ? W0(0, w(), z6) : W0(w() - 1, -1, z6);
    }

    public final View U0(boolean z6) {
        return this.f12869u ? W0(w() - 1, -1, z6) : W0(0, w(), z6);
    }

    public final View V0(int i6, int i7) {
        int i8;
        int i9;
        R0();
        if (i7 <= i6 && i7 >= i6) {
            return v(i6);
        }
        if (this.f12866r.e(v(i6)) < this.f12866r.k()) {
            i8 = 16644;
            i9 = 16388;
        } else {
            i8 = 4161;
            i9 = 4097;
        }
        return this.f12864p == 0 ? this.f12844c.e(i6, i7, i8, i9) : this.f12845d.e(i6, i7, i8, i9);
    }

    public final View W0(int i6, int i7, boolean z6) {
        R0();
        int i8 = z6 ? 24579 : 320;
        return this.f12864p == 0 ? this.f12844c.e(i6, i7, i8, 320) : this.f12845d.e(i6, i7, i8, 320);
    }

    /* 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 X0(P p6, V v3, boolean z6, boolean z7) {
        int i6;
        int iW;
        int i7;
        R0();
        int iW2 = w();
        if (z7) {
            iW = w() - 1;
            i6 = -1;
            i7 = -1;
        } else {
            i6 = iW2;
            iW = 0;
            i7 = 1;
        }
        int iB = v3.b();
        int iK = this.f12866r.k();
        int iG = this.f12866r.g();
        View view = null;
        View view2 = null;
        View view3 = null;
        while (iW != i6) {
            View viewV = v(iW);
            int iL = J.L(viewV);
            int iE = this.f12866r.e(viewV);
            int iB2 = this.f12866r.b(viewV);
            if (iL >= 0 && iL < iB) {
                if (!((K) viewV.getLayoutParams()).f12856a.isRemoved()) {
                    boolean z8 = iB2 <= iK && iE < iK;
                    boolean z9 = iE >= iG && iB2 > iG;
                    if (!z8 && !z9) {
                        return viewV;
                    }
                    if (z6) {
                        if (z9) {
                            view2 = viewV;
                        } else if (view == null) {
                            view = viewV;
                        }
                    } else if (!z8) {
                        if (view == null) {
                        }
                    }
                } else if (view3 == null) {
                    view3 = viewV;
                }
            }
            iW += i7;
        }
        return view != null ? view : view2 != null ? view2 : view3;
    }

    @Override // androidx.recyclerview.widget.J
    public View Y(View view, int i6, P p6, V v3) {
        int iQ0;
        h1();
        if (w() != 0 && (iQ0 = Q0(i6)) != Integer.MIN_VALUE) {
            R0();
            l1(iQ0, (int) (this.f12866r.l() * 0.33333334f), false, v3);
            C1170u c1170u = this.f12865q;
            c1170u.f13183g = Integer.MIN_VALUE;
            c1170u.f13177a = false;
            S0(p6, c1170u, v3, true);
            View viewV0 = iQ0 == -1 ? this.f12869u ? V0(w() - 1, -1) : V0(0, w()) : this.f12869u ? V0(0, w()) : V0(w() - 1, -1);
            View viewB1 = iQ0 == -1 ? b1() : a1();
            if (!viewB1.hasFocusable()) {
                return viewV0;
            }
            if (viewV0 != null) {
                return viewB1;
            }
        }
        return null;
    }

    public final int Y0(int i6, P p6, V v3, boolean z6) {
        int iG;
        int iG2 = this.f12866r.g() - i6;
        if (iG2 <= 0) {
            return 0;
        }
        int i7 = -i1(-iG2, p6, v3);
        int i8 = i6 + i7;
        if (!z6 || (iG = this.f12866r.g() - i8) <= 0) {
            return i7;
        }
        this.f12866r.o(iG);
        return iG + i7;
    }

    @Override // androidx.recyclerview.widget.J
    public final void Z(AccessibilityEvent accessibilityEvent) {
        super.Z(accessibilityEvent);
        if (w() > 0) {
            View viewW0 = W0(0, w(), false);
            accessibilityEvent.setFromIndex(viewW0 == null ? -1 : J.L(viewW0));
            View viewW02 = W0(w() - 1, -1, false);
            accessibilityEvent.setToIndex(viewW02 != null ? J.L(viewW02) : -1);
        }
    }

    public final int Z0(int i6, P p6, V v3, boolean z6) {
        int iK;
        int iK2 = i6 - this.f12866r.k();
        if (iK2 <= 0) {
            return 0;
        }
        int i7 = -i1(iK2, p6, v3);
        int i8 = i6 + i7;
        if (!z6 || (iK = i8 - this.f12866r.k()) <= 0) {
            return i7;
        }
        this.f12866r.o(-iK);
        return i7 - iK;
    }

    public final View a1() {
        return v(this.f12869u ? 0 : w() - 1);
    }

    @Override // androidx.recyclerview.widget.J
    public final void b(String str) {
        if (this.f12874z == null) {
            super.b(str);
        }
    }

    public final View b1() {
        return v(this.f12869u ? w() - 1 : 0);
    }

    public final boolean c1() {
        return G() == 1;
    }

    @Override // androidx.recyclerview.widget.J
    public final boolean d() {
        return this.f12864p == 0;
    }

    public void d1(P p6, V v3, C1170u c1170u, C1169t c1169t) {
        int I5;
        int i6;
        int i7;
        int iD;
        View viewB = c1170u.b(p6);
        if (viewB == null) {
            c1169t.f13174b = true;
            return;
        }
        K k6 = (K) viewB.getLayoutParams();
        if (c1170u.f13187k == null) {
            if (this.f12869u == (c1170u.f13182f == -1)) {
                a(viewB, -1, false);
            } else {
                a(viewB, 0, false);
            }
        } else {
            if (this.f12869u == (c1170u.f13182f == -1)) {
                a(viewB, -1, true);
            } else {
                a(viewB, 0, true);
            }
        }
        K k7 = (K) viewB.getLayoutParams();
        Rect rectH = this.f12843b.H(viewB);
        int i8 = rectH.left + rectH.right;
        int i9 = rectH.top + rectH.bottom;
        int iX = J.x(d(), this.f12854n, this.l, J() + I() + ((ViewGroup.MarginLayoutParams) k7).leftMargin + ((ViewGroup.MarginLayoutParams) k7).rightMargin + i8, ((ViewGroup.MarginLayoutParams) k7).width);
        int iX2 = J.x(e(), this.f12855o, this.f12853m, H() + K() + ((ViewGroup.MarginLayoutParams) k7).topMargin + ((ViewGroup.MarginLayoutParams) k7).bottomMargin + i9, ((ViewGroup.MarginLayoutParams) k7).height);
        if (I0(viewB, iX, iX2, k7)) {
            viewB.measure(iX, iX2);
        }
        c1169t.f13173a = this.f12866r.c(viewB);
        if (this.f12864p == 1) {
            if (c1()) {
                iD = this.f12854n - J();
                I5 = iD - this.f12866r.d(viewB);
            } else {
                I5 = I();
                iD = this.f12866r.d(viewB) + I5;
            }
            if (c1170u.f13182f == -1) {
                i6 = c1170u.f13178b;
                i7 = i6 - c1169t.f13173a;
            } else {
                i7 = c1170u.f13178b;
                i6 = c1169t.f13173a + i7;
            }
        } else {
            int iK = K();
            int iD2 = this.f12866r.d(viewB) + iK;
            if (c1170u.f13182f == -1) {
                int i10 = c1170u.f13178b;
                int i11 = i10 - c1169t.f13173a;
                iD = i10;
                i6 = iD2;
                I5 = i11;
                i7 = iK;
            } else {
                int i12 = c1170u.f13178b;
                int i13 = c1169t.f13173a + i12;
                I5 = i12;
                i6 = iD2;
                i7 = iK;
                iD = i13;
            }
        }
        J.S(viewB, I5, i7, iD, i6);
        if (k6.f12856a.isRemoved() || k6.f12856a.isUpdated()) {
            c1169t.f13175c = true;
        }
        c1169t.f13176d = viewB.hasFocusable();
    }

    @Override // androidx.recyclerview.widget.J
    public final boolean e() {
        return this.f12864p == 1;
    }

    public void e1(P p6, V v3, C1168s c1168s, int i6) {
    }

    public final void f1(P p6, C1170u c1170u) {
        if (!c1170u.f13177a || c1170u.l) {
            return;
        }
        int i6 = c1170u.f13183g;
        int i7 = c1170u.f13185i;
        if (c1170u.f13182f == -1) {
            int iW = w();
            if (i6 < 0) {
                return;
            }
            int iF = (this.f12866r.f() - i6) + i7;
            if (this.f12869u) {
                for (int i8 = 0; i8 < iW; i8++) {
                    View viewV = v(i8);
                    if (this.f12866r.e(viewV) < iF || this.f12866r.n(viewV) < iF) {
                        g1(p6, 0, i8);
                        return;
                    }
                }
                return;
            }
            int i9 = iW - 1;
            for (int i10 = i9; i10 >= 0; i10--) {
                View viewV2 = v(i10);
                if (this.f12866r.e(viewV2) < iF || this.f12866r.n(viewV2) < iF) {
                    g1(p6, i9, i10);
                    return;
                }
            }
            return;
        }
        if (i6 < 0) {
            return;
        }
        int i11 = i6 - i7;
        int iW2 = w();
        if (!this.f12869u) {
            for (int i12 = 0; i12 < iW2; i12++) {
                View viewV3 = v(i12);
                if (this.f12866r.b(viewV3) > i11 || this.f12866r.m(viewV3) > i11) {
                    g1(p6, 0, i12);
                    return;
                }
            }
            return;
        }
        int i13 = iW2 - 1;
        for (int i14 = i13; i14 >= 0; i14--) {
            View viewV4 = v(i14);
            if (this.f12866r.b(viewV4) > i11 || this.f12866r.m(viewV4) > i11) {
                g1(p6, i13, i14);
                return;
            }
        }
    }

    public final void g1(P p6, int i6, int i7) {
        if (i6 == i7) {
            return;
        }
        if (i7 <= i6) {
            while (i6 > i7) {
                View viewV = v(i6);
                v0(i6);
                p6.i(viewV);
                i6--;
            }
            return;
        }
        for (int i8 = i7 - 1; i8 >= i6; i8--) {
            View viewV2 = v(i8);
            v0(i8);
            p6.i(viewV2);
        }
    }

    @Override // androidx.recyclerview.widget.J
    public final void h(int i6, int i7, V v3, C0629x c0629x) {
        if (this.f12864p != 0) {
            i6 = i7;
        }
        if (w() == 0 || i6 == 0) {
            return;
        }
        R0();
        l1(i6 > 0 ? 1 : -1, Math.abs(i6), true, v3);
        M0(v3, this.f12865q, c0629x);
    }

    public final void h1() {
        if (this.f12864p == 1 || !c1()) {
            this.f12869u = this.f12868t;
        } else {
            this.f12869u = !this.f12868t;
        }
    }

    @Override // androidx.recyclerview.widget.J
    public final void i(int i6, C0629x c0629x) {
        boolean z6;
        int i7;
        C1171v c1171v = this.f12874z;
        if (c1171v == null || (i7 = c1171v.f13188a) < 0) {
            h1();
            z6 = this.f12869u;
            i7 = this.f12872x;
            if (i7 == -1) {
                i7 = z6 ? i6 - 1 : 0;
            }
        } else {
            z6 = c1171v.f13190c;
        }
        int i8 = z6 ? -1 : 1;
        for (int i9 = 0; i9 < this.f12862C && i7 >= 0 && i7 < i6; i9++) {
            c0629x.a(i7, 0);
            i7 += i8;
        }
    }

    public final int i1(int i6, P p6, V v3) {
        if (w() != 0 && i6 != 0) {
            R0();
            this.f12865q.f13177a = true;
            int i7 = i6 > 0 ? 1 : -1;
            int iAbs = Math.abs(i6);
            l1(i7, iAbs, true, v3);
            C1170u c1170u = this.f12865q;
            int iS0 = S0(p6, c1170u, v3, false) + c1170u.f13183g;
            if (iS0 >= 0) {
                if (iAbs > iS0) {
                    i6 = i7 * iS0;
                }
                this.f12866r.o(-i6);
                this.f12865q.f13186j = i6;
                return i6;
            }
        }
        return 0;
    }

    @Override // androidx.recyclerview.widget.J
    public final int j(V v3) {
        return N0(v3);
    }

    public final void j1(int i6) {
        if (i6 != 0 && i6 != 1) {
            throw new IllegalArgumentException(Z0.o.l("invalid orientation:", i6));
        }
        b(null);
        if (i6 != this.f12864p || this.f12866r == null) {
            T1.f fVarA = T1.f.a(this, i6);
            this.f12866r = fVarA;
            this.f12860A.f13168a = fVarA;
            this.f12864p = i6;
            y0();
        }
    }

    @Override // androidx.recyclerview.widget.J
    public int k(V v3) {
        return O0(v3);
    }

    /* JADX WARN: Removed duplicated region for block: B:111:0x01d9  */
    /* JADX WARN: Removed duplicated region for block: B:135:0x022b  */
    /* JADX WARN: Removed duplicated region for block: B:95:0x0194  */
    @Override // androidx.recyclerview.widget.J
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public void k0(P p6, V v3) {
        View focusedChild;
        View focusedChild2;
        View viewX0;
        int i6;
        int iE;
        int i7;
        int i8;
        int i9;
        List list;
        int i10;
        int i11;
        int iY0;
        int i12;
        View viewR;
        int iE2;
        int iG;
        int i13;
        int i14 = -1;
        if (!(this.f12874z == null && this.f12872x == -1) && v3.b() == 0) {
            s0(p6);
            return;
        }
        C1171v c1171v = this.f12874z;
        if (c1171v != null && (i13 = c1171v.f13188a) >= 0) {
            this.f12872x = i13;
        }
        R0();
        this.f12865q.f13177a = false;
        h1();
        RecyclerView recyclerView = this.f12843b;
        if (recyclerView == null || (focusedChild = recyclerView.getFocusedChild()) == null || ((ArrayList) this.f12842a.f743d).contains(focusedChild)) {
            focusedChild = null;
        }
        C1168s c1168s = this.f12860A;
        if (!c1168s.f13172e || this.f12872x != -1 || this.f12874z != null) {
            c1168s.d();
            c1168s.f13171d = this.f12869u ^ this.f12870v;
            if (v3.f13003g || (i6 = this.f12872x) == -1) {
                if (w() != 0) {
                    RecyclerView recyclerView2 = this.f12843b;
                    if (recyclerView2 == null || (focusedChild2 = recyclerView2.getFocusedChild()) == null || ((ArrayList) this.f12842a.f743d).contains(focusedChild2)) {
                        focusedChild2 = null;
                    }
                    if (focusedChild2 != null) {
                        K k6 = (K) focusedChild2.getLayoutParams();
                        if (k6.f12856a.isRemoved() || k6.f12856a.getLayoutPosition() < 0 || k6.f12856a.getLayoutPosition() >= v3.b()) {
                            boolean z6 = this.f12867s;
                            boolean z7 = this.f12870v;
                            if (z6 == z7 && (viewX0 = X0(p6, v3, c1168s.f13171d, z7)) != null) {
                                c1168s.b(J.L(viewX0), viewX0);
                                if (!v3.f13003g && L0()) {
                                    int iE3 = this.f12866r.e(viewX0);
                                    int iB = this.f12866r.b(viewX0);
                                    int iK = this.f12866r.k();
                                    int iG2 = this.f12866r.g();
                                    boolean z8 = iB <= iK && iE3 < iK;
                                    boolean z9 = iE3 >= iG2 && iB > iG2;
                                    if (z8 || z9) {
                                        if (c1168s.f13171d) {
                                            iK = iG2;
                                        }
                                        c1168s.f13170c = iK;
                                    }
                                }
                            } else {
                                c1168s.a();
                                c1168s.f13169b = this.f12870v ? v3.b() - 1 : 0;
                            }
                        } else {
                            c1168s.c(J.L(focusedChild2), focusedChild2);
                        }
                        c1168s.f13172e = true;
                    }
                }
            } else if (i6 < 0 || i6 >= v3.b()) {
                this.f12872x = -1;
                this.f12873y = Integer.MIN_VALUE;
                if (w() != 0) {
                }
            } else {
                int i15 = this.f12872x;
                c1168s.f13169b = i15;
                C1171v c1171v2 = this.f12874z;
                if (c1171v2 != null && c1171v2.f13188a >= 0) {
                    boolean z10 = c1171v2.f13190c;
                    c1168s.f13171d = z10;
                    if (z10) {
                        c1168s.f13170c = this.f12866r.g() - this.f12874z.f13189b;
                    } else {
                        c1168s.f13170c = this.f12866r.k() + this.f12874z.f13189b;
                    }
                } else if (this.f12873y == Integer.MIN_VALUE) {
                    View viewR2 = r(i15);
                    if (viewR2 == null) {
                        if (w() > 0) {
                            c1168s.f13171d = (this.f12872x < J.L(v(0))) == this.f12869u;
                        }
                        c1168s.a();
                    } else if (this.f12866r.c(viewR2) > this.f12866r.l()) {
                        c1168s.a();
                    } else if (this.f12866r.e(viewR2) - this.f12866r.k() < 0) {
                        c1168s.f13170c = this.f12866r.k();
                        c1168s.f13171d = false;
                    } else if (this.f12866r.g() - this.f12866r.b(viewR2) < 0) {
                        c1168s.f13170c = this.f12866r.g();
                        c1168s.f13171d = true;
                    } else {
                        if (c1168s.f13171d) {
                            int iB2 = this.f12866r.b(viewR2);
                            T1.f fVar = this.f12866r;
                            iE = (Integer.MIN_VALUE == fVar.f6580a ? 0 : fVar.l() - fVar.f6580a) + iB2;
                        } else {
                            iE = this.f12866r.e(viewR2);
                        }
                        c1168s.f13170c = iE;
                    }
                } else {
                    boolean z11 = this.f12869u;
                    c1168s.f13171d = z11;
                    if (z11) {
                        c1168s.f13170c = this.f12866r.g() - this.f12873y;
                    } else {
                        c1168s.f13170c = this.f12866r.k() + this.f12873y;
                    }
                }
                c1168s.f13172e = true;
            }
        } else if (focusedChild != null && (this.f12866r.e(focusedChild) >= this.f12866r.g() || this.f12866r.b(focusedChild) <= this.f12866r.k())) {
            c1168s.c(J.L(focusedChild), focusedChild);
        }
        C1170u c1170u = this.f12865q;
        c1170u.f13182f = c1170u.f13186j >= 0 ? 1 : -1;
        int[] iArr = this.f12863D;
        iArr[0] = 0;
        iArr[1] = 0;
        int iL = v3.f12997a != -1 ? this.f12866r.l() : 0;
        if (this.f12865q.f13182f == -1) {
            i7 = 0;
        } else {
            i7 = iL;
            iL = 0;
        }
        iArr[0] = iL;
        iArr[1] = i7;
        int iK2 = this.f12866r.k() + Math.max(0, iL);
        int iH = this.f12866r.h() + Math.max(0, iArr[1]);
        if (v3.f13003g && (i12 = this.f12872x) != -1 && this.f12873y != Integer.MIN_VALUE && (viewR = r(i12)) != null) {
            if (this.f12869u) {
                iG = this.f12866r.g() - this.f12866r.b(viewR);
                iE2 = this.f12873y;
            } else {
                iE2 = this.f12866r.e(viewR) - this.f12866r.k();
                iG = this.f12873y;
            }
            int i16 = iG - iE2;
            if (i16 > 0) {
                iK2 += i16;
            } else {
                iH -= i16;
            }
        }
        if (!c1168s.f13171d ? !this.f12869u : this.f12869u) {
            i14 = 1;
        }
        e1(p6, v3, c1168s, i14);
        p(p6);
        this.f12865q.l = this.f12866r.i() == 0 && this.f12866r.f() == 0;
        this.f12865q.getClass();
        this.f12865q.f13185i = 0;
        if (c1168s.f13171d) {
            n1(c1168s.f13169b, c1168s.f13170c);
            C1170u c1170u2 = this.f12865q;
            c1170u2.f13184h = iK2;
            S0(p6, c1170u2, v3, false);
            C1170u c1170u3 = this.f12865q;
            i9 = c1170u3.f13178b;
            int i17 = c1170u3.f13180d;
            int i18 = c1170u3.f13179c;
            if (i18 > 0) {
                iH += i18;
            }
            m1(c1168s.f13169b, c1168s.f13170c);
            C1170u c1170u4 = this.f12865q;
            c1170u4.f13184h = iH;
            c1170u4.f13180d += c1170u4.f13181e;
            S0(p6, c1170u4, v3, false);
            C1170u c1170u5 = this.f12865q;
            i8 = c1170u5.f13178b;
            int i19 = c1170u5.f13179c;
            if (i19 > 0) {
                n1(i17, i9);
                C1170u c1170u6 = this.f12865q;
                c1170u6.f13184h = i19;
                S0(p6, c1170u6, v3, false);
                i9 = this.f12865q.f13178b;
            }
        } else {
            m1(c1168s.f13169b, c1168s.f13170c);
            C1170u c1170u7 = this.f12865q;
            c1170u7.f13184h = iH;
            S0(p6, c1170u7, v3, false);
            C1170u c1170u8 = this.f12865q;
            i8 = c1170u8.f13178b;
            int i20 = c1170u8.f13180d;
            int i21 = c1170u8.f13179c;
            if (i21 > 0) {
                iK2 += i21;
            }
            n1(c1168s.f13169b, c1168s.f13170c);
            C1170u c1170u9 = this.f12865q;
            c1170u9.f13184h = iK2;
            c1170u9.f13180d += c1170u9.f13181e;
            S0(p6, c1170u9, v3, false);
            C1170u c1170u10 = this.f12865q;
            int i22 = c1170u10.f13178b;
            int i23 = c1170u10.f13179c;
            if (i23 > 0) {
                m1(i20, i8);
                C1170u c1170u11 = this.f12865q;
                c1170u11.f13184h = i23;
                S0(p6, c1170u11, v3, false);
                i8 = this.f12865q.f13178b;
            }
            i9 = i22;
        }
        if (w() > 0) {
            if (this.f12869u ^ this.f12870v) {
                int iY02 = Y0(i8, p6, v3, true);
                i10 = i9 + iY02;
                i11 = i8 + iY02;
                iY0 = Z0(i10, p6, v3, false);
            } else {
                int iZ0 = Z0(i9, p6, v3, true);
                i10 = i9 + iZ0;
                i11 = i8 + iZ0;
                iY0 = Y0(i11, p6, v3, false);
            }
            i9 = i10 + iY0;
            i8 = i11 + iY0;
        }
        if (v3.f13007k && w() != 0 && !v3.f13003g && L0()) {
            List list2 = p6.f12885d;
            int size = list2.size();
            int iL2 = J.L(v(0));
            int iC = 0;
            int iC2 = 0;
            for (int i24 = 0; i24 < size; i24++) {
                Z z12 = (Z) list2.get(i24);
                if (!z12.isRemoved()) {
                    if ((z12.getLayoutPosition() < iL2) != this.f12869u) {
                        iC += this.f12866r.c(z12.itemView);
                    } else {
                        iC2 += this.f12866r.c(z12.itemView);
                    }
                }
            }
            this.f12865q.f13187k = list2;
            if (iC > 0) {
                n1(J.L(b1()), i9);
                C1170u c1170u12 = this.f12865q;
                c1170u12.f13184h = iC;
                c1170u12.f13179c = 0;
                c1170u12.a(null);
                S0(p6, this.f12865q, v3, false);
            }
            if (iC2 > 0) {
                m1(J.L(a1()), i8);
                C1170u c1170u13 = this.f12865q;
                c1170u13.f13184h = iC2;
                c1170u13.f13179c = 0;
                list = null;
                c1170u13.a(null);
                S0(p6, this.f12865q, v3, false);
            } else {
                list = null;
            }
            this.f12865q.f13187k = list;
        }
        if (v3.f13003g) {
            c1168s.d();
        } else {
            T1.f fVar2 = this.f12866r;
            fVar2.f6580a = fVar2.l();
        }
        this.f12867s = this.f12870v;
    }

    public void k1(boolean z6) {
        b(null);
        if (this.f12870v == z6) {
            return;
        }
        this.f12870v = z6;
        y0();
    }

    @Override // androidx.recyclerview.widget.J
    public int l(V v3) {
        return P0(v3);
    }

    @Override // androidx.recyclerview.widget.J
    public void l0(V v3) {
        this.f12874z = null;
        this.f12872x = -1;
        this.f12873y = Integer.MIN_VALUE;
        this.f12860A.d();
    }

    public final void l1(int i6, int i7, boolean z6, V v3) {
        int i8;
        int iK;
        this.f12865q.l = this.f12866r.i() == 0 && this.f12866r.f() == 0;
        this.f12865q.f13182f = i6;
        int[] iArr = this.f12863D;
        iArr[0] = 0;
        iArr[1] = 0;
        int iL = v3.f12997a != -1 ? this.f12866r.l() : 0;
        if (this.f12865q.f13182f == -1) {
            i8 = 0;
        } else {
            i8 = iL;
            iL = 0;
        }
        iArr[0] = iL;
        iArr[1] = i8;
        int iMax = Math.max(0, iL);
        int iMax2 = Math.max(0, iArr[1]);
        boolean z7 = i6 == 1;
        C1170u c1170u = this.f12865q;
        int i9 = z7 ? iMax2 : iMax;
        c1170u.f13184h = i9;
        if (!z7) {
            iMax = iMax2;
        }
        c1170u.f13185i = iMax;
        if (z7) {
            c1170u.f13184h = this.f12866r.h() + i9;
            View viewA1 = a1();
            C1170u c1170u2 = this.f12865q;
            c1170u2.f13181e = this.f12869u ? -1 : 1;
            int iL2 = J.L(viewA1);
            C1170u c1170u3 = this.f12865q;
            c1170u2.f13180d = iL2 + c1170u3.f13181e;
            c1170u3.f13178b = this.f12866r.b(viewA1);
            iK = this.f12866r.b(viewA1) - this.f12866r.g();
        } else {
            View viewB1 = b1();
            C1170u c1170u4 = this.f12865q;
            c1170u4.f13184h = this.f12866r.k() + c1170u4.f13184h;
            C1170u c1170u5 = this.f12865q;
            c1170u5.f13181e = this.f12869u ? 1 : -1;
            int iL3 = J.L(viewB1);
            C1170u c1170u6 = this.f12865q;
            c1170u5.f13180d = iL3 + c1170u6.f13181e;
            c1170u6.f13178b = this.f12866r.e(viewB1);
            iK = (-this.f12866r.e(viewB1)) + this.f12866r.k();
        }
        C1170u c1170u7 = this.f12865q;
        c1170u7.f13179c = i7;
        if (z6) {
            c1170u7.f13179c = i7 - iK;
        }
        c1170u7.f13183g = iK;
    }

    @Override // androidx.recyclerview.widget.J
    public final int m(V v3) {
        return N0(v3);
    }

    public final void m1(int i6, int i7) {
        this.f12865q.f13179c = this.f12866r.g() - i7;
        C1170u c1170u = this.f12865q;
        c1170u.f13181e = this.f12869u ? -1 : 1;
        c1170u.f13180d = i6;
        c1170u.f13182f = 1;
        c1170u.f13178b = i7;
        c1170u.f13183g = Integer.MIN_VALUE;
    }

    @Override // androidx.recyclerview.widget.J
    public int n(V v3) {
        return O0(v3);
    }

    public final void n1(int i6, int i7) {
        this.f12865q.f13179c = i7 - this.f12866r.k();
        C1170u c1170u = this.f12865q;
        c1170u.f13180d = i6;
        c1170u.f13181e = this.f12869u ? 1 : -1;
        c1170u.f13182f = -1;
        c1170u.f13178b = i7;
        c1170u.f13183g = Integer.MIN_VALUE;
    }

    @Override // androidx.recyclerview.widget.J
    public int o(V v3) {
        return P0(v3);
    }

    @Override // androidx.recyclerview.widget.J
    public final void o0(Parcelable parcelable) {
        if (parcelable instanceof C1171v) {
            C1171v c1171v = (C1171v) parcelable;
            this.f12874z = c1171v;
            if (this.f12872x != -1) {
                c1171v.f13188a = -1;
            }
            y0();
        }
    }

    @Override // androidx.recyclerview.widget.J
    public final Parcelable p0() {
        C1171v c1171v = this.f12874z;
        if (c1171v != null) {
            C1171v c1171v2 = new C1171v();
            c1171v2.f13188a = c1171v.f13188a;
            c1171v2.f13189b = c1171v.f13189b;
            c1171v2.f13190c = c1171v.f13190c;
            return c1171v2;
        }
        C1171v c1171v3 = new C1171v();
        if (w() <= 0) {
            c1171v3.f13188a = -1;
            return c1171v3;
        }
        R0();
        boolean z6 = this.f12867s ^ this.f12869u;
        c1171v3.f13190c = z6;
        if (z6) {
            View viewA1 = a1();
            c1171v3.f13189b = this.f12866r.g() - this.f12866r.b(viewA1);
            c1171v3.f13188a = J.L(viewA1);
            return c1171v3;
        }
        View viewB1 = b1();
        c1171v3.f13188a = J.L(viewB1);
        c1171v3.f13189b = this.f12866r.e(viewB1) - this.f12866r.k();
        return c1171v3;
    }

    @Override // androidx.recyclerview.widget.J
    public final View r(int i6) {
        int iW = w();
        if (iW == 0) {
            return null;
        }
        int iL = i6 - J.L(v(0));
        if (iL >= 0 && iL < iW) {
            View viewV = v(iL);
            if (J.L(viewV) == i6) {
                return viewV;
            }
        }
        return super.r(i6);
    }

    @Override // androidx.recyclerview.widget.J
    public K s() {
        return new K(-2, -2);
    }

    public LinearLayoutManager(Context context, AttributeSet attributeSet, int i6, int i7) {
        this.f12864p = 1;
        this.f12868t = false;
        this.f12869u = false;
        this.f12870v = false;
        this.f12871w = true;
        this.f12872x = -1;
        this.f12873y = Integer.MIN_VALUE;
        this.f12874z = null;
        this.f12860A = new C1168s();
        this.f12861B = new C1169t();
        this.f12862C = 2;
        this.f12863D = new int[2];
        I iM = J.M(context, attributeSet, i6, i7);
        j1(iM.f12838a);
        boolean z6 = iM.f12840c;
        b(null);
        if (z6 != this.f12868t) {
            this.f12868t = z6;
            y0();
        }
        k1(iM.f12841d);
    }

    @Override // androidx.recyclerview.widget.J
    public final void X(RecyclerView recyclerView) {
    }
}
