package androidx.leanback.widget;

import N1.C0203d0;
import N1.C0224z;
import android.content.Context;
import android.graphics.Rect;
import android.media.AudioManager;
import android.os.Bundle;
import android.os.Parcelable;
import android.util.AttributeSet;
import android.util.Log;
import android.util.SparseArray;
import android.util.SparseIntArray;
import android.view.FocusFinder;
import android.view.Gravity;
import android.view.View;
import android.view.ViewGroup;
import android.view.accessibility.AccessibilityEvent;
import androidx.datastore.preferences.protobuf.C0432j;
import androidx.recyclerview.widget.RecyclerView;
import d5.AbstractC0844a;
import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;

/* JADX INFO: loaded from: classes.dex */
public final class GridLayoutManager extends androidx.recyclerview.widget.a {

    /* JADX INFO: renamed from: y0, reason: collision with root package name */
    public static final Rect f8383y0 = new Rect();

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

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

    /* JADX INFO: renamed from: G, reason: collision with root package name */
    public int f8386G;
    public AbstractC0469i H;

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

    /* JADX INFO: renamed from: J, reason: collision with root package name */
    public N1.M f8388J;

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

    /* JADX INFO: renamed from: L, reason: collision with root package name */
    public N1.p0 f8390L;

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

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

    /* JADX INFO: renamed from: O, reason: collision with root package name */
    public final SparseIntArray f8393O;

    /* JADX INFO: renamed from: P, reason: collision with root package name */
    public int[] f8394P;

    /* JADX INFO: renamed from: Q, reason: collision with root package name */
    public AudioManager f8395Q;

    /* JADX INFO: renamed from: R, reason: collision with root package name */
    public N1.i0 f8396R;

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

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

    /* JADX INFO: renamed from: U, reason: collision with root package name */
    public ArrayList f8399U;

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

    /* JADX INFO: renamed from: W, reason: collision with root package name */
    public int f8401W;
    public AbstractC0489t X;

    /* JADX INFO: renamed from: Y, reason: collision with root package name */
    public C0491v f8402Y;

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

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

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

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

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

    /* JADX INFO: renamed from: e0, reason: collision with root package name */
    public int[] f8408e0;

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

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

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

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

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

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

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

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

    /* JADX INFO: renamed from: n0, reason: collision with root package name */
    public r f8417n0;

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

    /* JADX INFO: renamed from: p0, reason: collision with root package name */
    public final C2.a f8419p0;
    public final A1.y q0;

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

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

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

    /* JADX INFO: renamed from: u0, reason: collision with root package name */
    public final Q0 f8423u0;

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

    /* JADX INFO: renamed from: w0, reason: collision with root package name */
    public final M4.k f8425w0;

    /* JADX INFO: renamed from: x0, reason: collision with root package name */
    public final P.g f8426x0;

    public GridLayoutManager() {
        this(null);
    }

    public static int f1(View view) {
        C0490u c0490u;
        if (view == null || (c0490u = (C0490u) view.getLayoutParams()) == null || c0490u.f4520q.j()) {
            return -1;
        }
        return c0490u.f4520q.c();
    }

    public static int g1(View view) {
        C0490u c0490u = (C0490u) view.getLayoutParams();
        return androidx.recyclerview.widget.a.O(view) + ((ViewGroup.MarginLayoutParams) c0490u).topMargin + ((ViewGroup.MarginLayoutParams) c0490u).bottomMargin;
    }

    public static int h1(View view) {
        C0490u c0490u = (C0490u) view.getLayoutParams();
        return androidx.recyclerview.widget.a.P(view) + ((ViewGroup.MarginLayoutParams) c0490u).leftMargin + ((ViewGroup.MarginLayoutParams) c0490u).rightMargin;
    }

    @Override // androidx.recyclerview.widget.a
    public final void A0(Parcelable parcelable) {
        if (parcelable instanceof C0493x) {
            C0493x c0493x = (C0493x) parcelable;
            this.f8401W = c0493x.f8729q;
            this.f8403Z = 0;
            Bundle bundle = c0493x.f8730r;
            Q0 q0 = this.f8423u0;
            N1.B0 b02 = (N1.B0) q0.f8514s;
            if (b02 != null && bundle != null) {
                b02.r(-1);
                for (String str : bundle.keySet()) {
                    ((N1.B0) q0.f8514s).m(str, bundle.getSparseParcelableArray(str));
                }
            }
            this.f8397S |= 256;
            M0();
        }
    }

    /* JADX WARN: Removed duplicated region for block: B:20:0x0031 A[PHI: r0
      0x0031: PHI (r0v9 int) = (r0v8 int), (r0v12 int) binds: [B:19:0x002f, B:12:0x001d] A[DONT_GENERATE, DONT_INLINE]] */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public final int A1(int i) {
        int i5;
        int i8 = this.f8397S;
        if ((i8 & 64) == 0 && (i8 & 3) != 1) {
            C2.a aVar = this.f8419p0;
            if (i > 0) {
                R0 r02 = (R0) aVar.f1159t;
                if (r02.f8515a != Integer.MAX_VALUE && i > (i5 = r02.f8517c)) {
                    i = i5;
                }
            } else if (i < 0) {
                R0 r03 = (R0) aVar.f1159t;
                if (r03.f8516b != Integer.MIN_VALUE && i < (i5 = r03.f8518d)) {
                }
            }
        }
        if (i == 0) {
            return 0;
        }
        int i9 = -i;
        int I7 = I();
        if (this.f8387I == 1) {
            for (int i10 = 0; i10 < I7; i10++) {
                H(i10).offsetTopAndBottom(i9);
            }
        } else {
            for (int i11 = 0; i11 < I7; i11++) {
                H(i11).offsetLeftAndRight(i9);
            }
        }
        if ((this.f8397S & 3) == 1) {
            M1();
            return i;
        }
        int I8 = I();
        if ((this.f8397S & 262144) == 0 ? i >= 0 : i <= 0) {
            c1();
        } else {
            t1();
        }
        boolean z8 = I() > I8;
        int I9 = I();
        if ((262144 & this.f8397S) == 0 ? i >= 0 : i <= 0) {
            y1();
        } else {
            x1();
        }
        if (z8 | (I() < I9)) {
            L1();
        }
        this.H.invalidate();
        M1();
        return i;
    }

    /* JADX WARN: Removed duplicated region for block: B:17:0x0054  */
    @Override // androidx.recyclerview.widget.a
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public final Parcelable B0() {
        Bundle bundle;
        int i;
        C0493x c0493x = new C0493x();
        c0493x.f8730r = Bundle.EMPTY;
        c0493x.f8729q = this.f8401W;
        Q0 q0 = this.f8423u0;
        N1.B0 b02 = (N1.B0) q0.f8514s;
        if (b02 != null) {
            synchronized (((d3.E) b02.f4422g)) {
                i = b02.f4418c;
            }
            if (i == 0) {
                bundle = null;
            } else {
                LinkedHashMap linkedHashMapQ = ((N1.B0) q0.f8514s).q();
                bundle = new Bundle();
                for (Map.Entry entry : linkedHashMapQ.entrySet()) {
                    bundle.putSparseParcelableArray((String) entry.getKey(), (SparseArray) entry.getValue());
                }
            }
        }
        int I7 = I();
        for (int i5 = 0; i5 < I7; i5++) {
            View viewH = H(i5);
            int iF1 = f1(viewH);
            if (iF1 != -1 && q0.f8512q != 0) {
                String string = Integer.toString(iF1);
                SparseArray<Parcelable> sparseArray = new SparseArray<>();
                viewH.saveHierarchyState(sparseArray);
                if (bundle == null) {
                    bundle = new Bundle();
                }
                bundle.putSparseParcelableArray(string, sparseArray);
            }
        }
        c0493x.f8730r = bundle;
        return c0493x;
    }

    public final int B1(int i) {
        int i5 = 0;
        if (i == 0) {
            return 0;
        }
        int i8 = -i;
        int I7 = I();
        if (this.f8387I == 0) {
            while (i5 < I7) {
                H(i5).offsetTopAndBottom(i8);
                i5++;
            }
        } else {
            while (i5 < I7) {
                H(i5).offsetLeftAndRight(i8);
                i5++;
            }
        }
        this.f8405b0 += i;
        N1();
        this.H.invalidate();
        return i;
    }

    public final void C1(int i, boolean z8) {
        View viewD = D(i);
        boolean zB0 = b0();
        if (!zB0 && !this.H.isLayoutRequested() && viewD != null && f1(viewD) == i) {
            this.f8397S |= 32;
            E1(viewD, viewD.findFocus(), z8, 0, 0);
            this.f8397S &= -33;
            return;
        }
        int i5 = this.f8397S;
        if ((i5 & 512) == 0 || (i5 & 64) != 0) {
            this.f8401W = i;
            this.f8403Z = Integer.MIN_VALUE;
            return;
        }
        if (z8 && !this.H.isLayoutRequested()) {
            this.f8401W = i;
            this.f8403Z = Integer.MIN_VALUE;
            if (this.f8417n0 == null) {
                Log.w("GridLayoutManager:" + this.H.getId(), "setSelectionSmooth should not be called before first layout pass");
                return;
            }
            C0488s c0488s = new C0488s(this);
            c0488s.f4460a = i;
            a1(c0488s);
            int i8 = c0488s.f4460a;
            if (i8 != this.f8401W) {
                this.f8401W = i8;
                return;
            }
            return;
        }
        if (zB0) {
            AbstractC0489t abstractC0489t = this.X;
            if (abstractC0489t != null) {
                abstractC0489t.f8715q = true;
            }
            this.H.w0();
        }
        if (!this.H.isLayoutRequested() && viewD != null && f1(viewD) == i) {
            this.f8397S |= 32;
            E1(viewD, viewD.findFocus(), z8, 0, 0);
            this.f8397S &= -33;
        } else {
            this.f8401W = i;
            this.f8403Z = Integer.MIN_VALUE;
            this.f8397S |= 256;
            M0();
        }
    }

    public final void D1(View view, View view2, boolean z8) {
        E1(view, view2, z8, 0, 0);
    }

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

    /* JADX WARN: Removed duplicated region for block: B:20:0x003c  */
    /* JADX WARN: Removed duplicated region for block: B:23:0x0046  */
    /* JADX WARN: Removed duplicated region for block: B:28:0x004f  */
    /* JADX WARN: Removed duplicated region for block: B:33:0x005b  */
    /* JADX WARN: Removed duplicated region for block: B:42:0x0075  */
    /* JADX WARN: Type inference fix 'apply assigned field type' failed
    java.lang.UnsupportedOperationException: ArgType.getObject(), call class: class jadx.core.dex.instructions.args.ArgType$UnknownArg
    	at jadx.core.dex.instructions.args.ArgType.getObject(ArgType.java:593)
    	at jadx.core.dex.attributes.nodes.ClassTypeVarsAttr.getTypeVarsMapFor(ClassTypeVarsAttr.java:35)
    	at jadx.core.dex.nodes.utils.TypeUtils.replaceClassGenerics(TypeUtils.java:177)
    	at jadx.core.dex.visitors.typeinference.FixTypesVisitor.insertExplicitUseCast(FixTypesVisitor.java:397)
    	at jadx.core.dex.visitors.typeinference.FixTypesVisitor.tryFieldTypeWithNewCasts(FixTypesVisitor.java:359)
    	at jadx.core.dex.visitors.typeinference.FixTypesVisitor.applyFieldType(FixTypesVisitor.java:309)
    	at jadx.core.dex.visitors.typeinference.FixTypesVisitor.visit(FixTypesVisitor.java:94)
     */
    @Override // androidx.recyclerview.widget.a
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public final boolean E0(N1.i0 i0Var, N1.p0 p0Var, int i, Bundle bundle) {
        boolean z8;
        if ((this.f8397S & 131072) != 0) {
            z1(i0Var, p0Var);
            boolean z9 = (this.f8397S & 262144) != 0;
            if (this.f8387I == 0) {
                if (i == N.c.f4361m.a()) {
                    i = z9 ? 4096 : 8192;
                } else if (i == N.c.f4363o.a()) {
                    if (z9) {
                    }
                }
                int i5 = this.f8401W;
                z8 = i5 != 0 && i == 8192;
                boolean z10 = i5 != p0Var.b() - 1 && i == 4096;
                if (!z8 || z10) {
                    AccessibilityEvent accessibilityEventObtain = AccessibilityEvent.obtain(4096);
                    this.H.onInitializeAccessibilityEvent(accessibilityEventObtain);
                    AbstractC0469i abstractC0469i = this.H;
                    abstractC0469i.requestSendAccessibilityEvent(abstractC0469i, accessibilityEventObtain);
                } else if (i == 4096) {
                    u1(true);
                    w1(1, false);
                } else if (i == 8192) {
                    u1(false);
                    w1(-1, false);
                }
                r1();
            } else {
                if (i != N.c.f4360l.a()) {
                    if (i == N.c.f4362n.a()) {
                    }
                }
                int i52 = this.f8401W;
                if (i52 != 0) {
                    if (i52 != p0Var.b() - 1) {
                        if (z8) {
                            AccessibilityEvent accessibilityEventObtain2 = AccessibilityEvent.obtain(4096);
                            this.H.onInitializeAccessibilityEvent(accessibilityEventObtain2);
                            AbstractC0469i abstractC0469i2 = this.H;
                            abstractC0469i2.requestSendAccessibilityEvent(abstractC0469i2, accessibilityEventObtain2);
                            r1();
                        }
                    }
                }
            }
        }
        return true;
    }

    public final void E1(View view, View view2, boolean z8, int i, int i5) {
        if ((this.f8397S & 64) != 0) {
            return;
        }
        int iF1 = f1(view);
        if (view != null && view2 != null) {
            ((C0490u) view.getLayoutParams()).getClass();
        }
        if (iF1 != this.f8401W) {
            this.f8401W = iF1;
            this.f8403Z = 0;
            if ((this.f8397S & 3) != 1) {
                d1();
            }
            if (this.H.Q()) {
                this.H.invalidate();
            }
        }
        if (view == null) {
            return;
        }
        if (!view.hasFocus() && this.H.hasFocus()) {
            view.requestFocus();
        }
        if ((this.f8397S & 131072) == 0 && z8) {
            return;
        }
        int[] iArr = f8384z0;
        if (!l1(view, view2, iArr) && i == 0 && i5 == 0) {
            return;
        }
        int i8 = iArr[0] + i;
        int i9 = iArr[1] + i5;
        if ((this.f8397S & 3) == 1) {
            A1(i8);
            B1(i9);
            return;
        }
        if (this.f8387I != 0) {
            i9 = i8;
            i8 = i9;
        }
        if (z8) {
            this.H.p0(i8, i9, false);
        } else {
            this.H.scrollBy(i8, i9);
            e1();
        }
    }

    @Override // androidx.recyclerview.widget.a
    public final C0203d0 F(Context context, AttributeSet attributeSet) {
        return new C0490u(context, attributeSet);
    }

    public final void F1(int i) {
        if (i == 0 || i == 1) {
            this.f8387I = i;
            this.f8388J = N1.M.b(this, i);
            C2.a aVar = this.f8419p0;
            aVar.getClass();
            R0 r02 = (R0) aVar.f1158s;
            R0 r03 = (R0) aVar.f1157r;
            if (i == 0) {
                aVar.f1159t = r03;
                aVar.f1160u = r02;
            } else {
                aVar.f1159t = r02;
                aVar.f1160u = r03;
            }
            A1.y yVar = this.q0;
            yVar.getClass();
            if (i == 0) {
                yVar.f365t = (C) yVar.f364s;
            } else {
                yVar.f365t = (C) yVar.f363r;
            }
            this.f8397S |= 256;
        }
    }

    @Override // androidx.recyclerview.widget.a
    public final C0203d0 G(ViewGroup.LayoutParams layoutParams) {
        return layoutParams instanceof C0490u ? new C0490u((C0490u) layoutParams) : layoutParams instanceof C0203d0 ? new C0490u((C0203d0) layoutParams) : layoutParams instanceof ViewGroup.MarginLayoutParams ? new C0490u((ViewGroup.MarginLayoutParams) layoutParams) : new C0490u(layoutParams);
    }

    @Override // androidx.recyclerview.widget.a
    public final void G0(N1.i0 i0Var) {
        for (int I7 = I() - 1; I7 >= 0; I7--) {
            J0(I7, i0Var);
        }
    }

    public final void G1(int i) {
        if (i < 0 && i != -2) {
            throw new IllegalArgumentException(AbstractC0844a.j("Invalid row height: ", i));
        }
        this.f8406c0 = i;
    }

    public final void H1(int i, boolean z8) {
        if (this.f8401W == i || i == -1) {
            return;
        }
        C1(i, z8);
    }

    public final void I1() {
        int I7 = I();
        for (int i = 0; i < I7; i++) {
            J1(H(i));
        }
    }

    public final void J1(View view) {
        C0490u c0490u = (C0490u) view.getLayoutParams();
        c0490u.getClass();
        A1.y yVar = this.q0;
        C c3 = (C) yVar.f364s;
        c0490u.f8721y = D.a(view, c3, c3.f8356e);
        C c8 = (C) yVar.f363r;
        c0490u.f8722z = D.a(view, c8, c8.f8356e);
    }

    @Override // androidx.recyclerview.widget.a
    public final int K(N1.i0 i0Var, N1.p0 p0Var) {
        r rVar;
        return (this.f8387I != 1 || (rVar = this.f8417n0) == null) ? super.K(i0Var, p0Var) : rVar.f8705e;
    }

    @Override // androidx.recyclerview.widget.a
    public final boolean K0(RecyclerView recyclerView, View view, Rect rect, boolean z8) {
        return false;
    }

    public final void K1() {
        if (I() <= 0) {
            this.f8391M = 0;
        } else {
            this.f8391M = this.f8417n0.f8706f - ((C0490u) H(0).getLayoutParams()).f4520q.d();
        }
    }

    @Override // androidx.recyclerview.widget.a
    public final int L(View view) {
        return super.L(view) - ((C0490u) view.getLayoutParams()).f8720x;
    }

    public final void L1() {
        int i = (this.f8397S & (-1025)) | (v1(false) ? 1024 : 0);
        this.f8397S = i;
        if ((i & 1024) != 0) {
            AbstractC0469i abstractC0469i = this.H;
            Field field = M.J.f4065a;
            abstractC0469i.postOnAnimation(this.f8425w0);
        }
    }

    @Override // androidx.recyclerview.widget.a
    public final void M(View view, Rect rect) {
        super.M(view, rect);
        C0490u c0490u = (C0490u) view.getLayoutParams();
        rect.left += c0490u.f8717u;
        rect.top += c0490u.f8718v;
        rect.right -= c0490u.f8719w;
        rect.bottom -= c0490u.f8720x;
    }

    public final void M1() {
        int iB;
        int i;
        int i5;
        int i8;
        int i9;
        int i10;
        int top;
        int i11;
        int top2;
        int i12;
        if (this.f8390L.b() == 0) {
            return;
        }
        if ((this.f8397S & 262144) == 0) {
            i = this.f8417n0.f8707g;
            int iB2 = this.f8390L.b() - 1;
            i5 = this.f8417n0.f8706f;
            i8 = iB2;
            iB = 0;
        } else {
            r rVar = this.f8417n0;
            int i13 = rVar.f8706f;
            int i14 = rVar.f8707g;
            iB = this.f8390L.b() - 1;
            i = i13;
            i5 = i14;
            i8 = 0;
        }
        if (i < 0 || i5 < 0) {
            return;
        }
        boolean z8 = i == i8;
        boolean z9 = i5 == iB;
        int i15 = Integer.MIN_VALUE;
        int iG = Integer.MAX_VALUE;
        C2.a aVar = this.f8419p0;
        if (!z8) {
            R0 r02 = (R0) aVar.f1159t;
            if (r02.f8515a == Integer.MAX_VALUE && !z9 && r02.f8516b == Integer.MIN_VALUE) {
                return;
            }
        }
        int[] iArr = f8384z0;
        if (z8) {
            iG = this.f8417n0.g(true, iArr);
            View viewD = D(iArr[1]);
            if (this.f8387I == 0) {
                C0490u c0490u = (C0490u) viewD.getLayoutParams();
                c0490u.getClass();
                top2 = viewD.getLeft() + c0490u.f8717u;
                i12 = c0490u.f8721y;
            } else {
                C0490u c0490u2 = (C0490u) viewD.getLayoutParams();
                c0490u2.getClass();
                top2 = viewD.getTop() + c0490u2.f8718v;
                i12 = c0490u2.f8722z;
            }
            i9 = top2 + i12;
            ((C0490u) viewD.getLayoutParams()).getClass();
        } else {
            i9 = Integer.MAX_VALUE;
        }
        if (z9) {
            i15 = this.f8417n0.i(false, iArr);
            View viewD2 = D(iArr[1]);
            if (this.f8387I == 0) {
                C0490u c0490u3 = (C0490u) viewD2.getLayoutParams();
                c0490u3.getClass();
                top = viewD2.getLeft() + c0490u3.f8717u;
                i11 = c0490u3.f8721y;
            } else {
                C0490u c0490u4 = (C0490u) viewD2.getLayoutParams();
                c0490u4.getClass();
                top = viewD2.getTop() + c0490u4.f8718v;
                i11 = c0490u4.f8722z;
            }
            i10 = top + i11;
        } else {
            i10 = Integer.MIN_VALUE;
        }
        ((R0) aVar.f1159t).c(i15, iG, i10, i9);
    }

    @Override // androidx.recyclerview.widget.a
    public final int N(View view) {
        return super.N(view) + ((C0490u) view.getLayoutParams()).f8717u;
    }

    public final void N1() {
        R0 r02 = (R0) this.f8419p0.f1160u;
        int i = r02.f8523j - this.f8405b0;
        int iM1 = m1() + i;
        r02.c(i, iM1, i, iM1);
    }

    @Override // androidx.recyclerview.widget.a
    public final int O0(int i, N1.i0 i0Var, N1.p0 p0Var) {
        if ((this.f8397S & 512) == 0 || this.f8417n0 == null) {
            return 0;
        }
        z1(i0Var, p0Var);
        this.f8397S = (this.f8397S & (-4)) | 2;
        int iA1 = this.f8387I == 0 ? A1(i) : B1(i);
        r1();
        this.f8397S &= -4;
        return iA1;
    }

    @Override // androidx.recyclerview.widget.a
    public final void P0(int i) {
        H1(i, false);
    }

    @Override // androidx.recyclerview.widget.a
    public final int Q(View view) {
        return super.Q(view) - ((C0490u) view.getLayoutParams()).f8719w;
    }

    @Override // androidx.recyclerview.widget.a
    public final int Q0(int i, N1.i0 i0Var, N1.p0 p0Var) {
        int i5 = this.f8397S;
        if ((i5 & 512) == 0 || this.f8417n0 == null) {
            return 0;
        }
        this.f8397S = (i5 & (-4)) | 2;
        z1(i0Var, p0Var);
        int iA1 = this.f8387I == 1 ? A1(i) : B1(i);
        r1();
        this.f8397S &= -4;
        return iA1;
    }

    @Override // androidx.recyclerview.widget.a
    public final int R(View view) {
        return super.R(view) + ((C0490u) view.getLayoutParams()).f8718v;
    }

    @Override // androidx.recyclerview.widget.a
    public final int V(N1.i0 i0Var, N1.p0 p0Var) {
        r rVar;
        return (this.f8387I != 0 || (rVar = this.f8417n0) == null) ? super.V(i0Var, p0Var) : rVar.f8705e;
    }

    @Override // androidx.recyclerview.widget.a
    public final void Z0(RecyclerView recyclerView, N1.p0 p0Var, int i) {
        H1(i, true);
    }

    @Override // androidx.recyclerview.widget.a
    public final void a1(N1.H h8) {
        AbstractC0489t abstractC0489t = this.X;
        if (abstractC0489t != null) {
            abstractC0489t.f8715q = true;
        }
        super.a1(h8);
        if (!h8.f4464e || !(h8 instanceof AbstractC0489t)) {
            this.X = null;
            this.f8402Y = null;
            return;
        }
        AbstractC0489t abstractC0489t2 = (AbstractC0489t) h8;
        this.X = abstractC0489t2;
        if (abstractC0489t2 instanceof C0491v) {
            this.f8402Y = (C0491v) abstractC0489t2;
        } else {
            this.f8402Y = null;
        }
    }

    public final void c1() {
        this.f8417n0.b((this.f8397S & 262144) != 0 ? (-this.f8421s0) - this.f8392N : this.f8420r0 + this.f8421s0 + this.f8392N, false);
    }

    public final void d1() {
        ArrayList arrayList;
        if (this.f8398T != null || ((arrayList = this.f8399U) != null && arrayList.size() > 0)) {
            int i = this.f8401W;
            View viewD = i == -1 ? null : D(i);
            if (viewD != null) {
                N1.t0 t0VarM = this.H.M(viewD);
                P p3 = this.f8398T;
                if (p3 != null) {
                    p3.c(viewD);
                }
                AbstractC0469i abstractC0469i = this.H;
                int i5 = this.f8401W;
                ArrayList arrayList2 = this.f8399U;
                if (arrayList2 != null) {
                    for (int size = arrayList2.size() - 1; size >= 0; size--) {
                        ((Q) this.f8399U.get(size)).a(abstractC0469i, t0VarM, i5);
                    }
                }
            } else {
                P p4 = this.f8398T;
                if (p4 != null) {
                    p4.c(null);
                }
                AbstractC0469i abstractC0469i2 = this.H;
                ArrayList arrayList3 = this.f8399U;
                if (arrayList3 != null) {
                    for (int size2 = arrayList3.size() - 1; size2 >= 0; size2--) {
                        ((Q) this.f8399U.get(size2)).a(abstractC0469i2, null, -1);
                    }
                }
            }
            if ((this.f8397S & 3) == 1 || this.H.isLayoutRequested()) {
                return;
            }
            int I7 = I();
            for (int i8 = 0; i8 < I7; i8++) {
                if (H(i8).isLayoutRequested()) {
                    AbstractC0469i abstractC0469i3 = this.H;
                    Field field = M.J.f4065a;
                    abstractC0469i3.postOnAnimation(this.f8425w0);
                    return;
                }
            }
        }
    }

    public final void e1() {
        ArrayList arrayList = this.f8399U;
        if (arrayList == null || arrayList.size() <= 0) {
            return;
        }
        int i = this.f8401W;
        View viewD = i == -1 ? null : D(i);
        if (viewD != null) {
            this.H.M(viewD);
            ArrayList arrayList2 = this.f8399U;
            if (arrayList2 == null) {
                return;
            }
            for (int size = arrayList2.size() - 1; size >= 0; size--) {
                ((Q) this.f8399U.get(size)).getClass();
            }
            return;
        }
        P p3 = this.f8398T;
        if (p3 != null) {
            p3.c(null);
        }
        ArrayList arrayList3 = this.f8399U;
        if (arrayList3 == null) {
            return;
        }
        for (int size2 = arrayList3.size() - 1; size2 >= 0; size2--) {
            ((Q) this.f8399U.get(size2)).getClass();
        }
    }

    @Override // androidx.recyclerview.widget.a
    public final void g0(N1.T t6, N1.T t8) {
        if (t6 != null) {
            this.f8417n0 = null;
            this.f8408e0 = null;
            this.f8397S &= -1025;
            this.f8401W = -1;
            this.f8403Z = 0;
            N1.B0 b02 = (N1.B0) this.f8423u0.f8514s;
            if (b02 != null) {
                b02.r(-1);
            }
        }
        if (t8 instanceof G) {
            this.f8424v0 = (G) t8;
        } else {
            this.f8424v0 = null;
        }
    }

    /* JADX WARN: Removed duplicated region for block: B:26:0x0053  */
    /* JADX WARN: Removed duplicated region for block: B:27:0x0055  */
    /* JADX WARN: Removed duplicated region for block: B:29:0x005b  */
    /* JADX WARN: Removed duplicated region for block: B:43:0x007a A[ADDED_TO_REGION] */
    /* JADX WARN: Removed duplicated region for block: B:45:0x0083  */
    /* JADX WARN: Removed duplicated region for block: B:51:0x008f  */
    /* JADX WARN: Removed duplicated region for block: B:53:0x0092  */
    /* JADX WARN: Removed duplicated region for block: B:54:0x009b  */
    /* JADX WARN: Removed duplicated region for block: B:56:0x009e  */
    /* JADX WARN: Removed duplicated region for block: B:59:0x00ab  */
    /* JADX WARN: Removed duplicated region for block: B:62:0x00b1  */
    /* JADX WARN: Removed duplicated region for block: B:64:0x00b4  */
    /* JADX WARN: Removed duplicated region for block: B:65:0x00b6  */
    @Override // androidx.recyclerview.widget.a
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public final boolean h0(RecyclerView recyclerView, ArrayList arrayList, int i, int i5) {
        int i8;
        int iF1;
        View viewD;
        char c3;
        char c8;
        int i9;
        int I7;
        boolean z8;
        char c9;
        char c10;
        AbstractC0469i abstractC0469i;
        View viewC;
        boolean z9 = true;
        if ((this.f8397S & 32768) == 0) {
            if (!recyclerView.hasFocus()) {
                int size = arrayList.size();
                if (this.f8418o0 != 0) {
                    R0 r02 = (R0) this.f8419p0.f1159t;
                    int i10 = r02.f8523j;
                    int i11 = ((r02.i - i10) - r02.f8524k) + i10;
                    int I8 = I();
                    for (int i12 = 0; i12 < I8; i12++) {
                        View viewH = H(i12);
                        if (viewH.getVisibility() == 0 && this.f8388J.g(viewH) >= i10 && this.f8388J.d(viewH) <= i11) {
                            viewH.addFocusables(arrayList, i, i5);
                        }
                    }
                    if (arrayList.size() == size) {
                        int I9 = I();
                        for (int i13 = 0; i13 < I9; i13++) {
                            View viewH2 = H(i13);
                            if (viewH2.getVisibility() == 0) {
                                viewH2.addFocusables(arrayList, i, i5);
                            }
                        }
                    }
                } else {
                    View viewD2 = D(this.f8401W);
                    if (viewD2 != null) {
                        viewD2.addFocusables(arrayList, i, i5);
                    }
                }
                if (arrayList.size() != size || !recyclerView.isFocusable()) {
                    return true;
                }
                arrayList.add(recyclerView);
                return true;
            }
            if (this.f8402Y == null) {
                int iI1 = i1(i);
                View viewFindFocus = recyclerView.findFocus();
                if (viewFindFocus == null || (abstractC0469i = this.H) == null || viewFindFocus == abstractC0469i || (viewC = C(viewFindFocus)) == null) {
                    i8 = -1;
                    iF1 = f1(H(i8));
                    viewD = iF1 != -1 ? null : D(iF1);
                    if (viewD != null) {
                        viewD.addFocusables(arrayList, i, i5);
                    }
                    if (this.f8417n0 != null && I() != 0) {
                        c3 = 2;
                        c8 = 3;
                        if ((iI1 == 3 && iI1 != 2) || this.f8417n0.f8705e > 1) {
                            r rVar = this.f8417n0;
                            int i14 = (rVar == null || viewD == null) ? -1 : rVar.k(iF1).f7097q;
                            int size2 = arrayList.size();
                            i9 = (iI1 != 1 || iI1 == 3) ? 1 : -1;
                            int I10 = i9 <= 0 ? I() - 1 : 0;
                            I7 = i8 != -1 ? i9 > 0 ? 0 : I() - 1 : i8 + i9;
                            while (true) {
                                if (i9 > 0) {
                                    if (I7 < I10) {
                                        break;
                                    }
                                } else {
                                    if (I7 > I10) {
                                        break;
                                    }
                                    View viewH3 = H(I7);
                                    if (viewH3.getVisibility() != 0 || !viewH3.hasFocusable()) {
                                        z8 = z9;
                                        c9 = c3;
                                        c10 = c8;
                                    } else if (viewD == null) {
                                        viewH3.addFocusables(arrayList, i, i5);
                                        if (arrayList.size() > size2) {
                                            break;
                                        }
                                        z8 = z9;
                                        c9 = c3;
                                        c10 = c8;
                                    } else {
                                        int iF12 = f1(H(I7));
                                        W2.j jVarK = this.f8417n0.k(iF12);
                                        if (jVarK == null) {
                                            z8 = z9;
                                            c9 = 2;
                                            c10 = 3;
                                        } else {
                                            int i15 = jVarK.f7097q;
                                            if (iI1 == z9) {
                                                if (i15 == i14 && iF12 > iF1) {
                                                    viewH3.addFocusables(arrayList, i, i5);
                                                    if (arrayList.size() > size2) {
                                                        break;
                                                    }
                                                }
                                                z8 = z9;
                                                c9 = 2;
                                                c10 = 3;
                                            } else if (iI1 == 0) {
                                                if (i15 == i14 && iF12 < iF1) {
                                                    viewH3.addFocusables(arrayList, i, i5);
                                                    if (arrayList.size() > size2) {
                                                        break;
                                                    }
                                                }
                                                z8 = z9;
                                                c9 = 2;
                                                c10 = 3;
                                            } else {
                                                c10 = 3;
                                                if (iI1 == 3) {
                                                    if (i15 != i14) {
                                                        if (i15 < i14) {
                                                            break;
                                                        }
                                                        viewH3.addFocusables(arrayList, i, i5);
                                                    }
                                                    z8 = z9;
                                                    c9 = 2;
                                                } else {
                                                    z8 = z9;
                                                    c9 = 2;
                                                    if (iI1 == 2 && i15 != i14) {
                                                        if (i15 > i14) {
                                                            return z8;
                                                        }
                                                        viewH3.addFocusables(arrayList, i, i5);
                                                    }
                                                }
                                            }
                                        }
                                    }
                                    I7 += i9;
                                    c8 = c10;
                                    c3 = c9;
                                    z9 = z8;
                                }
                            }
                        }
                    }
                } else {
                    int I11 = I();
                    i8 = 0;
                    while (i8 < I11) {
                        if (H(i8) == viewC) {
                            break;
                        }
                        i8++;
                    }
                    i8 = -1;
                    iF1 = f1(H(i8));
                    if (iF1 != -1) {
                    }
                    if (viewD != null) {
                    }
                    if (this.f8417n0 != null) {
                        c3 = 2;
                        c8 = 3;
                        if (iI1 == 3) {
                            r rVar2 = this.f8417n0;
                            if (rVar2 == null) {
                                int size22 = arrayList.size();
                                if (iI1 != 1) {
                                    if (i9 <= 0) {
                                    }
                                    I7 = i8 != -1 ? i9 > 0 ? 0 : I() - 1 : i8 + i9;
                                    while (true) {
                                        if (i9 > 0) {
                                        }
                                        I7 += i9;
                                        c8 = c10;
                                        c3 = c9;
                                        z9 = z8;
                                    }
                                }
                            }
                        } else {
                            r rVar22 = this.f8417n0;
                            if (rVar22 == null) {
                            }
                        }
                    }
                }
            }
        }
        return z9;
    }

    public final int i1(int i) {
        int i5 = this.f8387I;
        if (i5 != 0) {
            if (i5 == 1) {
                if (i == 17) {
                    return (this.f8397S & 524288) == 0 ? 2 : 3;
                }
                if (i == 33) {
                    return 0;
                }
                if (i == 66) {
                    return (this.f8397S & 524288) == 0 ? 3 : 2;
                }
                if (i == 130) {
                    return 1;
                }
            }
        }
        if (i != 17) {
            if (i == 33) {
                return 2;
            }
            if (i != 66) {
                return i != 130 ? 17 : 3;
            }
            if ((this.f8397S & 262144) != 0) {
                return 0;
            }
        } else if ((this.f8397S & 262144) == 0) {
            return 0;
        }
        return 1;
    }

    public final int j1(int i) {
        int i5 = this.f8407d0;
        if (i5 != 0) {
            return i5;
        }
        int[] iArr = this.f8408e0;
        if (iArr == null) {
            return 0;
        }
        return iArr[i];
    }

    public final int k1(int i) {
        int iJ1 = 0;
        if ((this.f8397S & 524288) != 0) {
            for (int i5 = this.f8415l0 - 1; i5 > i; i5--) {
                iJ1 += j1(i5) + this.f8413j0;
            }
            return iJ1;
        }
        int iJ12 = 0;
        while (iJ1 < i) {
            iJ12 += j1(iJ1) + this.f8413j0;
            iJ1++;
        }
        return iJ12;
    }

    /* JADX WARN: Removed duplicated region for block: B:71:0x0154  */
    /* JADX WARN: Removed duplicated region for block: B:72:0x0156  */
    /* JADX WARN: Removed duplicated region for block: B:76:0x015d  */
    /* JADX WARN: Removed duplicated region for block: B:78:0x0171  */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public final boolean l1(View view, View view2, int[] iArr) {
        View viewD;
        int i;
        int iD;
        int left;
        int i5;
        int iB;
        int top;
        int i8;
        int left2;
        int i9;
        int i10 = this.f8418o0;
        C2.a aVar = this.f8419p0;
        if (i10 != 1 && i10 != 2) {
            R0 r02 = (R0) aVar.f1159t;
            if (this.f8387I == 0) {
                C0490u c0490u = (C0490u) view.getLayoutParams();
                c0490u.getClass();
                top = view.getLeft() + c0490u.f8717u;
                i8 = c0490u.f8721y;
            } else {
                C0490u c0490u2 = (C0490u) view.getLayoutParams();
                c0490u2.getClass();
                top = view.getTop() + c0490u2.f8718v;
                i8 = c0490u2.f8722z;
            }
            int iB2 = r02.b(top + i8);
            if (view2 != null) {
                ((C0490u) view.getLayoutParams()).getClass();
            }
            if (this.f8387I == 0) {
                C0490u c0490u3 = (C0490u) view.getLayoutParams();
                c0490u3.getClass();
                left2 = view.getTop() + c0490u3.f8718v;
                i9 = c0490u3.f8722z;
            } else {
                C0490u c0490u4 = (C0490u) view.getLayoutParams();
                c0490u4.getClass();
                left2 = view.getLeft() + c0490u4.f8717u;
                i9 = c0490u4.f8721y;
            }
            int iB3 = ((R0) aVar.f1160u).b(left2 + i9);
            if (iB2 == 0 && iB3 == 0) {
                iArr[0] = 0;
                iArr[1] = 0;
                return false;
            }
            iArr[0] = iB2;
            iArr[1] = iB3;
            return true;
        }
        int iF1 = f1(view);
        int iG = this.f8388J.g(view);
        int iD2 = this.f8388J.d(view);
        R0 r03 = (R0) aVar.f1159t;
        int i11 = r03.f8523j;
        int i12 = (r03.i - i11) - r03.f8524k;
        W2.j jVarK = this.f8417n0.k(iF1);
        int i13 = jVarK == null ? -1 : jVarK.f7097q;
        View viewD2 = null;
        if (iG < i11) {
            if (this.f8418o0 == 2) {
                View view3 = view;
                while (true) {
                    r rVar = this.f8417n0;
                    if (!rVar.m(rVar.f8703c ? Integer.MIN_VALUE : Integer.MAX_VALUE, true)) {
                        viewD = null;
                        viewD2 = view3;
                        break;
                    }
                    r rVar2 = this.f8417n0;
                    C0224z c0224z = rVar2.j(rVar2.f8706f, iF1)[i13];
                    View viewD3 = D(c0224z.d(0));
                    if (iD2 - this.f8388J.g(viewD3) <= i12) {
                        view3 = viewD3;
                    } else if (c0224z.e() > 2) {
                        viewD = null;
                        viewD2 = D(c0224z.d(2));
                    } else {
                        viewD = null;
                        viewD2 = viewD3;
                    }
                }
            } else {
                viewD = null;
                viewD2 = view;
            }
        } else if (iD2 <= i12 + i11) {
            viewD = null;
        } else if (this.f8418o0 == 2) {
            while (true) {
                r rVar3 = this.f8417n0;
                C0224z c0224z2 = rVar3.j(iF1, rVar3.f8707g)[i13];
                viewD = D(c0224z2.d(c0224z2.e() - 1));
                if (this.f8388J.d(viewD) - iG > i12) {
                    viewD = null;
                    break;
                }
                if (!this.f8417n0.a()) {
                    break;
                }
            }
            if (viewD == null) {
                viewD2 = view;
            }
        } else {
            viewD = view;
        }
        if (viewD2 != null) {
            iD = this.f8388J.g(viewD2);
        } else {
            if (viewD == null) {
                i = 0;
                if (viewD2 == null) {
                    view = viewD2;
                } else if (viewD != null) {
                    view = viewD;
                }
                if (this.f8387I != 0) {
                    C0490u c0490u5 = (C0490u) view.getLayoutParams();
                    c0490u5.getClass();
                    left = view.getTop() + c0490u5.f8718v;
                    i5 = c0490u5.f8722z;
                } else {
                    C0490u c0490u6 = (C0490u) view.getLayoutParams();
                    c0490u6.getClass();
                    left = view.getLeft() + c0490u6.f8717u;
                    i5 = c0490u6.f8721y;
                }
                iB = ((R0) aVar.f1160u).b(left + i5);
                if (i != 0 && iB == 0) {
                    return false;
                }
                iArr[0] = i;
                iArr[1] = iB;
                return true;
            }
            iD = this.f8388J.d(viewD);
            i11 += i12;
        }
        i = iD - i11;
        if (viewD2 == null) {
        }
        if (this.f8387I != 0) {
        }
        iB = ((R0) aVar.f1160u).b(left + i5);
        if (i != 0) {
        }
        iArr[0] = i;
        iArr[1] = iB;
        return true;
    }

    @Override // androidx.recyclerview.widget.a
    public final void m0(N1.i0 i0Var, N1.p0 p0Var, N.e eVar) {
        z1(i0Var, p0Var);
        int iB = p0Var.b();
        int i = this.f8397S;
        boolean z8 = (262144 & i) != 0;
        if ((i & 2048) == 0 || (iB > 1 && !p1(0))) {
            if (this.f8387I == 0) {
                eVar.b(z8 ? N.c.f4363o : N.c.f4361m);
            } else {
                eVar.b(N.c.f4360l);
            }
            eVar.m();
        }
        if ((this.f8397S & 4096) == 0 || (iB > 1 && !p1(iB - 1))) {
            if (this.f8387I == 0) {
                eVar.b(z8 ? N.c.f4361m : N.c.f4363o);
            } else {
                eVar.b(N.c.f4362n);
            }
            eVar.m();
        }
        eVar.j(K4.c.E(V(i0Var, p0Var), K(i0Var, p0Var), 0));
        eVar.i("android.widget.GridView");
        r1();
    }

    public final int m1() {
        int i = (this.f8397S & 524288) != 0 ? 0 : this.f8415l0 - 1;
        return j1(i) + k1(i);
    }

    @Override // androidx.recyclerview.widget.a
    public final void n0(N1.i0 i0Var, N1.p0 p0Var, View view, N.e eVar) {
        W2.j jVarK;
        ViewGroup.LayoutParams layoutParams = view.getLayoutParams();
        if (this.f8417n0 == null || !(layoutParams instanceof C0490u)) {
            return;
        }
        int iC = ((C0490u) layoutParams).f4520q.c();
        int i = -1;
        if (iC >= 0 && (jVarK = this.f8417n0.k(iC)) != null) {
            i = jVarK.f7097q;
        }
        if (i < 0) {
            return;
        }
        int i5 = iC / this.f8417n0.f8705e;
        if (this.f8387I == 0) {
            eVar.k(K4.c.F(false, i, 1, i5, 1));
        } else {
            eVar.k(K4.c.F(false, i5, 1, i, 1));
        }
    }

    /* JADX WARN: Multi-variable type inference failed */
    public final View n1(int i) {
        View viewD = this.f8396R.d(i);
        C0490u c0490u = (C0490u) viewD.getLayoutParams();
        N1.t0 t0VarM = this.H.M(viewD);
        if (t0VarM instanceof InterfaceC0477m) {
            ((InterfaceC0477m) t0VarM).a();
        }
        G g8 = this.f8424v0;
        if (g8 != null) {
            InterfaceC0477m interfaceC0477m = (InterfaceC0477m) g8.i.get(t0VarM.f4659f);
            if (interfaceC0477m != null) {
                interfaceC0477m.a();
            }
        }
        c0490u.getClass();
        return viewD;
    }

    public final boolean o1() {
        int iS = S();
        return iS == 0 || this.H.H(iS - 1) != null;
    }

    @Override // androidx.recyclerview.widget.a
    public final boolean p() {
        return this.f8387I == 0 || this.f8415l0 > 1;
    }

    @Override // androidx.recyclerview.widget.a
    public final View p0(View view, int i) {
        View viewFindNextFocus;
        View viewFindNextFocus2;
        if ((this.f8397S & 32768) != 0) {
            return view;
        }
        FocusFinder focusFinder = FocusFinder.getInstance();
        if (i == 2 || i == 1) {
            if (q()) {
                viewFindNextFocus = focusFinder.findNextFocus(this.H, view, i == 2 ? 130 : 33);
            } else {
                viewFindNextFocus = null;
            }
            if (p()) {
                viewFindNextFocus2 = focusFinder.findNextFocus(this.H, view, (this.f9115r.getLayoutDirection() == 1) ^ (i == 2) ? 66 : 17);
            } else {
                viewFindNextFocus2 = viewFindNextFocus;
            }
        } else {
            viewFindNextFocus2 = focusFinder.findNextFocus(this.H, view, i);
        }
        if (viewFindNextFocus2 != null) {
            return viewFindNextFocus2;
        }
        if (this.H.getDescendantFocusability() == 393216) {
            return this.H.getParent().focusSearch(view, i);
        }
        int iI1 = i1(i);
        boolean z8 = this.H.getScrollState() != 0;
        if (iI1 == 1) {
            if (z8 || (this.f8397S & 4096) == 0) {
                viewFindNextFocus2 = view;
            }
            if ((this.f8397S & 131072) != 0 && !o1()) {
                u1(true);
                viewFindNextFocus2 = view;
            }
        } else if (iI1 == 0) {
            if (z8 || (this.f8397S & 2048) == 0) {
                viewFindNextFocus2 = view;
            }
            if ((this.f8397S & 131072) != 0 && S() != 0 && this.H.H(0) == null) {
                u1(false);
                viewFindNextFocus2 = view;
            }
        } else if (iI1 == 3) {
        }
        if (viewFindNextFocus2 != null) {
            return viewFindNextFocus2;
        }
        View viewFocusSearch = this.H.getParent().focusSearch(view, i);
        return viewFocusSearch != null ? viewFocusSearch : view != null ? view : this.H;
    }

    public final boolean p1(int i) {
        N1.t0 t0VarH = this.H.H(i);
        if (t0VarH == null) {
            return false;
        }
        View view = t0VarH.f4654a;
        return view.getLeft() >= 0 && view.getRight() <= this.H.getWidth() && view.getTop() >= 0 && view.getBottom() <= this.H.getHeight();
    }

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

    @Override // androidx.recyclerview.widget.a
    public final void q0(RecyclerView recyclerView, int i, int i5) {
        r rVar;
        int i8;
        int i9 = this.f8401W;
        if (i9 != -1 && (rVar = this.f8417n0) != null && rVar.f8706f >= 0 && (i8 = this.f8403Z) != Integer.MIN_VALUE && i <= i9 + i8) {
            this.f8403Z = i8 + i5;
        }
        N1.B0 b02 = (N1.B0) this.f8423u0.f8514s;
        if (b02 != null) {
            b02.r(-1);
        }
    }

    public final void q1(View view, int i, int i5, int i8, int i9) {
        int iJ1;
        int i10;
        int iG1 = this.f8387I == 0 ? g1(view) : h1(view);
        int i11 = this.f8407d0;
        if (i11 > 0) {
            iG1 = Math.min(iG1, i11);
        }
        int i12 = this.f8414k0;
        int i13 = i12 & 112;
        int absoluteGravity = (this.f8397S & 786432) != 0 ? Gravity.getAbsoluteGravity(i12 & 8388615, 1) : i12 & 7;
        int i14 = this.f8387I;
        if ((i14 != 0 || i13 != 48) && (i14 != 1 || absoluteGravity != 3)) {
            if ((i14 == 0 && i13 == 80) || (i14 == 1 && absoluteGravity == 5)) {
                iJ1 = j1(i) - iG1;
            } else if ((i14 == 0 && i13 == 16) || (i14 == 1 && absoluteGravity == 1)) {
                iJ1 = (j1(i) - iG1) / 2;
            }
            i9 += iJ1;
        }
        if (this.f8387I == 0) {
            i10 = iG1 + i9;
        } else {
            int i15 = iG1 + i9;
            int i16 = i9;
            i9 = i5;
            i5 = i16;
            i10 = i8;
            i8 = i15;
        }
        C0490u c0490u = (C0490u) view.getLayoutParams();
        androidx.recyclerview.widget.a.c0(view, i5, i9, i8, i10);
        Rect rect = f8383y0;
        super.M(view, rect);
        int i17 = i5 - rect.left;
        int i18 = i9 - rect.top;
        int i19 = rect.right - i8;
        int i20 = rect.bottom - i10;
        c0490u.f8717u = i17;
        c0490u.f8718v = i18;
        c0490u.f8719w = i19;
        c0490u.f8720x = i20;
        J1(view);
    }

    @Override // androidx.recyclerview.widget.a
    public final boolean r(C0203d0 c0203d0) {
        return c0203d0 instanceof C0490u;
    }

    @Override // androidx.recyclerview.widget.a
    public final void r0(RecyclerView recyclerView) {
        this.f8403Z = 0;
        N1.B0 b02 = (N1.B0) this.f8423u0.f8514s;
        if (b02 != null) {
            b02.r(-1);
        }
    }

    public final void r1() {
        int i = this.f8389K - 1;
        this.f8389K = i;
        if (i == 0) {
            this.f8396R = null;
            this.f8390L = null;
            this.f8391M = 0;
            this.f8392N = 0;
        }
    }

    @Override // androidx.recyclerview.widget.a
    public final void s0(RecyclerView recyclerView, int i, int i5) {
        int i8;
        int i9 = this.f8401W;
        if (i9 != -1 && (i8 = this.f8403Z) != Integer.MIN_VALUE) {
            int i10 = i9 + i8;
            if (i <= i10 && i10 < i + 1) {
                this.f8403Z = (i5 - i) + i8;
            } else if (i < i10 && i5 > i10 - 1) {
                this.f8403Z = i8 - 1;
            } else if (i > i10 && i5 < i10) {
                this.f8403Z = i8 + 1;
            }
        }
        N1.B0 b02 = (N1.B0) this.f8423u0.f8514s;
        if (b02 != null) {
            b02.r(-1);
        }
    }

    public final void s1(View view) {
        int childMeasureSpec;
        int childMeasureSpec2;
        C0490u c0490u = (C0490u) view.getLayoutParams();
        Rect rect = f8383y0;
        o(view, rect);
        int i = ((ViewGroup.MarginLayoutParams) c0490u).leftMargin + ((ViewGroup.MarginLayoutParams) c0490u).rightMargin + rect.left + rect.right;
        int i5 = ((ViewGroup.MarginLayoutParams) c0490u).topMargin + ((ViewGroup.MarginLayoutParams) c0490u).bottomMargin + rect.top + rect.bottom;
        int iMakeMeasureSpec = this.f8406c0 == -2 ? View.MeasureSpec.makeMeasureSpec(0, 0) : View.MeasureSpec.makeMeasureSpec(this.f8407d0, 1073741824);
        if (this.f8387I == 0) {
            childMeasureSpec = ViewGroup.getChildMeasureSpec(View.MeasureSpec.makeMeasureSpec(0, 0), i, ((ViewGroup.MarginLayoutParams) c0490u).width);
            childMeasureSpec2 = ViewGroup.getChildMeasureSpec(iMakeMeasureSpec, i5, ((ViewGroup.MarginLayoutParams) c0490u).height);
        } else {
            int childMeasureSpec3 = ViewGroup.getChildMeasureSpec(View.MeasureSpec.makeMeasureSpec(0, 0), i5, ((ViewGroup.MarginLayoutParams) c0490u).height);
            childMeasureSpec = ViewGroup.getChildMeasureSpec(iMakeMeasureSpec, i, ((ViewGroup.MarginLayoutParams) c0490u).width);
            childMeasureSpec2 = childMeasureSpec3;
        }
        view.measure(childMeasureSpec, childMeasureSpec2);
    }

    @Override // androidx.recyclerview.widget.a
    public final void t(int i, int i5, N1.p0 p0Var, C0224z c0224z) {
        try {
            z1(null, p0Var);
            if (this.f8387I != 0) {
                i = i5;
            }
            if (I() != 0 && i != 0) {
                this.f8417n0.e(i < 0 ? -this.f8421s0 : this.f8420r0 + this.f8421s0, i, c0224z);
                r1();
            }
        } finally {
            r1();
        }
    }

    @Override // androidx.recyclerview.widget.a
    public final void t0(RecyclerView recyclerView, int i, int i5) {
        r rVar;
        int i8;
        int i9;
        int i10 = this.f8401W;
        if (i10 != -1 && (rVar = this.f8417n0) != null && rVar.f8706f >= 0 && (i8 = this.f8403Z) != Integer.MIN_VALUE && i <= (i9 = i10 + i8)) {
            if (i + i5 > i9) {
                this.f8401W = (i - i9) + i8 + i10;
                this.f8403Z = Integer.MIN_VALUE;
            } else {
                this.f8403Z = i8 - i5;
            }
        }
        N1.B0 b02 = (N1.B0) this.f8423u0.f8514s;
        if (b02 != null) {
            b02.r(-1);
        }
    }

    public final void t1() {
        this.f8417n0.m((this.f8397S & 262144) != 0 ? this.f8420r0 + this.f8421s0 + this.f8392N : (-this.f8421s0) - this.f8392N, false);
    }

    @Override // androidx.recyclerview.widget.a
    public final void u(int i, C0224z c0224z) {
        int i5 = this.H.f8661i1;
        if (i == 0 || i5 == 0) {
            return;
        }
        int iMax = Math.max(0, Math.min(this.f8401W - ((i5 - 1) / 2), i - i5));
        for (int i8 = iMax; i8 < i && i8 < iMax + i5; i8++) {
            c0224z.b(i8, 0);
        }
    }

    @Override // androidx.recyclerview.widget.a
    public final void u0(int i, int i5) {
        int i8;
        int i9 = i5 + i;
        while (i < i9) {
            Q0 q0 = this.f8423u0;
            N1.B0 b02 = (N1.B0) q0.f8514s;
            if (b02 != null) {
                synchronized (((d3.E) b02.f4422g)) {
                    i8 = b02.f4418c;
                }
                if (i8 != 0) {
                    ((N1.B0) q0.f8514s).n(Integer.toString(i));
                }
            }
            i++;
        }
    }

    public final void u1(boolean z8) {
        int i;
        if (z8) {
            if (o1()) {
                return;
            }
        } else if (S() == 0 || this.H.H(0) != null) {
            return;
        }
        C0491v c0491v = this.f8402Y;
        if (c0491v == null) {
            C0491v c0491v2 = new C0491v(this, z8 ? 1 : -1, this.f8415l0 > 1);
            this.f8403Z = 0;
            a1(c0491v2);
        } else {
            GridLayoutManager gridLayoutManager = c0491v.f8725u;
            if (z8) {
                int i5 = c0491v.f8724t;
                if (i5 < gridLayoutManager.f8386G) {
                    c0491v.f8724t = i5 + 1;
                }
            } else {
                int i8 = c0491v.f8724t;
                if (i8 > (-gridLayoutManager.f8386G)) {
                    c0491v.f8724t = i8 - 1;
                }
            }
        }
        if (this.f8387I == 0) {
            i = 4;
            if (this.f9115r.getLayoutDirection() != 1 ? !z8 : z8) {
                i = 3;
            }
        } else {
            i = z8 ? 2 : 1;
        }
        if (this.f8395Q == null) {
            this.f8395Q = (AudioManager) this.H.getContext().getSystemService("audio");
        }
        this.f8395Q.playSoundEffect(i);
    }

    /* JADX WARN: Removed duplicated region for block: B:75:0x0148  */
    /* JADX WARN: Removed duplicated region for block: B:77:0x014c  */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public final boolean v1(boolean z8) {
        int i;
        int i5 = 0;
        if (this.f8407d0 != 0 || this.f8408e0 == null) {
            return false;
        }
        r rVar = this.f8417n0;
        C0224z[] c0224zArrJ = rVar == null ? null : rVar.j(rVar.f8706f, rVar.f8707g);
        int i8 = 0;
        boolean z9 = false;
        int i9 = -1;
        while (i8 < this.f8415l0) {
            C0224z c0224z = c0224zArrJ == null ? null : c0224zArrJ[i8];
            int iE = c0224z == null ? i5 : c0224z.e();
            int i10 = -1;
            for (int i11 = i5; i11 < iE; i11 += 2) {
                int iD = c0224z.d(i11 + 1);
                for (int iD2 = c0224z.d(i11); iD2 <= iD; iD2++) {
                    View viewD = D(iD2 - this.f8391M);
                    if (viewD != null) {
                        if (z8) {
                            s1(viewD);
                        }
                        int iG1 = this.f8387I == 0 ? g1(viewD) : h1(viewD);
                        if (iG1 > i10) {
                            i10 = iG1;
                        }
                    }
                }
            }
            int iB = this.f8390L.b();
            if (this.H.f9033K || !z8 || i10 >= 0 || iB <= 0) {
                i = i5;
            } else if (i9 >= 0) {
                i = i5;
                if (i9 >= 0) {
                    i10 = i9;
                }
            } else {
                int i12 = this.f8401W;
                if (i12 < 0) {
                    i12 = i5;
                } else if (i12 >= iB) {
                    i12 = iB - 1;
                }
                if (I() > 0) {
                    int iD3 = this.H.M(H(i5)).d();
                    int iD4 = this.H.M(H(I() - 1)).d();
                    if (i12 >= iD3 && i12 <= iD4) {
                        i12 = i12 - iD3 <= iD4 - i12 ? iD3 - 1 : iD4 + 1;
                        if (i12 < 0 && iD4 < iB - 1) {
                            i12 = iD4 + 1;
                        } else if (i12 >= iB && iD3 > 0) {
                            i12 = iD3 - 1;
                        }
                    }
                }
                if (i12 >= 0 && i12 < iB) {
                    int iMakeMeasureSpec = View.MeasureSpec.makeMeasureSpec(i5, i5);
                    int iMakeMeasureSpec2 = View.MeasureSpec.makeMeasureSpec(i5, i5);
                    View viewD2 = this.f8396R.d(i12);
                    int[] iArr = this.f8422t0;
                    if (viewD2 != null) {
                        C0490u c0490u = (C0490u) viewD2.getLayoutParams();
                        Rect rect = f8383y0;
                        o(viewD2, rect);
                        i = i5;
                        viewD2.measure(ViewGroup.getChildMeasureSpec(iMakeMeasureSpec, getPaddingRight() + getPaddingLeft() + ((ViewGroup.MarginLayoutParams) c0490u).leftMargin + ((ViewGroup.MarginLayoutParams) c0490u).rightMargin + rect.left + rect.right, ((ViewGroup.MarginLayoutParams) c0490u).width), ViewGroup.getChildMeasureSpec(iMakeMeasureSpec2, getPaddingBottom() + getPaddingTop() + ((ViewGroup.MarginLayoutParams) c0490u).topMargin + ((ViewGroup.MarginLayoutParams) c0490u).bottomMargin + rect.top + rect.bottom, ((ViewGroup.MarginLayoutParams) c0490u).height));
                        iArr[i] = h1(viewD2);
                        iArr[1] = g1(viewD2);
                        this.f8396R.i(viewD2);
                    } else {
                        i = i5;
                    }
                    i9 = this.f8387I == 0 ? iArr[1] : iArr[i];
                }
                if (i9 >= 0) {
                }
            }
            if (i10 < 0) {
                i10 = i;
            }
            int[] iArr2 = this.f8408e0;
            if (iArr2[i8] != i10) {
                iArr2[i8] = i10;
                z9 = true;
            }
            i8++;
            i5 = i;
        }
        return z9;
    }

    /* JADX WARN: Removed duplicated region for block: B:129:0x02b2 A[LOOP:3: B:128:0x02b0->B:129:0x02b2, LOOP_END] */
    /* JADX WARN: Removed duplicated region for block: B:132:0x02d0  */
    /* JADX WARN: Removed duplicated region for block: B:138:0x02e5 A[LOOP:11: B:138:0x02e5->B:355:?, LOOP_START] */
    /* JADX WARN: Removed duplicated region for block: B:156:0x0338  */
    /* JADX WARN: Removed duplicated region for block: B:167:0x03d8  */
    /* JADX WARN: Removed duplicated region for block: B:168:0x03db  */
    /* JADX WARN: Removed duplicated region for block: B:178:0x03f0 A[LOOP:12: B:178:0x03f0->B:356:?, LOOP_START] */
    /* JADX WARN: Removed duplicated region for block: B:304:0x05f9 A[PHI: r1 r2
      0x05f9: PHI (r1v41 int) = (r1v37 int), (r1v44 int) binds: [B:315:0x0626, B:303:0x05f7] A[DONT_GENERATE, DONT_INLINE]
      0x05f9: PHI (r2v46 int) = (r2v42 int), (r2v49 int) binds: [B:315:0x0626, B:303:0x05f7] A[DONT_GENERATE, DONT_INLINE]] */
    @Override // androidx.recyclerview.widget.a
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public final void w0(N1.i0 i0Var, N1.p0 p0Var) {
        int i;
        int i5;
        int i8;
        boolean z8;
        View view;
        boolean z9;
        r d02;
        int i9;
        int i10;
        int left;
        int right;
        int i11;
        List list;
        int size;
        r rVar;
        int i12;
        int i13;
        int i14;
        W2.j jVarK;
        int i15;
        int i16;
        W2.j jVarK2;
        if (this.f8415l0 != 0 && p0Var.b() >= 0) {
            if ((this.f8397S & 64) != 0 && I() > 0) {
                this.f8397S |= 128;
                return;
            }
            int i17 = this.f8397S;
            if ((i17 & 512) == 0) {
                this.f8417n0 = null;
                this.f8408e0 = null;
                this.f8397S = i17 & (-1025);
                G0(i0Var);
                return;
            }
            this.f8397S = (i17 & (-4)) | 1;
            z1(i0Var, p0Var);
            int iMax = Integer.MIN_VALUE;
            if (p0Var.f4620g) {
                K1();
                int I7 = I();
                if (this.f8417n0 != null && I7 > 0) {
                    int i18 = this.H.M(H(0)).f4657d;
                    int i19 = this.H.M(H(I7 - 1)).f4657d;
                    int iMin = Integer.MAX_VALUE;
                    for (int i20 = 0; i20 < I7; i20++) {
                        View viewH = H(i20);
                        C0490u c0490u = (C0490u) viewH.getLayoutParams();
                        this.H.getClass();
                        N1.t0 t0VarN = RecyclerView.N(viewH);
                        int iC = t0VarN != null ? t0VarN.c() : -1;
                        if (c0490u.f4520q.m() || c0490u.f4520q.j() || viewH.isLayoutRequested() || ((!viewH.hasFocus() && this.f8401W == c0490u.f4520q.c()) || ((viewH.hasFocus() && this.f8401W != c0490u.f4520q.c()) || iC < i18 || iC > i19))) {
                            iMin = Math.min(iMin, this.f8388J.g(viewH));
                            iMax = Math.max(iMax, this.f8388J.d(viewH));
                        }
                    }
                    if (iMax > iMin) {
                        this.f8392N = iMax - iMin;
                    }
                    c1();
                    t1();
                }
                this.f8397S &= -4;
                r1();
                return;
            }
            boolean z10 = p0Var.f4623k;
            SparseIntArray sparseIntArray = this.f8393O;
            if (z10) {
                sparseIntArray.clear();
                int I8 = I();
                for (int i21 = 0; i21 < I8; i21++) {
                    int i22 = this.H.M(H(i21)).f4657d;
                    if (i22 >= 0 && (jVarK2 = this.f8417n0.k(i22)) != null) {
                        sparseIntArray.put(i22, jVarK2.f7097q);
                    }
                }
            }
            boolean z11 = !b0() && this.f8418o0 == 0;
            int i23 = this.f8401W;
            if (i23 != -1 && (i16 = this.f8403Z) != Integer.MIN_VALUE) {
                this.f8401W = i23 + i16;
            }
            this.f8403Z = 0;
            View viewD = D(this.f8401W);
            int i24 = this.f8401W;
            boolean zHasFocus = this.H.hasFocus();
            r rVar2 = this.f8417n0;
            int i25 = rVar2 != null ? rVar2.f8706f : -1;
            int i26 = rVar2 != null ? rVar2.f8707g : -1;
            if (this.f8387I == 0) {
                i5 = p0Var.f4627o;
                i = p0Var.f4628p;
            } else {
                i = p0Var.f4627o;
                i5 = p0Var.f4628p;
            }
            int i27 = i5;
            int i28 = i;
            int i29 = i27;
            int iB = this.f8390L.b();
            if (iB == 0) {
                this.f8401W = -1;
            } else {
                int i30 = this.f8401W;
                if (i30 >= iB) {
                    this.f8401W = iB - 1;
                } else if (i30 == -1 && iB > 0) {
                    this.f8401W = 0;
                }
            }
            boolean z12 = this.f8390L.f4619f;
            C2.a aVar = this.f8419p0;
            if (z12 || (rVar = this.f8417n0) == null || rVar.f8706f < 0 || (this.f8397S & 256) != 0 || rVar.f8705e != this.f8415l0) {
                i8 = i29;
                z8 = z11;
                view = viewD;
                z9 = zHasFocus;
                int i31 = this.f8397S;
                this.f8397S = i31 & (-257);
                r rVar3 = this.f8417n0;
                if (rVar3 == null || this.f8415l0 != rVar3.f8705e) {
                    int i32 = this.f8415l0;
                    if (i32 == 1) {
                        d02 = new D0();
                    } else {
                        G0 g02 = new G0();
                        g02.f8379j = new C0432j(64);
                        g02.f8380k = -1;
                        g02.n(i32);
                        d02 = g02;
                    }
                    this.f8417n0 = d02;
                    d02.f8702b = this.f8426x0;
                    d02.f8703c = (this.f8397S & 262144) != 0;
                    R0 r02 = (R0) aVar.f1159t;
                    r02.f8516b = Integer.MIN_VALUE;
                    r02.f8515a = Integer.MAX_VALUE;
                    int i33 = this.D;
                    R0 r03 = (R0) aVar.f1157r;
                    r03.i = i33;
                    int i34 = this.f9113E;
                    R0 r04 = (R0) aVar.f1158s;
                    r04.i = i34;
                    int paddingLeft = getPaddingLeft();
                    int paddingRight = getPaddingRight();
                    r03.f8523j = paddingLeft;
                    r03.f8524k = paddingRight;
                    int paddingTop = getPaddingTop();
                    int paddingBottom = getPaddingBottom();
                    r04.f8523j = paddingTop;
                    r04.f8524k = paddingBottom;
                    this.f8420r0 = ((R0) aVar.f1159t).i;
                    this.f8405b0 = 0;
                    N1();
                    this.f8417n0.f8704d = this.f8412i0;
                    B(this.f8396R);
                    r rVar4 = this.f8417n0;
                    rVar4.f8707g = -1;
                    rVar4.f8706f = -1;
                    R0 r05 = (R0) aVar.f1159t;
                    r05.f8516b = Integer.MIN_VALUE;
                    r05.f8518d = Integer.MIN_VALUE;
                    r05.f8515a = Integer.MAX_VALUE;
                    r05.f8517c = Integer.MAX_VALUE;
                    int i35 = this.f8397S;
                    this.f8397S = i35 & (-5);
                    this.f8397S = (i35 & (-21)) | (!z8 ? 16 : 0);
                    if (z8 && (i25 < 0 || (i9 = this.f8401W) > i26 || i9 < i25)) {
                        i25 = this.f8401W;
                        i26 = i25;
                    }
                    rVar4.i = i25;
                    if (i26 != -1) {
                        while (this.f8417n0.a() && D(i26) == null) {
                        }
                    }
                } else {
                    if (((i31 & 262144) != 0) != rVar3.f8703c) {
                    }
                    R0 r022 = (R0) aVar.f1159t;
                    r022.f8516b = Integer.MIN_VALUE;
                    r022.f8515a = Integer.MAX_VALUE;
                    int i332 = this.D;
                    R0 r032 = (R0) aVar.f1157r;
                    r032.i = i332;
                    int i342 = this.f9113E;
                    R0 r042 = (R0) aVar.f1158s;
                    r042.i = i342;
                    int paddingLeft2 = getPaddingLeft();
                    int paddingRight2 = getPaddingRight();
                    r032.f8523j = paddingLeft2;
                    r032.f8524k = paddingRight2;
                    int paddingTop2 = getPaddingTop();
                    int paddingBottom2 = getPaddingBottom();
                    r042.f8523j = paddingTop2;
                    r042.f8524k = paddingBottom2;
                    this.f8420r0 = ((R0) aVar.f1159t).i;
                    this.f8405b0 = 0;
                    N1();
                    this.f8417n0.f8704d = this.f8412i0;
                    B(this.f8396R);
                    r rVar42 = this.f8417n0;
                    rVar42.f8707g = -1;
                    rVar42.f8706f = -1;
                    R0 r052 = (R0) aVar.f1159t;
                    r052.f8516b = Integer.MIN_VALUE;
                    r052.f8518d = Integer.MIN_VALUE;
                    r052.f8515a = Integer.MAX_VALUE;
                    r052.f8517c = Integer.MAX_VALUE;
                    int i352 = this.f8397S;
                    this.f8397S = i352 & (-5);
                    this.f8397S = (i352 & (-21)) | (!z8 ? 16 : 0);
                    if (z8) {
                        i25 = this.f8401W;
                        i26 = i25;
                    }
                    rVar42.i = i25;
                    if (i26 != -1) {
                    }
                }
            } else {
                R0 r06 = (R0) aVar.f1157r;
                r06.i = this.D;
                int i36 = this.f9113E;
                R0 r07 = (R0) aVar.f1158s;
                r07.i = i36;
                int paddingLeft3 = getPaddingLeft();
                int paddingRight3 = getPaddingRight();
                r06.f8523j = paddingLeft3;
                r06.f8524k = paddingRight3;
                int paddingTop3 = getPaddingTop();
                int paddingBottom3 = getPaddingBottom();
                r07.f8523j = paddingTop3;
                r07.f8524k = paddingBottom3;
                this.f8420r0 = ((R0) aVar.f1159t).i;
                N1();
                r rVar5 = this.f8417n0;
                rVar5.f8704d = this.f8412i0;
                this.f8397S |= 4;
                rVar5.i = this.f8401W;
                int I9 = I();
                int i37 = this.f8417n0.f8706f;
                this.f8397S &= -9;
                int i38 = i37;
                int i39 = 0;
                while (i39 < I9) {
                    View viewH2 = H(i39);
                    if (i38 == f1(viewH2) && (jVarK = this.f8417n0.k(i38)) != null) {
                        int i40 = i29;
                        int iK1 = (k1(jVarK.f7097q) + ((R0) aVar.f1160u).f8523j) - this.f8405b0;
                        int iG = this.f8388J.g(viewH2);
                        C2.a aVar2 = aVar;
                        Rect rect = f8383y0;
                        M(viewH2, rect);
                        int iWidth = this.f8387I == 0 ? rect.width() : rect.height();
                        if ((((C0490u) viewH2.getLayoutParams()).f4520q.f4662j & 2) != 0) {
                            this.f8397S |= 8;
                            i15 = iG;
                            N0(this.f8396R, this.f9114q.n(viewH2), viewH2);
                            viewH2 = n1(i38);
                            m(viewH2, i39, false);
                        } else {
                            i15 = iG;
                        }
                        s1(viewH2);
                        int iH1 = this.f8387I == 0 ? h1(viewH2) : g1(viewH2);
                        i12 = I9;
                        z9 = zHasFocus;
                        boolean z13 = z11;
                        i13 = i39;
                        i8 = i40;
                        z8 = z13;
                        view = viewD;
                        int i41 = iH1;
                        q1(viewH2, jVarK.f7097q, i15, i15 + iH1, iK1);
                        if (iWidth != i41) {
                            int i42 = this.f8417n0.f8707g;
                            for (i14 = i12 - 1; i14 >= i13; i14--) {
                                View viewH3 = H(i14);
                                N0(this.f8396R, this.f9114q.n(viewH3), viewH3);
                            }
                            this.f8417n0.l(i38);
                            if ((this.f8397S & 65536) == 0) {
                                c1();
                                int i43 = this.f8401W;
                                if (i43 >= 0 && i43 <= i42) {
                                    while (true) {
                                        r rVar6 = this.f8417n0;
                                        if (rVar6.f8707g >= this.f8401W) {
                                            break;
                                        } else {
                                            rVar6.a();
                                        }
                                    }
                                }
                            } else {
                                while (this.f8417n0.a() && this.f8417n0.f8707g < i42) {
                                }
                            }
                            M1();
                            N1();
                        } else {
                            i39 = i13 + 1;
                            i38++;
                            aVar = aVar2;
                            i29 = i8;
                            z11 = z8;
                            zHasFocus = z9;
                            viewD = view;
                            I9 = i12;
                        }
                    } else {
                        i8 = i29;
                        i12 = I9;
                        z8 = z11;
                        view = viewD;
                        z9 = zHasFocus;
                        i13 = i39;
                        int i422 = this.f8417n0.f8707g;
                        while (i14 >= i13) {
                        }
                        this.f8417n0.l(i38);
                        if ((this.f8397S & 65536) == 0) {
                        }
                        M1();
                        N1();
                    }
                }
                i8 = i29;
                z8 = z11;
                view = viewD;
                z9 = zHasFocus;
                M1();
                N1();
            }
            while (true) {
                M1();
                r rVar7 = this.f8417n0;
                int i44 = rVar7.f8706f;
                int i45 = rVar7.f8707g;
                int i46 = -i8;
                int i47 = -i28;
                View viewD2 = D(this.f8401W);
                if (viewD2 != null && z8) {
                    E1(viewD2, viewD2.findFocus(), false, i46, i47);
                }
                if (viewD2 != null && z9 && !viewD2.hasFocus()) {
                    viewD2.requestFocus();
                } else if (!z9 && !this.H.hasFocus()) {
                    if (viewD2 == null || !viewD2.hasFocusable()) {
                        int I10 = I();
                        int i48 = 0;
                        while (true) {
                            if (i48 >= I10) {
                                break;
                            }
                            viewD2 = H(i48);
                            if (viewD2 != null && viewD2.hasFocusable()) {
                                this.H.focusableViewAvailable(viewD2);
                                break;
                            }
                            i48++;
                        }
                    } else {
                        this.H.focusableViewAvailable(viewD2);
                    }
                    if (z8 && viewD2 != null && viewD2.hasFocus()) {
                        E1(viewD2, viewD2.findFocus(), false, i46, i47);
                    }
                }
                c1();
                t1();
                r rVar8 = this.f8417n0;
                if (rVar8.f8706f == i44 && rVar8.f8707g == i45) {
                    break;
                }
            }
            y1();
            x1();
            if (p0Var.f4623k && (size = (list = this.f8396R.f4558d).size()) != 0) {
                int[] iArr = this.f8394P;
                if (iArr == null || size > iArr.length) {
                    int length = iArr == null ? 16 : iArr.length;
                    while (length < size) {
                        length <<= 1;
                    }
                    this.f8394P = new int[length];
                }
                int i49 = 0;
                for (int i50 = 0; i50 < size; i50++) {
                    int iC2 = ((N1.t0) list.get(i50)).c();
                    if (iC2 >= 0) {
                        this.f8394P[i49] = iC2;
                        i49++;
                    }
                }
                if (i49 > 0) {
                    Arrays.sort(this.f8394P, 0, i49);
                    r rVar9 = this.f8417n0;
                    int[] iArr2 = this.f8394P;
                    int i51 = rVar9.f8707g;
                    int iBinarySearch = i51 >= 0 ? Arrays.binarySearch(iArr2, 0, i49, i51) : 0;
                    Object[] objArr = rVar9.f8701a;
                    if (iBinarySearch < 0) {
                        int iS = rVar9.f8703c ? (rVar9.f8702b.s(i51) - rVar9.f8702b.t(i51)) - rVar9.f8704d : rVar9.f8704d + rVar9.f8702b.t(i51) + rVar9.f8702b.s(i51);
                        for (int i52 = (-iBinarySearch) - 1; i52 < i49; i52++) {
                            int i53 = iArr2[i52];
                            int i54 = sparseIntArray.get(i53);
                            int i55 = i54 < 0 ? 0 : i54;
                            int iQ = rVar9.f8702b.q(i53, true, objArr, true);
                            rVar9.f8702b.p(objArr[0], i53, iQ, i55, iS);
                            iS = rVar9.f8703c ? (iS - iQ) - rVar9.f8704d : iS + iQ + rVar9.f8704d;
                        }
                    }
                    int i56 = rVar9.f8706f;
                    int iBinarySearch2 = i56 >= 0 ? Arrays.binarySearch(iArr2, 0, i49, i56) : 0;
                    if (iBinarySearch2 < 0) {
                        int i57 = (-iBinarySearch2) - 2;
                        int iS2 = rVar9.f8703c ? rVar9.f8702b.s(i56) : rVar9.f8702b.s(i56);
                        while (i57 >= 0) {
                            int i58 = iArr2[i57];
                            int i59 = sparseIntArray.get(i58);
                            int i60 = i59 < 0 ? 0 : i59;
                            int iQ2 = rVar9.f8702b.q(i58, false, objArr, true);
                            int i61 = rVar9.f8703c ? iS2 + rVar9.f8704d + iQ2 : (iS2 - rVar9.f8704d) - iQ2;
                            rVar9.f8702b.p(objArr[0], i58, iQ2, i60, i61);
                            i57--;
                            iS2 = i61;
                        }
                    }
                }
                sparseIntArray.clear();
            }
            int i62 = this.f8397S;
            if ((i62 & 1024) != 0) {
                this.f8397S = i62 & (-1025);
            } else {
                L1();
            }
            if (((this.f8397S & 4) != 0 && ((i11 = this.f8401W) != i24 || D(i11) != view || (this.f8397S & 8) != 0)) || (this.f8397S & 20) == 16) {
                d1();
            }
            e1();
            int i63 = this.f8397S;
            if ((i63 & 64) != 0) {
                if (this.f8387I == 1) {
                    i10 = -this.f9113E;
                    if (I() > 0 && (left = H(0).getTop()) < 0) {
                        i10 += left;
                    }
                    A1(i10);
                } else {
                    if ((i63 & 262144) != 0) {
                        i10 = this.D;
                        if (I() > 0 && (right = H(0).getRight()) > i10) {
                            i10 = right;
                        }
                    } else {
                        i10 = -this.D;
                        if (I() > 0 && (left = H(0).getLeft()) < 0) {
                        }
                    }
                    A1(i10);
                }
            }
            this.f8397S &= -4;
            r1();
        }
    }

    public final int w1(int i, boolean z8) {
        W2.j jVarK;
        r rVar = this.f8417n0;
        if (rVar == null) {
            return i;
        }
        int i5 = this.f8401W;
        int i8 = (i5 == -1 || (jVarK = rVar.k(i5)) == null) ? -1 : jVarK.f7097q;
        int I7 = I();
        View view = null;
        for (int i9 = 0; i9 < I7 && i != 0; i9++) {
            int i10 = i > 0 ? i9 : (I7 - 1) - i9;
            View viewH = H(i10);
            if (viewH.getVisibility() == 0 && (!X() || viewH.hasFocusable())) {
                int iF1 = f1(H(i10));
                W2.j jVarK2 = this.f8417n0.k(iF1);
                int i11 = jVarK2 == null ? -1 : jVarK2.f7097q;
                if (i8 == -1) {
                    i5 = iF1;
                    view = viewH;
                    i8 = i11;
                } else if (i11 == i8 && ((i > 0 && iF1 > i5) || (i < 0 && iF1 < i5))) {
                    i = i > 0 ? i - 1 : i + 1;
                    i5 = iF1;
                    view = viewH;
                }
            }
        }
        if (view != null) {
            if (z8) {
                if (X()) {
                    this.f8397S |= 32;
                    view.requestFocus();
                    this.f8397S &= -33;
                }
                this.f8401W = i5;
                return i;
            }
            D1(view, view.findFocus(), true);
        }
        return i;
    }

    public final void x1() {
        int i = this.f8397S;
        if ((65600 & i) == 65536) {
            r rVar = this.f8417n0;
            int i5 = this.f8401W;
            int i8 = (i & 262144) != 0 ? -this.f8421s0 : this.f8420r0 + this.f8421s0;
            while (true) {
                int i9 = rVar.f8707g;
                if (i9 >= rVar.f8706f && i9 > i5) {
                    if (!rVar.f8703c) {
                        if (rVar.f8702b.s(i9) < i8) {
                            break;
                        }
                        rVar.f8702b.v(rVar.f8707g);
                        rVar.f8707g--;
                    } else {
                        if (rVar.f8702b.s(i9) > i8) {
                            break;
                        }
                        rVar.f8702b.v(rVar.f8707g);
                        rVar.f8707g--;
                    }
                } else {
                    break;
                }
            }
            if (rVar.f8707g < rVar.f8706f) {
                rVar.f8707g = -1;
                rVar.f8706f = -1;
            }
        }
    }

    @Override // androidx.recyclerview.widget.a
    public final void y0(N1.i0 i0Var, N1.p0 p0Var, int i, int i5) {
        int size;
        int size2;
        int mode;
        int paddingLeft;
        int paddingRight;
        int iM1;
        z1(i0Var, p0Var);
        if (this.f8387I == 0) {
            size2 = View.MeasureSpec.getSize(i);
            size = View.MeasureSpec.getSize(i5);
            mode = View.MeasureSpec.getMode(i5);
            paddingLeft = getPaddingTop();
            paddingRight = getPaddingBottom();
        } else {
            size = View.MeasureSpec.getSize(i);
            size2 = View.MeasureSpec.getSize(i5);
            mode = View.MeasureSpec.getMode(i);
            paddingLeft = getPaddingLeft();
            paddingRight = getPaddingRight();
        }
        int i8 = paddingRight + paddingLeft;
        this.f8409f0 = size;
        int i9 = this.f8406c0;
        if (i9 == -2) {
            int i10 = this.f8416m0;
            if (i10 == 0) {
                i10 = 1;
            }
            this.f8415l0 = i10;
            this.f8407d0 = 0;
            int[] iArr = this.f8408e0;
            if (iArr == null || iArr.length != i10) {
                this.f8408e0 = new int[i10];
            }
            if (this.f8390L.f4620g) {
                K1();
            }
            v1(true);
            if (mode == Integer.MIN_VALUE) {
                size = Math.min(m1() + i8, this.f8409f0);
            } else if (mode == 0) {
                iM1 = m1();
                size = iM1 + i8;
            } else {
                if (mode != 1073741824) {
                    throw new IllegalStateException("wrong spec");
                }
                size = this.f8409f0;
            }
        } else {
            if (mode != Integer.MIN_VALUE) {
                if (mode == 0) {
                    if (i9 == 0) {
                        i9 = size - i8;
                    }
                    this.f8407d0 = i9;
                    int i11 = this.f8416m0;
                    if (i11 == 0) {
                        i11 = 1;
                    }
                    this.f8415l0 = i11;
                    iM1 = ((i11 - 1) * this.f8413j0) + (i9 * i11);
                    size = iM1 + i8;
                } else if (mode != 1073741824) {
                    throw new IllegalStateException("wrong spec");
                }
            }
            int i12 = this.f8416m0;
            if (i12 == 0 && i9 == 0) {
                this.f8415l0 = 1;
                this.f8407d0 = size - i8;
            } else if (i12 == 0) {
                this.f8407d0 = i9;
                int i13 = this.f8413j0;
                this.f8415l0 = (size + i13) / (i9 + i13);
            } else if (i9 == 0) {
                this.f8415l0 = i12;
                this.f8407d0 = ((size - i8) - ((i12 - 1) * this.f8413j0)) / i12;
            } else {
                this.f8415l0 = i12;
                this.f8407d0 = i9;
            }
            if (mode == Integer.MIN_VALUE) {
                int i14 = this.f8407d0;
                int i15 = this.f8415l0;
                int i16 = ((i15 - 1) * this.f8413j0) + (i14 * i15) + i8;
                if (i16 < size) {
                    size = i16;
                }
            }
        }
        if (this.f8387I == 0) {
            this.f9115r.setMeasuredDimension(size2, size);
        } else {
            this.f9115r.setMeasuredDimension(size, size2);
        }
        r1();
    }

    public final void y1() {
        int i = this.f8397S;
        if ((65600 & i) == 65536) {
            r rVar = this.f8417n0;
            int i5 = this.f8401W;
            int i8 = (i & 262144) != 0 ? this.f8420r0 + this.f8421s0 : -this.f8421s0;
            while (true) {
                int i9 = rVar.f8707g;
                int i10 = rVar.f8706f;
                if (i9 >= i10 && i10 < i5) {
                    int iT = rVar.f8702b.t(i10);
                    if (!rVar.f8703c) {
                        if (rVar.f8702b.s(rVar.f8706f) + iT > i8) {
                            break;
                        }
                        rVar.f8702b.v(rVar.f8706f);
                        rVar.f8706f++;
                    } else {
                        if (rVar.f8702b.s(rVar.f8706f) - iT < i8) {
                            break;
                        }
                        rVar.f8702b.v(rVar.f8706f);
                        rVar.f8706f++;
                    }
                } else {
                    break;
                }
            }
            if (rVar.f8707g < rVar.f8706f) {
                rVar.f8707g = -1;
                rVar.f8706f = -1;
            }
        }
    }

    @Override // androidx.recyclerview.widget.a
    public final boolean z0(RecyclerView recyclerView, N1.p0 p0Var, View view, View view2) {
        if ((this.f8397S & 32768) == 0 && f1(view) != -1 && (this.f8397S & 35) == 0) {
            E1(view, view2, true, 0, 0);
        }
        return true;
    }

    public final void z1(N1.i0 i0Var, N1.p0 p0Var) {
        int i = this.f8389K;
        if (i == 0) {
            this.f8396R = i0Var;
            this.f8390L = p0Var;
            this.f8391M = 0;
            this.f8392N = 0;
        }
        this.f8389K = i + 1;
    }

    public GridLayoutManager(AbstractC0469i abstractC0469i) {
        this.f8385F = 1.0f;
        this.f8386G = 10;
        this.f8387I = 0;
        this.f8388J = new N1.L(this, 0);
        this.f8393O = new SparseIntArray();
        this.f8397S = 221696;
        this.f8398T = null;
        this.f8399U = null;
        this.f8400V = null;
        this.f8401W = -1;
        this.f8403Z = 0;
        this.f8414k0 = 8388659;
        this.f8416m0 = 1;
        this.f8418o0 = 0;
        this.f8419p0 = new C2.a(10);
        this.q0 = new A1.y(26);
        this.f8422t0 = new int[2];
        Q0 q0 = new Q0();
        q0.f8512q = 0;
        q0.f8513r = 100;
        this.f8423u0 = q0;
        this.f8425w0 = new M4.k(10, this);
        this.f8426x0 = new P.g(15, this);
        this.H = abstractC0469i;
        this.f8404a0 = -1;
        if (this.f9122y) {
            this.f9122y = false;
            this.f9123z = 0;
            RecyclerView recyclerView = this.f9115r;
            if (recyclerView != null) {
                recyclerView.f9074s.n();
            }
        }
    }

    @Override // androidx.recyclerview.widget.a
    public final void x0(N1.p0 p0Var) {
    }
}
