package androidx.recyclerview.widget;

import A1.x;
import M.J;
import N.c;
import N.e;
import N1.C;
import N1.C0203d0;
import N1.C0224z;
import N1.E;
import N1.F;
import N1.G;
import N1.T;
import N1.i0;
import N1.p0;
import N1.t0;
import android.content.Context;
import android.graphics.Rect;
import android.os.Bundle;
import android.util.AttributeSet;
import android.util.Log;
import android.util.SparseIntArray;
import android.view.View;
import android.view.ViewGroup;
import d3.R0;
import d5.AbstractC0844a;
import java.lang.reflect.Field;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashSet;
import java.util.Objects;
import java.util.Set;
import java.util.TreeMap;

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

    /* JADX INFO: renamed from: f0, reason: collision with root package name */
    public static final Set f8983f0 = Collections.unmodifiableSet(new HashSet(Arrays.asList(17, 66, 33, 130)));

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

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

    /* JADX INFO: renamed from: W, reason: collision with root package name */
    public int[] f8986W;
    public View[] X;

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

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

    /* JADX INFO: renamed from: a0, reason: collision with root package name */
    public final R0 f8989a0;

    /* JADX INFO: renamed from: b0, reason: collision with root package name */
    public final Rect f8990b0;

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

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

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

    public GridLayoutManager(Context context, AttributeSet attributeSet, int i, int i5) {
        super(context, attributeSet, i, i5);
        this.f8984U = false;
        this.f8985V = -1;
        this.f8987Y = new SparseIntArray();
        this.f8988Z = new SparseIntArray();
        this.f8989a0 = new R0(24);
        this.f8990b0 = new Rect();
        this.f8991c0 = -1;
        this.f8992d0 = -1;
        this.f8993e0 = -1;
        R1(a.U(context, attributeSet, i, i5).f4516b);
    }

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

    @Override // androidx.recyclerview.widget.LinearLayoutManager
    public final void C1(boolean z8) {
        if (z8) {
            throw new UnsupportedOperationException("GridLayoutManager does not support stack from end. Consider using reverse layout");
        }
        super.C1(false);
    }

    /* JADX WARN: Removed duplicated region for block: B:118:0x01a1  */
    /* JADX WARN: Removed duplicated region for block: B:121:0x01a7  */
    /* JADX WARN: Removed duplicated region for block: B:122:0x01a9 A[EDGE_INSN: B:209:0x01a9->B:122:0x01a9 BREAK  A[LOOP:2: B:126:0x01b9->B:135:0x01e2, LOOP_LABEL: LOOP:2: B:126:0x01b9->B:135:0x01e2], EDGE_INSN: B:216:0x01a9->B:122:0x01a9 BREAK  A[LOOP:5: B:148:0x0221->B:159:0x0251, LOOP_LABEL: LOOP:5: B:148:0x0221->B:159:0x0251]] */
    /* JADX WARN: Removed duplicated region for block: B:142:0x0213  */
    /* JADX WARN: Removed duplicated region for block: B:167:0x027e  */
    @Override // androidx.recyclerview.widget.LinearLayoutManager, androidx.recyclerview.widget.a
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public final boolean D0(int i, Bundle bundle) {
        View viewH;
        t0 t0VarM;
        int iIntValue;
        int i5;
        if (i == c.f4364p.a() && i != -1) {
            int i8 = 0;
            while (true) {
                if (i8 >= I()) {
                    viewH = null;
                    break;
                }
                View viewH2 = H(i8);
                Objects.requireNonNull(viewH2);
                if (viewH2.isAccessibilityFocused()) {
                    viewH = H(i8);
                    break;
                }
                i8++;
            }
            if (viewH != null && bundle != null) {
                int i9 = bundle.getInt("android.view.accessibility.action.ARGUMENT_DIRECTION_INT", -1);
                if (f8983f0.contains(Integer.valueOf(i9)) && (t0VarM = this.f9115r.M(viewH)) != null) {
                    int iC = t0VarM.c();
                    int iJ1 = J1(iC);
                    int iI1 = I1(iC);
                    if (iJ1 >= 0 && iI1 >= 0) {
                        if (!K1(iC).contains(Integer.valueOf(this.f8992d0)) || !L1(I1(iC), iC).contains(Integer.valueOf(this.f8993e0))) {
                            this.f8992d0 = iJ1;
                            this.f8993e0 = iI1;
                        }
                        int i10 = this.f8992d0;
                        if (i10 == -1) {
                            i10 = iJ1;
                        }
                        int i11 = this.f8993e0;
                        if (i11 != -1) {
                            iI1 = i11;
                        }
                        if (i9 == 17) {
                            iIntValue = iC - 1;
                            while (iIntValue >= 0) {
                                int iJ12 = J1(iIntValue);
                                int iI12 = I1(iIntValue);
                                if (iJ12 < 0 || iI12 < 0) {
                                    break;
                                }
                                if (this.f8994F != 1) {
                                    if (K1(iIntValue).contains(Integer.valueOf(i10)) && iI12 < iI1) {
                                        this.f8993e0 = iI12;
                                        break;
                                    }
                                    iIntValue--;
                                } else {
                                    if ((iJ12 == i10 && iI12 < iI1) || iJ12 < i10) {
                                        this.f8992d0 = iJ12;
                                        this.f8993e0 = iI12;
                                        break;
                                    }
                                    iIntValue--;
                                }
                            }
                            iIntValue = -1;
                            if (iIntValue == -1) {
                            }
                            if (iIntValue != -1) {
                            }
                        } else if (i9 == 33) {
                            iIntValue = iC - 1;
                            while (iIntValue >= 0) {
                                int iJ13 = J1(iIntValue);
                                int iI13 = I1(iIntValue);
                                if (iJ13 < 0 || iI13 < 0) {
                                    break;
                                }
                                if (this.f8994F != 1) {
                                    if (iJ13 < i10 && iI13 == iI1) {
                                        this.f8992d0 = ((Integer) Collections.max(K1(iIntValue))).intValue();
                                        break;
                                    }
                                    iIntValue--;
                                } else {
                                    if (iJ13 < i10 && L1(I1(iIntValue), iIntValue).contains(Integer.valueOf(iI1))) {
                                        this.f8992d0 = iJ13;
                                        break;
                                    }
                                    iIntValue--;
                                }
                            }
                            iIntValue = -1;
                            if (iIntValue == -1) {
                            }
                            if (iIntValue != -1) {
                            }
                        } else if (i9 == 66) {
                            iIntValue = iC + 1;
                            while (iIntValue < S()) {
                                int iJ14 = J1(iIntValue);
                                int iI14 = I1(iIntValue);
                                if (iJ14 < 0 || iI14 < 0) {
                                    break;
                                }
                                if (this.f8994F != 1) {
                                    if (iI14 > iI1 && K1(iIntValue).contains(Integer.valueOf(i10))) {
                                        this.f8993e0 = iI14;
                                        break;
                                    }
                                    iIntValue++;
                                } else {
                                    if ((iJ14 == i10 && iI14 > iI1) || iJ14 > i10) {
                                        this.f8992d0 = iJ14;
                                        this.f8993e0 = iI14;
                                        break;
                                    }
                                    iIntValue++;
                                }
                            }
                            iIntValue = -1;
                            if (iIntValue == -1) {
                                if (i9 != 17) {
                                }
                            }
                            if (iIntValue != -1) {
                            }
                        } else if (i9 == 130) {
                            iIntValue = iC + 1;
                            while (iIntValue < S()) {
                                int iJ15 = J1(iIntValue);
                                int iI15 = I1(iIntValue);
                                if (iJ15 < 0 || iI15 < 0) {
                                    break;
                                }
                                if (this.f8994F != 1) {
                                    if (iJ15 > i10 && iI15 == iI1) {
                                        this.f8992d0 = J1(iIntValue);
                                        break;
                                    }
                                    iIntValue++;
                                } else {
                                    if (iJ15 > i10 && (iI15 == iI1 || L1(I1(iIntValue), iIntValue).contains(Integer.valueOf(iI1)))) {
                                        this.f8992d0 = iJ15;
                                        break;
                                    }
                                    iIntValue++;
                                }
                            }
                            iIntValue = -1;
                            if (iIntValue == -1 && (i5 = this.f8994F) == 0) {
                                if (i9 != 17) {
                                    if (iJ1 >= 0 && i5 != 1) {
                                        TreeMap treeMap = new TreeMap(Collections.reverseOrder());
                                        int i12 = 0;
                                        loop2: while (true) {
                                            if (i12 >= S()) {
                                                for (Integer num : treeMap.keySet()) {
                                                    int iIntValue2 = num.intValue();
                                                    if (iIntValue2 < iJ1) {
                                                        iIntValue = ((Integer) treeMap.get(num)).intValue();
                                                        this.f8992d0 = iIntValue2;
                                                        this.f8993e0 = I1(iIntValue);
                                                        break;
                                                    }
                                                }
                                            } else {
                                                for (Integer num2 : K1(i12)) {
                                                    if (num2.intValue() < 0) {
                                                        break loop2;
                                                    }
                                                    treeMap.put(num2, Integer.valueOf(i12));
                                                }
                                                i12++;
                                            }
                                        }
                                    } else {
                                        iIntValue = -1;
                                    }
                                } else if (i9 == 66) {
                                    if (iJ1 >= 0 && i5 != 1) {
                                        TreeMap treeMap2 = new TreeMap();
                                        int i13 = 0;
                                        loop5: while (true) {
                                            if (i13 >= S()) {
                                                for (Integer num3 : treeMap2.keySet()) {
                                                    int iIntValue3 = num3.intValue();
                                                    if (iIntValue3 > iJ1) {
                                                        iIntValue = ((Integer) treeMap2.get(num3)).intValue();
                                                        this.f8992d0 = iIntValue3;
                                                        this.f8993e0 = 0;
                                                        break;
                                                    }
                                                }
                                            } else {
                                                for (Integer num4 : K1(i13)) {
                                                    if (num4.intValue() < 0) {
                                                        break loop5;
                                                    }
                                                    if (!treeMap2.containsKey(num4)) {
                                                        treeMap2.put(num4, Integer.valueOf(i13));
                                                    }
                                                }
                                                i13++;
                                            }
                                        }
                                        iIntValue = -1;
                                    }
                                }
                            }
                            if (iIntValue != -1) {
                                P0(iIntValue);
                                this.f8991c0 = iIntValue;
                                return true;
                            }
                        }
                    }
                }
            }
        } else {
            if (i != 16908343 || bundle == null) {
                return super.D0(i, bundle);
            }
            int i14 = bundle.getInt("android.view.accessibility.action.ARGUMENT_ROW_INT", -1);
            int i15 = bundle.getInt("android.view.accessibility.action.ARGUMENT_COLUMN_INT", -1);
            if (i14 != -1 && i15 != -1) {
                int iA = this.f9115r.f9019C.a();
                int i16 = 0;
                while (true) {
                    if (i16 >= iA) {
                        i16 = -1;
                        break;
                    }
                    RecyclerView recyclerView = this.f9115r;
                    int iO1 = O1(i16, recyclerView.f9074s, recyclerView.f9087y0);
                    RecyclerView recyclerView2 = this.f9115r;
                    int iN1 = N1(i16, recyclerView2.f9074s, recyclerView2.f9087y0);
                    if (this.f8994F != 1) {
                        if (iO1 == i14 && iN1 == i15) {
                            break;
                        }
                        i16++;
                    } else {
                        if (iO1 == i15 && iN1 == i14) {
                            break;
                        }
                        i16++;
                    }
                }
                if (i16 > -1) {
                    this.f9001N = i16;
                    this.f9002O = 0;
                    G g8 = this.f9003P;
                    if (g8 != null) {
                        g8.f4457q = -1;
                    }
                    M0();
                    return true;
                }
            }
        }
        return false;
    }

    @Override // androidx.recyclerview.widget.LinearLayoutManager, androidx.recyclerview.widget.a
    public final C0203d0 E() {
        return this.f8994F == 0 ? new C(-2, -1) : new C(-1, -2);
    }

    @Override // androidx.recyclerview.widget.a
    public final C0203d0 F(Context context, AttributeSet attributeSet) {
        C c3 = new C(context, attributeSet);
        c3.f4423u = -1;
        c3.f4424v = 0;
        return c3;
    }

    @Override // androidx.recyclerview.widget.a
    public final C0203d0 G(ViewGroup.LayoutParams layoutParams) {
        if (layoutParams instanceof ViewGroup.MarginLayoutParams) {
            C c3 = new C((ViewGroup.MarginLayoutParams) layoutParams);
            c3.f4423u = -1;
            c3.f4424v = 0;
            return c3;
        }
        C c8 = new C(layoutParams);
        c8.f4423u = -1;
        c8.f4424v = 0;
        return c8;
    }

    public final void G1(int i) {
        int i5;
        int[] iArr = this.f8986W;
        int i8 = this.f8985V;
        if (iArr == null || iArr.length != i8 + 1 || iArr[iArr.length - 1] != i) {
            iArr = new int[i8 + 1];
        }
        int i9 = 0;
        iArr[0] = 0;
        int i10 = i / i8;
        int i11 = i % i8;
        int i12 = 0;
        for (int i13 = 1; i13 <= i8; i13++) {
            i9 += i11;
            if (i9 <= 0 || i8 - i9 >= i11) {
                i5 = i10;
            } else {
                i5 = i10 + 1;
                i9 -= i8;
            }
            i12 += i5;
            iArr[i13] = i12;
        }
        this.f8986W = iArr;
    }

    public final void H1() {
        View[] viewArr = this.X;
        if (viewArr == null || viewArr.length != this.f8985V) {
            this.X = new View[this.f8985V];
        }
    }

    public final int I1(int i) {
        if (this.f8994F == 0) {
            RecyclerView recyclerView = this.f9115r;
            return N1(i, recyclerView.f9074s, recyclerView.f9087y0);
        }
        RecyclerView recyclerView2 = this.f9115r;
        return O1(i, recyclerView2.f9074s, recyclerView2.f9087y0);
    }

    public final int J1(int i) {
        if (this.f8994F == 1) {
            RecyclerView recyclerView = this.f9115r;
            return N1(i, recyclerView.f9074s, recyclerView.f9087y0);
        }
        RecyclerView recyclerView2 = this.f9115r;
        return O1(i, recyclerView2.f9074s, recyclerView2.f9087y0);
    }

    @Override // androidx.recyclerview.widget.a
    public final int K(i0 i0Var, p0 p0Var) {
        if (this.f8994F == 1) {
            return Math.min(this.f8985V, S());
        }
        if (p0Var.b() < 1) {
            return 0;
        }
        return N1(p0Var.b() - 1, i0Var, p0Var) + 1;
    }

    public final HashSet K1(int i) {
        return L1(J1(i), i);
    }

    public final HashSet L1(int i, int i5) {
        HashSet hashSet = new HashSet();
        RecyclerView recyclerView = this.f9115r;
        int iP1 = P1(i5, recyclerView.f9074s, recyclerView.f9087y0);
        for (int i8 = i; i8 < i + iP1; i8++) {
            hashSet.add(Integer.valueOf(i8));
        }
        return hashSet;
    }

    public final int M1(int i, int i5) {
        if (this.f8994F != 1 || !u1()) {
            int[] iArr = this.f8986W;
            return iArr[i5 + i] - iArr[i];
        }
        int[] iArr2 = this.f8986W;
        int i8 = this.f8985V;
        return iArr2[i8 - i] - iArr2[(i8 - i) - i5];
    }

    public final int N1(int i, i0 i0Var, p0 p0Var) {
        boolean z8 = p0Var.f4620g;
        R0 r02 = this.f8989a0;
        if (!z8) {
            int i5 = this.f8985V;
            r02.getClass();
            return R0.Q(i, i5);
        }
        int iB = i0Var.b(i);
        if (iB != -1) {
            int i8 = this.f8985V;
            r02.getClass();
            return R0.Q(iB, i8);
        }
        Log.w("GridLayoutManager", "Cannot find span size for pre layout position. " + i);
        return 0;
    }

    @Override // androidx.recyclerview.widget.LinearLayoutManager, androidx.recyclerview.widget.a
    public final int O0(int i, i0 i0Var, p0 p0Var) {
        S1();
        H1();
        return super.O0(i, i0Var, p0Var);
    }

    public final int O1(int i, i0 i0Var, p0 p0Var) {
        boolean z8 = p0Var.f4620g;
        R0 r02 = this.f8989a0;
        if (!z8) {
            int i5 = this.f8985V;
            r02.getClass();
            return i % i5;
        }
        int i8 = this.f8988Z.get(i, -1);
        if (i8 != -1) {
            return i8;
        }
        int iB = i0Var.b(i);
        if (iB != -1) {
            int i9 = this.f8985V;
            r02.getClass();
            return iB % i9;
        }
        Log.w("GridLayoutManager", "Cannot find span size for pre layout position. It is not cached, not in the adapter. Pos:" + i);
        return 0;
    }

    public final int P1(int i, i0 i0Var, p0 p0Var) {
        boolean z8 = p0Var.f4620g;
        R0 r02 = this.f8989a0;
        if (!z8) {
            r02.getClass();
            return 1;
        }
        int i5 = this.f8987Y.get(i, -1);
        if (i5 != -1) {
            return i5;
        }
        if (i0Var.b(i) != -1) {
            r02.getClass();
            return 1;
        }
        Log.w("GridLayoutManager", "Cannot find span size for pre layout position. It is not cached, not in the adapter. Pos:" + i);
        return 1;
    }

    @Override // androidx.recyclerview.widget.LinearLayoutManager, androidx.recyclerview.widget.a
    public final int Q0(int i, i0 i0Var, p0 p0Var) {
        S1();
        H1();
        return super.Q0(i, i0Var, p0Var);
    }

    public final void Q1(View view, int i, boolean z8) {
        int iJ;
        int iJ2;
        C c3 = (C) view.getLayoutParams();
        Rect rect = c3.f4521r;
        int i5 = rect.top + rect.bottom + ((ViewGroup.MarginLayoutParams) c3).topMargin + ((ViewGroup.MarginLayoutParams) c3).bottomMargin;
        int i8 = rect.left + rect.right + ((ViewGroup.MarginLayoutParams) c3).leftMargin + ((ViewGroup.MarginLayoutParams) c3).rightMargin;
        int iM1 = M1(c3.f4423u, c3.f4424v);
        if (this.f8994F == 1) {
            iJ2 = a.J(false, iM1, i, i8, ((ViewGroup.MarginLayoutParams) c3).width);
            iJ = a.J(true, this.H.n(), this.f9112C, i5, ((ViewGroup.MarginLayoutParams) c3).height);
        } else {
            int iJ3 = a.J(false, iM1, i, i5, ((ViewGroup.MarginLayoutParams) c3).height);
            int iJ4 = a.J(true, this.H.n(), this.f9111B, i8, ((ViewGroup.MarginLayoutParams) c3).width);
            iJ = iJ3;
            iJ2 = iJ4;
        }
        C0203d0 c0203d0 = (C0203d0) view.getLayoutParams();
        if (z8 ? Y0(view, iJ2, iJ, c0203d0) : W0(view, iJ2, iJ, c0203d0)) {
            view.measure(iJ2, iJ);
        }
    }

    public final void R1(int i) {
        if (i == this.f8985V) {
            return;
        }
        this.f8984U = true;
        if (i < 1) {
            throw new IllegalArgumentException(AbstractC0844a.j("Span count should be at least 1. Provided ", i));
        }
        this.f8985V = i;
        this.f8989a0.S();
        M0();
    }

    public final void S1() {
        int paddingBottom;
        int paddingTop;
        if (this.f8994F == 1) {
            paddingBottom = this.D - getPaddingRight();
            paddingTop = getPaddingLeft();
        } else {
            paddingBottom = this.f9113E - getPaddingBottom();
            paddingTop = getPaddingTop();
        }
        G1(paddingBottom - paddingTop);
    }

    @Override // androidx.recyclerview.widget.a
    public final void T0(Rect rect, int i, int i5) {
        int iS;
        int iS2;
        if (this.f8986W == null) {
            super.T0(rect, i, i5);
        }
        int paddingRight = getPaddingRight() + getPaddingLeft();
        int paddingBottom = getPaddingBottom() + getPaddingTop();
        if (this.f8994F == 1) {
            int iHeight = rect.height() + paddingBottom;
            RecyclerView recyclerView = this.f9115r;
            Field field = J.f4065a;
            iS2 = a.s(i5, iHeight, recyclerView.getMinimumHeight());
            int[] iArr = this.f8986W;
            iS = a.s(i, iArr[iArr.length - 1] + paddingRight, this.f9115r.getMinimumWidth());
        } else {
            int iWidth = rect.width() + paddingRight;
            RecyclerView recyclerView2 = this.f9115r;
            Field field2 = J.f4065a;
            iS = a.s(i, iWidth, recyclerView2.getMinimumWidth());
            int[] iArr2 = this.f8986W;
            iS2 = a.s(i5, iArr2[iArr2.length - 1] + paddingBottom, this.f9115r.getMinimumHeight());
        }
        this.f9115r.setMeasuredDimension(iS, iS2);
    }

    @Override // androidx.recyclerview.widget.a
    public final int V(i0 i0Var, p0 p0Var) {
        if (this.f8994F == 0) {
            return Math.min(this.f8985V, S());
        }
        if (p0Var.b() < 1) {
            return 0;
        }
        return N1(p0Var.b() - 1, i0Var, p0Var) + 1;
    }

    @Override // androidx.recyclerview.widget.LinearLayoutManager, androidx.recyclerview.widget.a
    public final boolean b1() {
        return this.f9003P == null && !this.f8984U;
    }

    @Override // androidx.recyclerview.widget.LinearLayoutManager
    public final void d1(p0 p0Var, F f3, C0224z c0224z) {
        int i;
        int i5 = this.f8985V;
        for (int i8 = 0; i8 < this.f8985V && (i = f3.f4449d) >= 0 && i < p0Var.b() && i5 > 0; i8++) {
            c0224z.b(f3.f4449d, Math.max(0, f3.f4452g));
            this.f8989a0.getClass();
            i5--;
            f3.f4449d += f3.f4450e;
        }
    }

    /* JADX WARN: Code restructure failed: missing block: B:54:0x00c9, code lost:
    
        if (r13 == (r2 > r15)) goto L49;
     */
    /* JADX WARN: Code restructure failed: missing block: B:76:0x0129, code lost:
    
        if (r16 == null) goto L78;
     */
    /* JADX WARN: Code restructure failed: missing block: B:77:0x012b, code lost:
    
        return r16;
     */
    /* JADX WARN: Code restructure failed: missing block: B:78:0x012c, code lost:
    
        return r17;
     */
    @Override // androidx.recyclerview.widget.LinearLayoutManager, androidx.recyclerview.widget.a
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public final View k0(View view, int i, i0 i0Var, p0 p0Var) {
        int I7;
        int i5;
        int I8;
        View view2;
        int i8;
        int i9;
        i0 i0Var2 = i0Var;
        p0 p0Var2 = p0Var;
        View viewC = C(view);
        if (viewC != null) {
            C c3 = (C) viewC.getLayoutParams();
            int i10 = c3.f4423u;
            int i11 = c3.f4424v + i10;
            if (super.k0(view, i, i0Var, p0Var) != null) {
                if ((h1(i) == 1) != this.f8998K) {
                    I8 = I() - 1;
                    I7 = -1;
                    i5 = -1;
                } else {
                    I7 = I();
                    i5 = 1;
                    I8 = 0;
                }
                boolean z8 = this.f8994F == 1 && u1();
                int iN1 = N1(I8, i0Var2, p0Var2);
                View view3 = null;
                int i12 = -1;
                int i13 = -1;
                int iMin = 0;
                int i14 = I8;
                int iMin2 = 0;
                View view4 = null;
                while (true) {
                    View view5 = view4;
                    if (i14 == I7) {
                        break;
                    }
                    int iN12 = N1(i14, i0Var2, p0Var2);
                    View viewH = H(i14);
                    if (viewH == viewC) {
                        break;
                    }
                    if (!viewH.hasFocusable() || iN12 == iN1) {
                        C c8 = (C) viewH.getLayoutParams();
                        int i15 = c8.f4423u;
                        view2 = viewC;
                        int i16 = c8.f4424v + i15;
                        if (viewH.hasFocusable() && i15 == i10 && i16 == i11) {
                            return viewH;
                        }
                        if (!(viewH.hasFocusable() && view3 == null) && (viewH.hasFocusable() || view5 != null)) {
                            i8 = I7;
                            int iMin3 = Math.min(i16, i11) - Math.max(i15, i10);
                            if (viewH.hasFocusable()) {
                                if (iMin3 <= iMin) {
                                    if (iMin3 == iMin) {
                                    }
                                    i9 = iMin;
                                }
                                i9 = iMin;
                            } else if (view3 == null) {
                                i9 = iMin;
                                if (!this.f9116s.T(viewH) || !this.f9117t.T(viewH)) {
                                    if (iMin3 <= iMin2) {
                                        if (iMin3 == iMin2) {
                                            if (z8 == (i15 > i12)) {
                                            }
                                        }
                                    }
                                }
                            } else {
                                i9 = iMin;
                            }
                            i14 += i5;
                            i0Var2 = i0Var;
                            p0Var2 = p0Var;
                            viewC = view2;
                            I7 = i8;
                        } else {
                            i9 = iMin;
                            i8 = I7;
                        }
                        if (viewH.hasFocusable()) {
                            int i17 = c8.f4423u;
                            iMin = Math.min(i16, i11) - Math.max(i15, i10);
                            view3 = viewH;
                            i13 = i17;
                            view4 = view5;
                        } else {
                            int i18 = c8.f4423u;
                            view4 = viewH;
                            i12 = i18;
                            iMin = i9;
                            iMin2 = Math.min(i16, i11) - Math.max(i15, i10);
                        }
                        i14 += i5;
                        i0Var2 = i0Var;
                        p0Var2 = p0Var;
                        viewC = view2;
                        I7 = i8;
                    } else {
                        if (view3 != null) {
                            break;
                        }
                        view2 = viewC;
                        i9 = iMin;
                        i8 = I7;
                    }
                    view4 = view5;
                    iMin = i9;
                    i14 += i5;
                    i0Var2 = i0Var;
                    p0Var2 = p0Var;
                    viewC = view2;
                    I7 = i8;
                }
            }
        }
        return null;
    }

    @Override // androidx.recyclerview.widget.LinearLayoutManager, androidx.recyclerview.widget.a
    public final void m0(i0 i0Var, p0 p0Var, e eVar) {
        super.m0(i0Var, p0Var, eVar);
        eVar.i("android.widget.GridView");
        T t6 = this.f9115r.f9019C;
        if (t6 == null || t6.a() <= 1) {
            return;
        }
        eVar.b(c.f4364p);
    }

    @Override // androidx.recyclerview.widget.a
    public final void n0(i0 i0Var, p0 p0Var, View view, e eVar) {
        ViewGroup.LayoutParams layoutParams = view.getLayoutParams();
        if (!(layoutParams instanceof C)) {
            o0(view, eVar);
            return;
        }
        C c3 = (C) layoutParams;
        int iN1 = N1(c3.f4520q.d(), i0Var, p0Var);
        if (this.f8994F == 0) {
            eVar.k(K4.c.F(false, c3.f4423u, c3.f4424v, iN1, 1));
        } else {
            eVar.k(K4.c.F(false, iN1, 1, c3.f4423u, c3.f4424v));
        }
    }

    @Override // androidx.recyclerview.widget.LinearLayoutManager
    public final View p1(i0 i0Var, p0 p0Var, boolean z8, boolean z9) {
        int i;
        int I7;
        int I8 = I();
        int i5 = 1;
        if (z9) {
            I7 = I() - 1;
            i = -1;
            i5 = -1;
        } else {
            i = I8;
            I7 = 0;
        }
        int iB = p0Var.b();
        i1();
        int iM = this.H.m();
        int i8 = this.H.i();
        View view = null;
        View view2 = null;
        while (I7 != i) {
            View viewH = H(I7);
            int iT = a.T(viewH);
            if (iT >= 0 && iT < iB && O1(iT, i0Var, p0Var) == 0) {
                if (((C0203d0) viewH.getLayoutParams()).f4520q.j()) {
                    if (view2 == null) {
                        view2 = viewH;
                    }
                } else {
                    if (this.H.g(viewH) < i8 && this.H.d(viewH) >= iM) {
                        return viewH;
                    }
                    if (view == null) {
                        view = viewH;
                    }
                }
            }
            I7 += i5;
        }
        return view != null ? view : view2;
    }

    @Override // androidx.recyclerview.widget.a
    public final void q0(RecyclerView recyclerView, int i, int i5) {
        R0 r02 = this.f8989a0;
        r02.S();
        ((SparseIntArray) r02.f11693s).clear();
    }

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

    @Override // androidx.recyclerview.widget.a
    public final void r0(RecyclerView recyclerView) {
        R0 r02 = this.f8989a0;
        r02.S();
        ((SparseIntArray) r02.f11693s).clear();
    }

    @Override // androidx.recyclerview.widget.a
    public final void s0(RecyclerView recyclerView, int i, int i5) {
        R0 r02 = this.f8989a0;
        r02.S();
        ((SparseIntArray) r02.f11693s).clear();
    }

    @Override // androidx.recyclerview.widget.a
    public final void t0(RecyclerView recyclerView, int i, int i5) {
        R0 r02 = this.f8989a0;
        r02.S();
        ((SparseIntArray) r02.f11693s).clear();
    }

    @Override // androidx.recyclerview.widget.a
    public final void v0(RecyclerView recyclerView, int i, int i5) {
        R0 r02 = this.f8989a0;
        r02.S();
        ((SparseIntArray) r02.f11693s).clear();
    }

    @Override // androidx.recyclerview.widget.LinearLayoutManager
    public final void v1(i0 i0Var, p0 p0Var, F f3, E e8) {
        int i;
        int i5;
        int i8;
        int iF;
        int paddingLeft;
        int paddingTop;
        int iF2;
        int iJ;
        int iJ2;
        boolean z8;
        int i9;
        View viewB;
        int iL = this.H.l();
        boolean z9 = iL != 1073741824;
        int i10 = I() > 0 ? this.f8986W[this.f8985V] : 0;
        if (z9) {
            S1();
        }
        boolean z10 = f3.f4450e == 1;
        int iO1 = this.f8985V;
        if (!z10) {
            iO1 = O1(f3.f4449d, i0Var, p0Var) + P1(f3.f4449d, i0Var, p0Var);
        }
        int i11 = 0;
        while (i11 < this.f8985V && (i9 = f3.f4449d) >= 0 && i9 < p0Var.b() && iO1 > 0) {
            int i12 = f3.f4449d;
            int iP1 = P1(i12, i0Var, p0Var);
            if (iP1 > this.f8985V) {
                StringBuilder sb = new StringBuilder("Item at position ");
                sb.append(i12);
                sb.append(" requires ");
                sb.append(iP1);
                sb.append(" spans but GridLayoutManager has only ");
                throw new IllegalArgumentException(AbstractC0844a.n(sb, this.f8985V, " spans."));
            }
            iO1 -= iP1;
            if (iO1 < 0 || (viewB = f3.b(i0Var)) == null) {
                break;
            }
            this.X[i11] = viewB;
            i11++;
        }
        if (i11 == 0) {
            e8.f4443b = true;
            return;
        }
        if (z10) {
            i8 = 1;
            i5 = i11;
            i = 0;
        } else {
            i = i11 - 1;
            i5 = -1;
            i8 = -1;
        }
        int i13 = 0;
        while (i != i5) {
            View view = this.X[i];
            C c3 = (C) view.getLayoutParams();
            int iP12 = P1(a.T(view), i0Var, p0Var);
            c3.f4424v = iP12;
            c3.f4423u = i13;
            i13 += iP12;
            i += i8;
        }
        float f7 = 0.0f;
        int i14 = 0;
        for (int i15 = 0; i15 < i11; i15++) {
            View view2 = this.X[i15];
            if (f3.f4455k != null) {
                z8 = false;
                if (z10) {
                    m(view2, -1, true);
                } else {
                    m(view2, 0, true);
                }
            } else if (z10) {
                l(view2);
                z8 = false;
            } else {
                z8 = false;
                m(view2, 0, false);
            }
            o(view2, this.f8990b0);
            Q1(view2, iL, z8);
            int iE = this.H.e(view2);
            if (iE > i14) {
                i14 = iE;
            }
            float f8 = (this.H.f(view2) * 1.0f) / ((C) view2.getLayoutParams()).f4424v;
            if (f8 > f7) {
                f7 = f8;
            }
        }
        if (z9) {
            G1(Math.max(Math.round(f7 * this.f8985V), i10));
            i14 = 0;
            for (int i16 = 0; i16 < i11; i16++) {
                View view3 = this.X[i16];
                Q1(view3, 1073741824, true);
                int iE2 = this.H.e(view3);
                if (iE2 > i14) {
                    i14 = iE2;
                }
            }
        }
        for (int i17 = 0; i17 < i11; i17++) {
            View view4 = this.X[i17];
            if (this.H.e(view4) != i14) {
                C c8 = (C) view4.getLayoutParams();
                Rect rect = c8.f4521r;
                int i18 = rect.top + rect.bottom + ((ViewGroup.MarginLayoutParams) c8).topMargin + ((ViewGroup.MarginLayoutParams) c8).bottomMargin;
                int i19 = rect.left + rect.right + ((ViewGroup.MarginLayoutParams) c8).leftMargin + ((ViewGroup.MarginLayoutParams) c8).rightMargin;
                int iM1 = M1(c8.f4423u, c8.f4424v);
                if (this.f8994F == 1) {
                    iJ2 = a.J(false, iM1, 1073741824, i19, ((ViewGroup.MarginLayoutParams) c8).width);
                    iJ = View.MeasureSpec.makeMeasureSpec(i14 - i18, 1073741824);
                } else {
                    int iMakeMeasureSpec = View.MeasureSpec.makeMeasureSpec(i14 - i19, 1073741824);
                    iJ = a.J(false, iM1, 1073741824, i18, ((ViewGroup.MarginLayoutParams) c8).height);
                    iJ2 = iMakeMeasureSpec;
                }
                if (Y0(view4, iJ2, iJ, (C0203d0) view4.getLayoutParams())) {
                    view4.measure(iJ2, iJ);
                }
            }
        }
        e8.f4442a = i14;
        if (this.f8994F != 1) {
            if (f3.f4451f == -1) {
                int i20 = f3.f4447b;
                paddingLeft = i20 - i14;
                iF = i20;
            } else {
                int i21 = f3.f4447b;
                iF = i21 + i14;
                paddingLeft = i21;
            }
            paddingTop = 0;
            iF2 = 0;
        } else if (f3.f4451f == -1) {
            iF2 = f3.f4447b;
            paddingTop = iF2 - i14;
            paddingLeft = 0;
            iF = 0;
        } else {
            int i22 = f3.f4447b;
            paddingTop = i22;
            iF = 0;
            iF2 = i22 + i14;
            paddingLeft = 0;
        }
        for (int i23 = 0; i23 < i11; i23++) {
            View view5 = this.X[i23];
            C c9 = (C) view5.getLayoutParams();
            if (this.f8994F != 1) {
                paddingTop = getPaddingTop() + this.f8986W[c9.f4423u];
                iF2 = this.H.f(view5) + paddingTop;
            } else if (u1()) {
                int paddingLeft2 = getPaddingLeft() + this.f8986W[this.f8985V - c9.f4423u];
                iF = paddingLeft2;
                paddingLeft = paddingLeft2 - this.H.f(view5);
            } else {
                paddingLeft = getPaddingLeft() + this.f8986W[c9.f4423u];
                iF = this.H.f(view5) + paddingLeft;
            }
            a.c0(view5, paddingLeft, paddingTop, iF, iF2);
            if (c9.f4520q.j() || c9.f4520q.m()) {
                e8.f4444c = true;
            }
            e8.f4445d = view5.hasFocusable() | e8.f4445d;
        }
        Arrays.fill(this.X, (Object) null);
    }

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

    @Override // androidx.recyclerview.widget.LinearLayoutManager, androidx.recyclerview.widget.a
    public final void w0(i0 i0Var, p0 p0Var) {
        boolean z8 = p0Var.f4620g;
        SparseIntArray sparseIntArray = this.f8988Z;
        SparseIntArray sparseIntArray2 = this.f8987Y;
        if (z8) {
            int I7 = I();
            for (int i = 0; i < I7; i++) {
                C c3 = (C) H(i).getLayoutParams();
                int iD = c3.f4520q.d();
                sparseIntArray2.put(iD, c3.f4424v);
                sparseIntArray.put(iD, c3.f4423u);
            }
        }
        super.w0(i0Var, p0Var);
        sparseIntArray2.clear();
        sparseIntArray.clear();
    }

    @Override // androidx.recyclerview.widget.LinearLayoutManager
    public final void w1(i0 i0Var, p0 p0Var, x xVar, int i) {
        S1();
        if (p0Var.b() > 0 && !p0Var.f4620g) {
            boolean z8 = i == 1;
            int iO1 = O1(xVar.f358c, i0Var, p0Var);
            if (z8) {
                while (iO1 > 0) {
                    int i5 = xVar.f358c;
                    if (i5 <= 0) {
                        break;
                    }
                    int i8 = i5 - 1;
                    xVar.f358c = i8;
                    iO1 = O1(i8, i0Var, p0Var);
                }
            } else {
                int iB = p0Var.b() - 1;
                int i9 = xVar.f358c;
                while (i9 < iB) {
                    int i10 = i9 + 1;
                    int iO12 = O1(i10, i0Var, p0Var);
                    if (iO12 <= iO1) {
                        break;
                    }
                    i9 = i10;
                    iO1 = iO12;
                }
                xVar.f358c = i9;
            }
        }
        H1();
    }

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

    @Override // androidx.recyclerview.widget.LinearLayoutManager, androidx.recyclerview.widget.a
    public final void x0(p0 p0Var) {
        View viewD;
        super.x0(p0Var);
        this.f8984U = false;
        int i = this.f8991c0;
        if (i == -1 || (viewD = D(i)) == null) {
            return;
        }
        viewD.sendAccessibilityEvent(67108864);
        this.f8991c0 = -1;
    }

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

    public GridLayoutManager(int i) {
        super(1);
        this.f8984U = false;
        this.f8985V = -1;
        this.f8987Y = new SparseIntArray();
        this.f8988Z = new SparseIntArray();
        this.f8989a0 = new R0(24);
        this.f8990b0 = new Rect();
        this.f8991c0 = -1;
        this.f8992d0 = -1;
        this.f8993e0 = -1;
        R1(i);
    }

    public GridLayoutManager() {
        super(1);
        this.f8984U = false;
        this.f8985V = -1;
        this.f8987Y = new SparseIntArray();
        this.f8988Z = new SparseIntArray();
        this.f8989a0 = new R0(24);
        this.f8990b0 = new Rect();
        this.f8991c0 = -1;
        this.f8992d0 = -1;
        this.f8993e0 = -1;
        R1(6);
    }
}
