package androidx.recyclerview.widget;

import android.content.Context;
import android.graphics.Rect;
import android.util.AttributeSet;
import android.util.SparseIntArray;
import android.view.View;
import android.view.ViewGroup;
import android.widget.GridView;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import defpackage.i3;
import defpackage.n41;
import defpackage.vw2;
import java.util.Arrays;

/* JADX INFO: loaded from: classes.dex */
public class GridLayoutManager extends LinearLayoutManager {
    public boolean a;
    public int b;
    public int[] c;
    public View[] d;
    public final SparseIntArray e;
    public final SparseIntArray f;
    public c i;
    public final Rect j;

    public static final class a extends c {
        @Override // androidx.recyclerview.widget.GridLayoutManager.c
        public final int b(int i, int i2) {
            return i % i2;
        }

        @Override // androidx.recyclerview.widget.GridLayoutManager.c
        public final int c(int i) {
            return 1;
        }
    }

    public static class b extends RecyclerView.p {
        public int e;
        public int f;

        public b(int i, int i2) {
            super(i, i2);
            this.e = -1;
            this.f = 0;
        }
    }

    public static abstract class c {
        public final SparseIntArray a = new SparseIntArray();
        public final SparseIntArray b = new SparseIntArray();

        public final int a(int i, int i2) {
            int iC = c(i);
            int i3 = 0;
            int i4 = 0;
            for (int i5 = 0; i5 < i; i5++) {
                int iC2 = c(i5);
                i3 += iC2;
                if (i3 == i2) {
                    i4++;
                    i3 = 0;
                } else if (i3 > i2) {
                    i4++;
                    i3 = iC2;
                }
            }
            return i3 + iC > i2 ? i4 + 1 : i4;
        }

        public int b(int i, int i2) {
            int iC = c(i);
            if (iC == i2) {
                return 0;
            }
            int i3 = 0;
            for (int i4 = 0; i4 < i; i4++) {
                int iC2 = c(i4);
                i3 += iC2;
                if (i3 == i2) {
                    i3 = 0;
                } else if (i3 > i2) {
                    i3 = iC2;
                }
            }
            if (iC + i3 <= i2) {
                return i3;
            }
            return 0;
        }

        public abstract int c(int i);

        public final void d() {
            this.a.clear();
        }
    }

    public GridLayoutManager(Context context, AttributeSet attributeSet, int i, int i2) {
        super(context, attributeSet, i, i2);
        this.a = false;
        this.b = -1;
        this.e = new SparseIntArray();
        this.f = new SparseIntArray();
        this.i = new a();
        this.j = new Rect();
        ag(RecyclerView.o.getProperties(context, attributeSet, i, i2).b);
    }

    public final void aa() {
        View[] viewArr = this.d;
        if (viewArr == null || viewArr.length != this.b) {
            this.d = new View[this.b];
        }
    }

    public final int ab(int i, int i2) {
        if (this.mOrientation != 1 || !isLayoutRTL()) {
            int[] iArr = this.c;
            return iArr[i2 + i] - iArr[i];
        }
        int[] iArr2 = this.c;
        int i3 = this.b;
        return iArr2[i3 - i] - iArr2[(i3 - i) - i2];
    }

    public final int ac(int i, RecyclerView.w wVar, RecyclerView.ac acVar) {
        if (!acVar.g) {
            return this.i.a(i, this.b);
        }
        int iB = wVar.b(i);
        if (iB != -1) {
            return this.i.a(iB, this.b);
        }
        n41.x(i, "Cannot find span size for pre layout position. ", "GridLayoutManager");
        return 0;
    }

    public final int ad(int i, RecyclerView.w wVar, RecyclerView.ac acVar) {
        if (!acVar.g) {
            return this.i.b(i, this.b);
        }
        int i2 = this.f.get(i, -1);
        if (i2 != -1) {
            return i2;
        }
        int iB = wVar.b(i);
        if (iB != -1) {
            return this.i.b(iB, this.b);
        }
        n41.x(i, "Cannot find span size for pre layout position. It is not cached, not in the adapter. Pos:", "GridLayoutManager");
        return 0;
    }

    public final int ae(int i, RecyclerView.w wVar, RecyclerView.ac acVar) {
        if (!acVar.g) {
            return this.i.c(i);
        }
        int i2 = this.e.get(i, -1);
        if (i2 != -1) {
            return i2;
        }
        int iB = wVar.b(i);
        if (iB != -1) {
            return this.i.c(iB);
        }
        n41.x(i, "Cannot find span size for pre layout position. It is not cached, not in the adapter. Pos:", "GridLayoutManager");
        return 1;
    }

    public final void af(View view, int i, boolean z) {
        int childMeasureSpec;
        int childMeasureSpec2;
        b bVar = (b) view.getLayoutParams();
        Rect rect = bVar.b;
        int i2 = rect.top + rect.bottom + ((ViewGroup.MarginLayoutParams) bVar).topMargin + ((ViewGroup.MarginLayoutParams) bVar).bottomMargin;
        int i3 = rect.left + rect.right + ((ViewGroup.MarginLayoutParams) bVar).leftMargin + ((ViewGroup.MarginLayoutParams) bVar).rightMargin;
        int iAb = ab(bVar.e, bVar.f);
        if (this.mOrientation == 1) {
            childMeasureSpec2 = RecyclerView.o.getChildMeasureSpec(iAb, i, i3, ((ViewGroup.MarginLayoutParams) bVar).width, false);
            childMeasureSpec = RecyclerView.o.getChildMeasureSpec(this.mOrientationHelper.n(), getHeightMode(), i2, ((ViewGroup.MarginLayoutParams) bVar).height, true);
        } else {
            int childMeasureSpec3 = RecyclerView.o.getChildMeasureSpec(iAb, i, i2, ((ViewGroup.MarginLayoutParams) bVar).height, false);
            int childMeasureSpec4 = RecyclerView.o.getChildMeasureSpec(this.mOrientationHelper.n(), getWidthMode(), i3, ((ViewGroup.MarginLayoutParams) bVar).width, true);
            childMeasureSpec = childMeasureSpec3;
            childMeasureSpec2 = childMeasureSpec4;
        }
        RecyclerView.p pVar = (RecyclerView.p) view.getLayoutParams();
        if (z ? shouldReMeasureChild(view, childMeasureSpec2, childMeasureSpec, pVar) : shouldMeasureChild(view, childMeasureSpec2, childMeasureSpec, pVar)) {
            view.measure(childMeasureSpec2, childMeasureSpec);
        }
    }

    public final void ag(int i) {
        if (i == this.b) {
            return;
        }
        this.a = true;
        if (i < 1) {
            throw new IllegalArgumentException(n41.k("Span count should be at least 1. Provided ", i));
        }
        this.b = i;
        this.i.d();
        requestLayout();
    }

    public final void ah() {
        int height;
        int paddingTop;
        if (getOrientation() == 1) {
            height = getWidth() - getPaddingRight();
            paddingTop = getPaddingLeft();
        } else {
            height = getHeight() - getPaddingBottom();
            paddingTop = getPaddingTop();
        }
        z(height - paddingTop);
    }

    @Override // androidx.recyclerview.widget.RecyclerView.o
    public final boolean checkLayoutParams(RecyclerView.p pVar) {
        return pVar instanceof b;
    }

    @Override // androidx.recyclerview.widget.LinearLayoutManager
    public final void collectPrefetchPositionsForLayoutState(RecyclerView.ac acVar, LinearLayoutManager.c cVar, RecyclerView.o.c cVar2) {
        int i;
        int iC = this.b;
        for (int i2 = 0; i2 < this.b && (i = cVar.d) >= 0 && i < acVar.b() && iC > 0; i2++) {
            int i3 = cVar.d;
            cVar2.a(i3, Math.max(0, cVar.g));
            iC -= this.i.c(i3);
            cVar.d += cVar.e;
        }
    }

    @Override // androidx.recyclerview.widget.LinearLayoutManager
    public final View findReferenceChild(RecyclerView.w wVar, RecyclerView.ac acVar, boolean z, boolean z2) {
        int i;
        int childCount;
        int childCount2 = getChildCount();
        int i2 = 1;
        if (z2) {
            childCount = getChildCount() - 1;
            i = -1;
            i2 = -1;
        } else {
            i = childCount2;
            childCount = 0;
        }
        int iB = acVar.b();
        ensureLayoutState();
        int iM = this.mOrientationHelper.m();
        int i3 = this.mOrientationHelper.i();
        View view = null;
        View view2 = null;
        while (childCount != i) {
            View childAt = getChildAt(childCount);
            int position = getPosition(childAt);
            if (position >= 0 && position < iB && ad(position, wVar, acVar) == 0) {
                if (((RecyclerView.p) childAt.getLayoutParams()).a.isRemoved()) {
                    if (view2 == null) {
                        view2 = childAt;
                    }
                } else {
                    if (this.mOrientationHelper.g(childAt) < i3 && this.mOrientationHelper.d(childAt) >= iM) {
                        return childAt;
                    }
                    if (view == null) {
                        view = childAt;
                    }
                }
            }
            childCount += i2;
        }
        return view != null ? view : view2;
    }

    @Override // androidx.recyclerview.widget.LinearLayoutManager, androidx.recyclerview.widget.RecyclerView.o
    public final RecyclerView.p generateDefaultLayoutParams() {
        return this.mOrientation == 0 ? new b(-2, -1) : new b(-1, -2);
    }

    @Override // androidx.recyclerview.widget.RecyclerView.o
    public final RecyclerView.p generateLayoutParams(Context context, AttributeSet attributeSet) {
        b bVar = new b(context, attributeSet);
        bVar.e = -1;
        bVar.f = 0;
        return bVar;
    }

    @Override // androidx.recyclerview.widget.RecyclerView.o
    public final int getColumnCountForAccessibility(RecyclerView.w wVar, RecyclerView.ac acVar) {
        if (this.mOrientation == 1) {
            return this.b;
        }
        if (acVar.b() < 1) {
            return 0;
        }
        return ac(acVar.b() - 1, wVar, acVar) + 1;
    }

    @Override // androidx.recyclerview.widget.RecyclerView.o
    public final int getRowCountForAccessibility(RecyclerView.w wVar, RecyclerView.ac acVar) {
        if (this.mOrientation == 0) {
            return this.b;
        }
        if (acVar.b() < 1) {
            return 0;
        }
        return ac(acVar.b() - 1, wVar, acVar) + 1;
    }

    @Override // androidx.recyclerview.widget.LinearLayoutManager
    public final void layoutChunk(RecyclerView.w wVar, RecyclerView.ac acVar, LinearLayoutManager.c cVar, LinearLayoutManager.b bVar) {
        int i;
        int i2;
        int i3;
        int iF;
        int paddingLeft;
        int paddingTop;
        int iF2;
        int childMeasureSpec;
        int childMeasureSpec2;
        boolean z;
        int i4;
        View viewB;
        int iL = this.mOrientationHelper.l();
        boolean z2 = iL != 1073741824;
        int i5 = getChildCount() > 0 ? this.c[this.b] : 0;
        if (z2) {
            ah();
        }
        boolean z3 = cVar.e == 1;
        int iAd = this.b;
        if (!z3) {
            iAd = ad(cVar.d, wVar, acVar) + ae(cVar.d, wVar, acVar);
        }
        int i6 = 0;
        while (i6 < this.b && (i4 = cVar.d) >= 0 && i4 < acVar.b() && iAd > 0) {
            int i7 = cVar.d;
            int iAe = ae(i7, wVar, acVar);
            if (iAe > this.b) {
                throw new IllegalArgumentException(n41.q(vw2.r("Item at position ", i7, " requires ", " spans but GridLayoutManager has only ", iAe), this.b, " spans."));
            }
            iAd -= iAe;
            if (iAd < 0 || (viewB = cVar.b(wVar)) == null) {
                break;
            }
            this.d[i6] = viewB;
            i6++;
        }
        if (i6 == 0) {
            bVar.b = true;
            return;
        }
        if (z3) {
            i3 = 1;
            i2 = i6;
            i = 0;
        } else {
            i = i6 - 1;
            i2 = -1;
            i3 = -1;
        }
        int i8 = 0;
        while (i != i2) {
            View view = this.d[i];
            b bVar2 = (b) view.getLayoutParams();
            int iAe2 = ae(getPosition(view), wVar, acVar);
            bVar2.f = iAe2;
            bVar2.e = i8;
            i8 += iAe2;
            i += i3;
        }
        float f = 0.0f;
        int i9 = 0;
        for (int i10 = 0; i10 < i6; i10++) {
            View view2 = this.d[i10];
            if (cVar.k != null) {
                z = false;
                if (z3) {
                    addDisappearingView(view2);
                } else {
                    addDisappearingView(view2, 0);
                }
            } else if (z3) {
                addView(view2);
                z = false;
            } else {
                z = false;
                addView(view2, 0);
            }
            calculateItemDecorationsForChild(view2, this.j);
            af(view2, iL, z);
            int iE = this.mOrientationHelper.e(view2);
            if (iE > i9) {
                i9 = iE;
            }
            float f2 = (this.mOrientationHelper.f(view2) * 1.0f) / ((b) view2.getLayoutParams()).f;
            if (f2 > f) {
                f = f2;
            }
        }
        if (z2) {
            z(Math.max(Math.round(f * this.b), i5));
            i9 = 0;
            for (int i11 = 0; i11 < i6; i11++) {
                View view3 = this.d[i11];
                af(view3, 1073741824, true);
                int iE2 = this.mOrientationHelper.e(view3);
                if (iE2 > i9) {
                    i9 = iE2;
                }
            }
        }
        for (int i12 = 0; i12 < i6; i12++) {
            View view4 = this.d[i12];
            if (this.mOrientationHelper.e(view4) != i9) {
                b bVar3 = (b) view4.getLayoutParams();
                Rect rect = bVar3.b;
                int i13 = rect.top + rect.bottom + ((ViewGroup.MarginLayoutParams) bVar3).topMargin + ((ViewGroup.MarginLayoutParams) bVar3).bottomMargin;
                int i14 = rect.left + rect.right + ((ViewGroup.MarginLayoutParams) bVar3).leftMargin + ((ViewGroup.MarginLayoutParams) bVar3).rightMargin;
                int iAb = ab(bVar3.e, bVar3.f);
                if (this.mOrientation == 1) {
                    childMeasureSpec2 = RecyclerView.o.getChildMeasureSpec(iAb, 1073741824, i14, ((ViewGroup.MarginLayoutParams) bVar3).width, false);
                    childMeasureSpec = View.MeasureSpec.makeMeasureSpec(i9 - i13, 1073741824);
                } else {
                    int iMakeMeasureSpec = View.MeasureSpec.makeMeasureSpec(i9 - i14, 1073741824);
                    childMeasureSpec = RecyclerView.o.getChildMeasureSpec(iAb, 1073741824, i13, ((ViewGroup.MarginLayoutParams) bVar3).height, false);
                    childMeasureSpec2 = iMakeMeasureSpec;
                }
                if (shouldReMeasureChild(view4, childMeasureSpec2, childMeasureSpec, (RecyclerView.p) view4.getLayoutParams())) {
                    view4.measure(childMeasureSpec2, childMeasureSpec);
                }
            }
        }
        bVar.a = i9;
        if (this.mOrientation != 1) {
            if (cVar.f == -1) {
                int i15 = cVar.b;
                paddingLeft = i15 - i9;
                iF = i15;
            } else {
                int i16 = cVar.b;
                iF = i16 + i9;
                paddingLeft = i16;
            }
            paddingTop = 0;
            iF2 = 0;
        } else if (cVar.f == -1) {
            iF2 = cVar.b;
            paddingTop = iF2 - i9;
            paddingLeft = 0;
            iF = 0;
        } else {
            int i17 = cVar.b;
            paddingTop = i17;
            iF = 0;
            iF2 = i17 + i9;
            paddingLeft = 0;
        }
        for (int i18 = 0; i18 < i6; i18++) {
            View view5 = this.d[i18];
            b bVar4 = (b) view5.getLayoutParams();
            if (this.mOrientation != 1) {
                paddingTop = getPaddingTop() + this.c[bVar4.e];
                iF2 = this.mOrientationHelper.f(view5) + paddingTop;
            } else if (isLayoutRTL()) {
                iF = this.c[this.b - bVar4.e] + getPaddingLeft();
                paddingLeft = iF - this.mOrientationHelper.f(view5);
            } else {
                paddingLeft = getPaddingLeft() + this.c[bVar4.e];
                iF = this.mOrientationHelper.f(view5) + paddingLeft;
            }
            int i19 = iF;
            int i20 = paddingLeft;
            int i21 = iF2;
            layoutDecoratedWithMargins(view5, i20, paddingTop, i19, i21);
            paddingLeft = i20;
            iF = i19;
            iF2 = i21;
            if (bVar4.a.isRemoved() || bVar4.a.isUpdated()) {
                bVar.c = true;
            }
            bVar.d = view5.hasFocusable() | bVar.d;
        }
        Arrays.fill(this.d, (Object) null);
    }

    @Override // androidx.recyclerview.widget.LinearLayoutManager
    public final void onAnchorReady(RecyclerView.w wVar, RecyclerView.ac acVar, LinearLayoutManager.a aVar, int i) {
        super.onAnchorReady(wVar, acVar, aVar, i);
        ah();
        if (acVar.b() > 0 && !acVar.g) {
            boolean z = i == 1;
            int iAd = ad(aVar.b, wVar, acVar);
            if (z) {
                while (iAd > 0) {
                    int i2 = aVar.b;
                    if (i2 <= 0) {
                        break;
                    }
                    int i3 = i2 - 1;
                    aVar.b = i3;
                    iAd = ad(i3, wVar, acVar);
                }
            } else {
                int iB = acVar.b() - 1;
                int i4 = aVar.b;
                while (i4 < iB) {
                    int i5 = i4 + 1;
                    int iAd2 = ad(i5, wVar, acVar);
                    if (iAd2 <= iAd) {
                        break;
                    }
                    i4 = i5;
                    iAd = iAd2;
                }
                aVar.b = i4;
            }
        }
        aa();
    }

    /* JADX WARN: Code restructure failed: missing block: B:56:0x00d3, code lost:
    
        if (r13 == (r2 > r15)) goto L47;
     */
    /* JADX WARN: Removed duplicated region for block: B:72:0x00fb  */
    /* JADX WARN: Removed duplicated region for block: B:73:0x0111  */
    @Override // androidx.recyclerview.widget.LinearLayoutManager, androidx.recyclerview.widget.RecyclerView.o
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public View onFocusSearchFailed(View view, int i, RecyclerView.w wVar, RecyclerView.ac acVar) {
        int childCount;
        int i2;
        int childCount2;
        View view2;
        View view3;
        View view4;
        int i3;
        int i4;
        int i5;
        RecyclerView.w wVar2 = wVar;
        RecyclerView.ac acVar2 = acVar;
        View viewFindContainingItemView = findContainingItemView(view);
        View view5 = null;
        if (viewFindContainingItemView == null) {
            return null;
        }
        b bVar = (b) viewFindContainingItemView.getLayoutParams();
        int i6 = bVar.e;
        int i7 = bVar.f + i6;
        if (super.onFocusSearchFailed(view, i, wVar, acVar) == null) {
            return null;
        }
        if ((convertFocusDirectionToLayoutDirection(i) == 1) != this.mShouldReverseLayout) {
            childCount2 = getChildCount() - 1;
            childCount = -1;
            i2 = -1;
        } else {
            childCount = getChildCount();
            i2 = 1;
            childCount2 = 0;
        }
        boolean z = this.mOrientation == 1 && isLayoutRTL();
        int iAc = ac(childCount2, wVar2, acVar2);
        int i8 = -1;
        int i9 = -1;
        int iMin = 0;
        int iMin2 = 0;
        int i10 = childCount2;
        View view6 = null;
        while (i10 != childCount) {
            int iAc2 = ac(i10, wVar2, acVar2);
            View childAt = getChildAt(i10);
            if (childAt == viewFindContainingItemView) {
                break;
            }
            if (!childAt.hasFocusable() || iAc2 == iAc) {
                b bVar2 = (b) childAt.getLayoutParams();
                int i11 = bVar2.e;
                view2 = viewFindContainingItemView;
                int i12 = bVar2.f + i11;
                if (childAt.hasFocusable() && i11 == i6 && i12 == i7) {
                    return childAt;
                }
                if (!(childAt.hasFocusable() && view5 == null) && (childAt.hasFocusable() || view6 != null)) {
                    view3 = view5;
                    int iMin3 = Math.min(i12, i7) - Math.max(i11, i6);
                    if (!childAt.hasFocusable()) {
                        if (view3 == null) {
                            view4 = view6;
                            i3 = iMin;
                            if (isViewPartiallyVisible(childAt, false, true)) {
                                i4 = iMin2;
                                if (iMin3 > i4) {
                                    i5 = i9;
                                } else if (iMin3 == i4) {
                                    i5 = i9;
                                    if (z == (i11 > i5)) {
                                    }
                                    iMin = i3;
                                    view5 = view3;
                                    i10 += i2;
                                    wVar2 = wVar;
                                    acVar2 = acVar;
                                    viewFindContainingItemView = view2;
                                } else {
                                    i5 = i9;
                                }
                                if (childAt.hasFocusable()) {
                                    int i13 = bVar2.e;
                                    iMin2 = Math.min(i12, i7) - Math.max(i11, i6);
                                    view6 = childAt;
                                    i9 = i13;
                                    iMin = i3;
                                    view5 = view3;
                                    i10 += i2;
                                    wVar2 = wVar;
                                    acVar2 = acVar;
                                    viewFindContainingItemView = view2;
                                } else {
                                    i9 = i5;
                                    iMin2 = i4;
                                    i8 = bVar2.e;
                                    view6 = view4;
                                    view5 = childAt;
                                    iMin = Math.min(i12, i7) - Math.max(i11, i6);
                                    i10 += i2;
                                    wVar2 = wVar;
                                    acVar2 = acVar;
                                    viewFindContainingItemView = view2;
                                }
                            }
                            i9 = i5;
                            iMin2 = i4;
                            view6 = view4;
                            iMin = i3;
                            view5 = view3;
                            i10 += i2;
                            wVar2 = wVar;
                            acVar2 = acVar;
                            viewFindContainingItemView = view2;
                        }
                        i5 = i9;
                        i4 = iMin2;
                        i9 = i5;
                        iMin2 = i4;
                        view6 = view4;
                        iMin = i3;
                        view5 = view3;
                        i10 += i2;
                        wVar2 = wVar;
                        acVar2 = acVar;
                        viewFindContainingItemView = view2;
                    } else if (iMin3 <= iMin) {
                        if (iMin3 == iMin) {
                        }
                    }
                } else {
                    view3 = view5;
                }
                view4 = view6;
                i3 = iMin;
                i5 = i9;
                i4 = iMin2;
                if (childAt.hasFocusable()) {
                }
            } else {
                if (view5 != null) {
                    break;
                }
                view2 = viewFindContainingItemView;
                view3 = view5;
            }
            view4 = view6;
            i3 = iMin;
            i5 = i9;
            i4 = iMin2;
            i9 = i5;
            iMin2 = i4;
            view6 = view4;
            iMin = i3;
            view5 = view3;
            i10 += i2;
            wVar2 = wVar;
            acVar2 = acVar;
            viewFindContainingItemView = view2;
        }
        View view7 = view5;
        return view7 != null ? view7 : view6;
    }

    @Override // androidx.recyclerview.widget.RecyclerView.o
    public final void onInitializeAccessibilityNodeInfo(RecyclerView.w wVar, RecyclerView.ac acVar, i3 i3Var) {
        super.onInitializeAccessibilityNodeInfo(wVar, acVar, i3Var);
        i3Var.i(GridView.class.getName());
    }

    @Override // androidx.recyclerview.widget.RecyclerView.o
    public final void onInitializeAccessibilityNodeInfoForItem(RecyclerView.w wVar, RecyclerView.ac acVar, View view, i3 i3Var) {
        ViewGroup.LayoutParams layoutParams = view.getLayoutParams();
        if (!(layoutParams instanceof b)) {
            super.onInitializeAccessibilityNodeInfoForItem(view, i3Var);
            return;
        }
        b bVar = (b) layoutParams;
        int iAc = ac(bVar.a.getLayoutPosition(), wVar, acVar);
        if (this.mOrientation == 0) {
            i3Var.k(i3.h.a(bVar.e, bVar.f, iAc, 1, false, false));
        } else {
            i3Var.k(i3.h.a(iAc, 1, bVar.e, bVar.f, false, false));
        }
    }

    @Override // androidx.recyclerview.widget.RecyclerView.o
    public final void onItemsAdded(RecyclerView recyclerView, int i, int i2) {
        this.i.d();
        this.i.b.clear();
    }

    @Override // androidx.recyclerview.widget.RecyclerView.o
    public final void onItemsChanged(RecyclerView recyclerView) {
        this.i.d();
        this.i.b.clear();
    }

    @Override // androidx.recyclerview.widget.RecyclerView.o
    public final void onItemsMoved(RecyclerView recyclerView, int i, int i2, int i3) {
        this.i.d();
        this.i.b.clear();
    }

    @Override // androidx.recyclerview.widget.RecyclerView.o
    public final void onItemsRemoved(RecyclerView recyclerView, int i, int i2) {
        this.i.d();
        this.i.b.clear();
    }

    @Override // androidx.recyclerview.widget.RecyclerView.o
    public final void onItemsUpdated(RecyclerView recyclerView, int i, int i2, Object obj) {
        this.i.d();
        this.i.b.clear();
    }

    @Override // androidx.recyclerview.widget.LinearLayoutManager, androidx.recyclerview.widget.RecyclerView.o
    public final void onLayoutChildren(RecyclerView.w wVar, RecyclerView.ac acVar) {
        boolean z = acVar.g;
        SparseIntArray sparseIntArray = this.f;
        SparseIntArray sparseIntArray2 = this.e;
        if (z) {
            int childCount = getChildCount();
            for (int i = 0; i < childCount; i++) {
                b bVar = (b) getChildAt(i).getLayoutParams();
                int layoutPosition = bVar.a.getLayoutPosition();
                sparseIntArray2.put(layoutPosition, bVar.f);
                sparseIntArray.put(layoutPosition, bVar.e);
            }
        }
        super.onLayoutChildren(wVar, acVar);
        sparseIntArray2.clear();
        sparseIntArray.clear();
    }

    @Override // androidx.recyclerview.widget.LinearLayoutManager, androidx.recyclerview.widget.RecyclerView.o
    public final void onLayoutCompleted(RecyclerView.ac acVar) {
        super.onLayoutCompleted(acVar);
        this.a = false;
    }

    @Override // androidx.recyclerview.widget.LinearLayoutManager, androidx.recyclerview.widget.RecyclerView.o
    public final int scrollHorizontallyBy(int i, RecyclerView.w wVar, RecyclerView.ac acVar) {
        ah();
        aa();
        return super.scrollHorizontallyBy(i, wVar, acVar);
    }

    @Override // androidx.recyclerview.widget.LinearLayoutManager, androidx.recyclerview.widget.RecyclerView.o
    public final int scrollVerticallyBy(int i, RecyclerView.w wVar, RecyclerView.ac acVar) {
        ah();
        aa();
        return super.scrollVerticallyBy(i, wVar, acVar);
    }

    @Override // androidx.recyclerview.widget.RecyclerView.o
    public final void setMeasuredDimension(Rect rect, int i, int i2) {
        int iChooseSize;
        int iChooseSize2;
        if (this.c == null) {
            super.setMeasuredDimension(rect, i, i2);
        }
        int paddingRight = getPaddingRight() + getPaddingLeft();
        int paddingBottom = getPaddingBottom() + getPaddingTop();
        if (this.mOrientation == 1) {
            iChooseSize2 = RecyclerView.o.chooseSize(i2, rect.height() + paddingBottom, getMinimumHeight());
            int[] iArr = this.c;
            iChooseSize = RecyclerView.o.chooseSize(i, iArr[iArr.length - 1] + paddingRight, getMinimumWidth());
        } else {
            iChooseSize = RecyclerView.o.chooseSize(i, rect.width() + paddingRight, getMinimumWidth());
            int[] iArr2 = this.c;
            iChooseSize2 = RecyclerView.o.chooseSize(i2, iArr2[iArr2.length - 1] + paddingBottom, getMinimumHeight());
        }
        setMeasuredDimension(iChooseSize, iChooseSize2);
    }

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

    @Override // androidx.recyclerview.widget.LinearLayoutManager, androidx.recyclerview.widget.RecyclerView.o
    public final boolean supportsPredictiveItemAnimations() {
        return this.mPendingSavedState == null && !this.a;
    }

    public final void z(int i) {
        int i2;
        int[] iArr = this.c;
        int i3 = this.b;
        if (iArr == null || iArr.length != i3 + 1 || iArr[iArr.length - 1] != i) {
            iArr = new int[i3 + 1];
        }
        int i4 = 0;
        iArr[0] = 0;
        int i5 = i / i3;
        int i6 = i % i3;
        int i7 = 0;
        for (int i8 = 1; i8 <= i3; i8++) {
            i4 += i6;
            if (i4 <= 0 || i3 - i4 >= i6) {
                i2 = i5;
            } else {
                i2 = i5 + 1;
                i4 -= i3;
            }
            i7 += i2;
            iArr[i8] = i7;
        }
        this.c = iArr;
    }

    @Override // androidx.recyclerview.widget.RecyclerView.o
    public final RecyclerView.p generateLayoutParams(ViewGroup.LayoutParams layoutParams) {
        if (layoutParams instanceof ViewGroup.MarginLayoutParams) {
            b bVar = new b((ViewGroup.MarginLayoutParams) layoutParams);
            bVar.e = -1;
            bVar.f = 0;
            return bVar;
        }
        b bVar2 = new b(layoutParams);
        bVar2.e = -1;
        bVar2.f = 0;
        return bVar2;
    }

    public GridLayoutManager(int i) {
        this.a = false;
        this.b = -1;
        this.e = new SparseIntArray();
        this.f = new SparseIntArray();
        this.i = new a();
        this.j = new Rect();
        ag(i);
    }

    public GridLayoutManager(int i, int i2) {
        super(1, false);
        this.a = false;
        this.b = -1;
        this.e = new SparseIntArray();
        this.f = new SparseIntArray();
        this.i = new a();
        this.j = new Rect();
        ag(i);
    }
}
