package androidx.recyclerview.widget;

import android.annotation.SuppressLint;
import android.content.Context;
import android.graphics.PointF;
import android.os.Parcel;
import android.os.Parcelable;
import android.util.AttributeSet;
import android.view.View;
import android.view.accessibility.AccessibilityEvent;
import androidx.recyclerview.widget.RecyclerView;
import androidx.recyclerview.widget.x;
import defpackage.m38;
import defpackage.n41;
import defpackage.vo6;
import java.util.List;

/* JADX INFO: loaded from: classes.dex */
public class LinearLayoutManager extends RecyclerView.o implements x.g, RecyclerView.ab.b {
    static final boolean DEBUG = false;
    public static final int HORIZONTAL = 0;
    public static final int INVALID_OFFSET = Integer.MIN_VALUE;
    private static final float MAX_SCROLL_FACTOR = 0.33333334f;
    private static final String TAG = "LinearLayoutManager";
    public static final int VERTICAL = 1;
    final a mAnchorInfo;
    private int mInitialPrefetchItemCount;
    private boolean mLastStackFromEnd;
    private final b mLayoutChunkResult;
    private c mLayoutState;
    int mOrientation;
    ak mOrientationHelper;
    d mPendingSavedState;
    int mPendingScrollPosition;
    int mPendingScrollPositionOffset;
    private boolean mRecycleChildrenOnDetach;
    private int[] mReusableIntPair;
    private boolean mReverseLayout;
    boolean mShouldReverseLayout;
    private boolean mSmoothScrollbarEnabled;
    private boolean mStackFromEnd;

    public static class a {
        public ak a;
        public int b;
        public int c;
        public boolean d;
        public boolean e;

        public a() {
            d();
        }

        public final void a() {
            this.c = this.d ? this.a.i() : this.a.m();
        }

        public final void b(int i, View view) {
            if (this.d) {
                this.c = this.a.o() + this.a.d(view);
            } else {
                this.c = this.a.g(view);
            }
            this.b = i;
        }

        public final void c(int i, View view) {
            int iO = this.a.o();
            if (iO >= 0) {
                b(i, view);
                return;
            }
            this.b = i;
            if (!this.d) {
                int iG = this.a.g(view);
                int iM = iG - this.a.m();
                this.c = iG;
                if (iM > 0) {
                    int i2 = (this.a.i() - Math.min(0, (this.a.i() - iO) - this.a.d(view))) - (this.a.e(view) + iG);
                    if (i2 < 0) {
                        this.c -= Math.min(iM, -i2);
                        return;
                    }
                    return;
                }
                return;
            }
            int i3 = (this.a.i() - iO) - this.a.d(view);
            this.c = this.a.i() - i3;
            if (i3 > 0) {
                int iE = this.c - this.a.e(view);
                int iM2 = this.a.m();
                int iMin = iE - (Math.min(this.a.g(view) - iM2, 0) + iM2);
                if (iMin < 0) {
                    this.c = Math.min(i3, -iMin) + this.c;
                }
            }
        }

        public final void d() {
            this.b = -1;
            this.c = Integer.MIN_VALUE;
            this.d = false;
            this.e = false;
        }

        public final String toString() {
            return "AnchorInfo{mPosition=" + this.b + ", mCoordinate=" + this.c + ", mLayoutFromEnd=" + this.d + ", mValid=" + this.e + '}';
        }
    }

    public static class b {
        public int a;
        public boolean b;
        public boolean c;
        public boolean d;
    }

    public static class c {
        public boolean a;
        public int b;
        public int c;
        public int d;
        public int e;
        public int f;
        public int g;
        public int h;
        public int i;
        public int j;
        public List k;
        public boolean l;

        public final void a(View view) {
            int layoutPosition;
            int size = this.k.size();
            View view2 = null;
            int i = Integer.MAX_VALUE;
            for (int i2 = 0; i2 < size; i2++) {
                View view3 = ((RecyclerView.ag) this.k.get(i2)).itemView;
                RecyclerView.p pVar = (RecyclerView.p) view3.getLayoutParams();
                if (view3 != view && !pVar.a.isRemoved() && (layoutPosition = (pVar.a.getLayoutPosition() - this.d) * this.e) >= 0 && layoutPosition < i) {
                    view2 = view3;
                    if (layoutPosition == 0) {
                        break;
                    } else {
                        i = layoutPosition;
                    }
                }
            }
            if (view2 == null) {
                this.d = -1;
            } else {
                this.d = ((RecyclerView.p) view2.getLayoutParams()).a.getLayoutPosition();
            }
        }

        public final View b(RecyclerView.w wVar) {
            List list = this.k;
            if (list == null) {
                View viewD = wVar.d(this.d);
                this.d += this.e;
                return viewD;
            }
            int size = list.size();
            for (int i = 0; i < size; i++) {
                View view = ((RecyclerView.ag) this.k.get(i)).itemView;
                RecyclerView.p pVar = (RecyclerView.p) view.getLayoutParams();
                if (!pVar.a.isRemoved() && this.d == pVar.a.getLayoutPosition()) {
                    a(view);
                    return view;
                }
            }
            return null;
        }
    }

    @m38
    @SuppressLint({"BanParcelableUsage"})
    public static class d implements Parcelable {
        public static final Parcelable.Creator<d> CREATOR = new a();
        public int a;
        public int b;
        public boolean c;

        public class a implements Parcelable.Creator<d> {
            @Override // android.os.Parcelable.Creator
            public final d createFromParcel(Parcel parcel) {
                d dVar = new d();
                dVar.a = parcel.readInt();
                dVar.b = parcel.readInt();
                dVar.c = parcel.readInt() == 1;
                return dVar;
            }

            @Override // android.os.Parcelable.Creator
            public final d[] newArray(int i) {
                return new d[i];
            }
        }

        @Override // android.os.Parcelable
        public final int describeContents() {
            return 0;
        }

        @Override // android.os.Parcelable
        public final void writeToParcel(Parcel parcel, int i) {
            parcel.writeInt(this.a);
            parcel.writeInt(this.b);
            parcel.writeInt(this.c ? 1 : 0);
        }
    }

    public LinearLayoutManager() {
        this(1, false);
    }

    @Override // androidx.recyclerview.widget.RecyclerView.o
    @SuppressLint({"UnknownNullness"})
    public void assertNotInLayoutOrScroll(String str) {
        if (this.mPendingSavedState == null) {
            super.assertNotInLayoutOrScroll(str);
        }
    }

    public void calculateExtraLayoutSpace(@vo6 RecyclerView.ac acVar, @vo6 int[] iArr) {
        int i;
        int extraLayoutSpace = getExtraLayoutSpace(acVar);
        if (this.mLayoutState.f == -1) {
            i = 0;
        } else {
            i = extraLayoutSpace;
            extraLayoutSpace = 0;
        }
        iArr[0] = extraLayoutSpace;
        iArr[1] = i;
    }

    @Override // androidx.recyclerview.widget.RecyclerView.o
    public boolean canScrollHorizontally() {
        return this.mOrientation == 0;
    }

    @Override // androidx.recyclerview.widget.RecyclerView.o
    public boolean canScrollVertically() {
        return this.mOrientation == 1;
    }

    @Override // androidx.recyclerview.widget.RecyclerView.o
    @SuppressLint({"UnknownNullness"})
    public void collectAdjacentPrefetchPositions(int i, int i2, RecyclerView.ac acVar, RecyclerView.o.c cVar) {
        if (this.mOrientation != 0) {
            i = i2;
        }
        if (getChildCount() == 0 || i == 0) {
            return;
        }
        ensureLayoutState();
        w(i > 0 ? 1 : -1, Math.abs(i), true, acVar);
        collectPrefetchPositionsForLayoutState(acVar, this.mLayoutState, cVar);
    }

    @Override // androidx.recyclerview.widget.RecyclerView.o
    @SuppressLint({"UnknownNullness"})
    public void collectInitialPrefetchPositions(int i, RecyclerView.o.c cVar) {
        boolean z;
        int i2;
        d dVar = this.mPendingSavedState;
        if (dVar == null || (i2 = dVar.a) < 0) {
            v();
            z = this.mShouldReverseLayout;
            i2 = this.mPendingScrollPosition;
            if (i2 == -1) {
                i2 = z ? i - 1 : 0;
            }
        } else {
            z = dVar.c;
        }
        int i3 = z ? -1 : 1;
        for (int i4 = 0; i4 < this.mInitialPrefetchItemCount && i2 >= 0 && i2 < i; i4++) {
            cVar.a(i2, 0);
            i2 += i3;
        }
    }

    public void collectPrefetchPositionsForLayoutState(RecyclerView.ac acVar, c cVar, RecyclerView.o.c cVar2) {
        int i = cVar.d;
        if (i < 0 || i >= acVar.b()) {
            return;
        }
        cVar2.a(i, Math.max(0, cVar.g));
    }

    @Override // androidx.recyclerview.widget.RecyclerView.o
    @SuppressLint({"UnknownNullness"})
    public int computeHorizontalScrollExtent(RecyclerView.ac acVar) {
        return n(acVar);
    }

    @Override // androidx.recyclerview.widget.RecyclerView.o
    @SuppressLint({"UnknownNullness"})
    public int computeHorizontalScrollOffset(RecyclerView.ac acVar) {
        return o(acVar);
    }

    @Override // androidx.recyclerview.widget.RecyclerView.o
    @SuppressLint({"UnknownNullness"})
    public int computeHorizontalScrollRange(RecyclerView.ac acVar) {
        return p(acVar);
    }

    @Override // androidx.recyclerview.widget.RecyclerView.ab.b
    @SuppressLint({"UnknownNullness"})
    public PointF computeScrollVectorForPosition(int i) {
        if (getChildCount() == 0) {
            return null;
        }
        int i2 = (i < getPosition(getChildAt(0))) != this.mShouldReverseLayout ? -1 : 1;
        return this.mOrientation == 0 ? new PointF(i2, 0.0f) : new PointF(0.0f, i2);
    }

    @Override // androidx.recyclerview.widget.RecyclerView.o
    @SuppressLint({"UnknownNullness"})
    public int computeVerticalScrollExtent(RecyclerView.ac acVar) {
        return n(acVar);
    }

    @Override // androidx.recyclerview.widget.RecyclerView.o
    @SuppressLint({"UnknownNullness"})
    public int computeVerticalScrollOffset(RecyclerView.ac acVar) {
        return o(acVar);
    }

    @Override // androidx.recyclerview.widget.RecyclerView.o
    @SuppressLint({"UnknownNullness"})
    public int computeVerticalScrollRange(RecyclerView.ac acVar) {
        return p(acVar);
    }

    public int convertFocusDirectionToLayoutDirection(int i) {
        return i != 1 ? i != 2 ? i != 17 ? i != 33 ? i != 66 ? (i == 130 && this.mOrientation == 1) ? 1 : Integer.MIN_VALUE : this.mOrientation == 0 ? 1 : Integer.MIN_VALUE : this.mOrientation == 1 ? -1 : Integer.MIN_VALUE : this.mOrientation == 0 ? -1 : Integer.MIN_VALUE : (this.mOrientation != 1 && isLayoutRTL()) ? -1 : 1 : (this.mOrientation != 1 && isLayoutRTL()) ? 1 : -1;
    }

    public c createLayoutState() {
        c cVar = new c();
        cVar.a = true;
        cVar.h = 0;
        cVar.i = 0;
        cVar.k = null;
        return cVar;
    }

    public void ensureLayoutState() {
        if (this.mLayoutState == null) {
            this.mLayoutState = createLayoutState();
        }
    }

    public int fill(RecyclerView.w wVar, c cVar, RecyclerView.ac acVar, boolean z) {
        int i;
        int i2 = cVar.c;
        int i3 = cVar.g;
        if (i3 != Integer.MIN_VALUE) {
            if (i2 < 0) {
                cVar.g = i3 + i2;
            }
            t(wVar, cVar);
        }
        int i4 = cVar.c + cVar.h;
        b bVar = this.mLayoutChunkResult;
        while (true) {
            if ((!cVar.l && i4 <= 0) || (i = cVar.d) < 0 || i >= acVar.b()) {
                break;
            }
            bVar.a = 0;
            bVar.b = false;
            bVar.c = false;
            bVar.d = false;
            layoutChunk(wVar, acVar, cVar, bVar);
            if (!bVar.b) {
                int i5 = cVar.b;
                int i6 = bVar.a;
                cVar.b = (cVar.f * i6) + i5;
                if (!bVar.c || cVar.k != null || !acVar.g) {
                    cVar.c -= i6;
                    i4 -= i6;
                }
                int i7 = cVar.g;
                if (i7 != Integer.MIN_VALUE) {
                    int i8 = i7 + i6;
                    cVar.g = i8;
                    int i9 = cVar.c;
                    if (i9 < 0) {
                        cVar.g = i8 + i9;
                    }
                    t(wVar, cVar);
                }
                if (z && bVar.d) {
                    break;
                }
            } else {
                break;
            }
        }
        return i2 - cVar.c;
    }

    public int findFirstCompletelyVisibleItemPosition() {
        View viewFindOneVisibleChild = findOneVisibleChild(0, getChildCount(), true, false);
        if (viewFindOneVisibleChild == null) {
            return -1;
        }
        return getPosition(viewFindOneVisibleChild);
    }

    public View findFirstVisibleChildClosestToEnd(boolean z, boolean z2) {
        return this.mShouldReverseLayout ? findOneVisibleChild(0, getChildCount(), z, z2) : findOneVisibleChild(getChildCount() - 1, -1, z, z2);
    }

    public View findFirstVisibleChildClosestToStart(boolean z, boolean z2) {
        return this.mShouldReverseLayout ? findOneVisibleChild(getChildCount() - 1, -1, z, z2) : findOneVisibleChild(0, getChildCount(), z, z2);
    }

    public int findFirstVisibleItemPosition() {
        View viewFindOneVisibleChild = findOneVisibleChild(0, getChildCount(), false, true);
        if (viewFindOneVisibleChild == null) {
            return -1;
        }
        return getPosition(viewFindOneVisibleChild);
    }

    public int findLastCompletelyVisibleItemPosition() {
        View viewFindOneVisibleChild = findOneVisibleChild(getChildCount() - 1, -1, true, false);
        if (viewFindOneVisibleChild == null) {
            return -1;
        }
        return getPosition(viewFindOneVisibleChild);
    }

    public int findLastVisibleItemPosition() {
        View viewFindOneVisibleChild = findOneVisibleChild(getChildCount() - 1, -1, false, true);
        if (viewFindOneVisibleChild == null) {
            return -1;
        }
        return getPosition(viewFindOneVisibleChild);
    }

    public View findOnePartiallyOrCompletelyInvisibleChild(int i, int i2) {
        int i3;
        int i4;
        ensureLayoutState();
        if (i2 <= i && i2 >= i) {
            return getChildAt(i);
        }
        if (this.mOrientationHelper.g(getChildAt(i)) < this.mOrientationHelper.m()) {
            i3 = 16644;
            i4 = 16388;
        } else {
            i3 = 4161;
            i4 = 4097;
        }
        return this.mOrientation == 0 ? this.mHorizontalBoundCheck.a(i, i2, i3, i4) : this.mVerticalBoundCheck.a(i, i2, i3, i4);
    }

    public View findOneVisibleChild(int i, int i2, boolean z, boolean z2) {
        ensureLayoutState();
        int i3 = z ? 24579 : 320;
        int i4 = z2 ? 320 : 0;
        return this.mOrientation == 0 ? this.mHorizontalBoundCheck.a(i, i2, i3, i4) : this.mVerticalBoundCheck.a(i, i2, i3, i4);
    }

    /* JADX WARN: Removed duplicated region for block: B:33:0x0075  */
    /* JADX WARN: Removed duplicated region for block: B:35:0x0079  */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public View findReferenceChild(RecyclerView.w wVar, RecyclerView.ac acVar, boolean z, boolean z2) {
        int i;
        int childCount;
        int i2;
        ensureLayoutState();
        int childCount2 = getChildCount();
        if (z2) {
            childCount = getChildCount() - 1;
            i = -1;
            i2 = -1;
        } else {
            i = childCount2;
            childCount = 0;
            i2 = 1;
        }
        int iB = acVar.b();
        int iM = this.mOrientationHelper.m();
        int i3 = this.mOrientationHelper.i();
        View view = null;
        View view2 = null;
        View view3 = null;
        while (childCount != i) {
            View childAt = getChildAt(childCount);
            int position = getPosition(childAt);
            int iG = this.mOrientationHelper.g(childAt);
            int iD = this.mOrientationHelper.d(childAt);
            if (position >= 0 && position < iB) {
                if (!((RecyclerView.p) childAt.getLayoutParams()).a.isRemoved()) {
                    boolean z3 = iD <= iM && iG < iM;
                    boolean z4 = iG >= i3 && iD > i3;
                    if (!z3 && !z4) {
                        return childAt;
                    }
                    if (z) {
                        if (z4) {
                            view2 = childAt;
                        } else if (view == null) {
                            view = childAt;
                        }
                    } else if (!z3) {
                        if (view == null) {
                        }
                    }
                } else if (view3 == null) {
                    view3 = childAt;
                }
            }
            childCount += i2;
        }
        return view != null ? view : view2 != null ? view2 : view3;
    }

    @Override // androidx.recyclerview.widget.RecyclerView.o
    @SuppressLint({"UnknownNullness"})
    public View findViewByPosition(int i) {
        int childCount = getChildCount();
        if (childCount == 0) {
            return null;
        }
        int position = i - getPosition(getChildAt(0));
        if (position >= 0 && position < childCount) {
            View childAt = getChildAt(position);
            if (getPosition(childAt) == i) {
                return childAt;
            }
        }
        return super.findViewByPosition(i);
    }

    @Override // androidx.recyclerview.widget.RecyclerView.o
    @SuppressLint({"UnknownNullness"})
    public RecyclerView.p generateDefaultLayoutParams() {
        return new RecyclerView.p(-2, -2);
    }

    public final View getChildClosestToEnd() {
        return getChildAt(this.mShouldReverseLayout ? 0 : getChildCount() - 1);
    }

    public final View getChildClosestToStart() {
        return getChildAt(this.mShouldReverseLayout ? getChildCount() - 1 : 0);
    }

    @Deprecated
    public int getExtraLayoutSpace(RecyclerView.ac acVar) {
        if (acVar.a != -1) {
            return this.mOrientationHelper.n();
        }
        return 0;
    }

    public int getInitialPrefetchItemCount() {
        return this.mInitialPrefetchItemCount;
    }

    public int getOrientation() {
        return this.mOrientation;
    }

    public boolean getRecycleChildrenOnDetach() {
        return this.mRecycleChildrenOnDetach;
    }

    public boolean getReverseLayout() {
        return this.mReverseLayout;
    }

    public boolean getStackFromEnd() {
        return this.mStackFromEnd;
    }

    @Override // androidx.recyclerview.widget.RecyclerView.o
    public boolean isAutoMeasureEnabled() {
        return true;
    }

    public boolean isLayoutRTL() {
        return getLayoutDirection() == 1;
    }

    public boolean isSmoothScrollbarEnabled() {
        return this.mSmoothScrollbarEnabled;
    }

    public void layoutChunk(RecyclerView.w wVar, RecyclerView.ac acVar, c cVar, b bVar) {
        int i;
        int i2;
        int i3;
        int i4;
        int paddingLeft;
        int iF;
        int i5;
        int i6;
        View viewB = cVar.b(wVar);
        if (viewB == null) {
            bVar.b = true;
            return;
        }
        RecyclerView.p pVar = (RecyclerView.p) viewB.getLayoutParams();
        if (cVar.k == null) {
            if (this.mShouldReverseLayout == (cVar.f == -1)) {
                addView(viewB);
            } else {
                addView(viewB, 0);
            }
        } else {
            if (this.mShouldReverseLayout == (cVar.f == -1)) {
                addDisappearingView(viewB);
            } else {
                addDisappearingView(viewB, 0);
            }
        }
        measureChildWithMargins(viewB, 0, 0);
        bVar.a = this.mOrientationHelper.e(viewB);
        if (this.mOrientation == 1) {
            if (isLayoutRTL()) {
                iF = getWidth() - getPaddingRight();
                paddingLeft = iF - this.mOrientationHelper.f(viewB);
            } else {
                paddingLeft = getPaddingLeft();
                iF = this.mOrientationHelper.f(viewB) + paddingLeft;
            }
            if (cVar.f == -1) {
                i6 = cVar.b;
                i5 = i6 - bVar.a;
            } else {
                i5 = cVar.b;
                i6 = bVar.a + i5;
            }
            int i7 = paddingLeft;
            i4 = i5;
            i3 = i7;
            i2 = i6;
            i = iF;
        } else {
            int paddingTop = getPaddingTop();
            int iF2 = this.mOrientationHelper.f(viewB) + paddingTop;
            if (cVar.f == -1) {
                int i8 = cVar.b;
                i3 = i8 - bVar.a;
                i = i8;
                i2 = iF2;
            } else {
                int i9 = cVar.b;
                i = bVar.a + i9;
                i2 = iF2;
                i3 = i9;
            }
            i4 = paddingTop;
        }
        layoutDecoratedWithMargins(viewB, i3, i4, i, i2);
        if (pVar.a.isRemoved() || pVar.a.isUpdated()) {
            bVar.c = true;
        }
        bVar.d = viewB.hasFocusable();
    }

    public final int n(RecyclerView.ac acVar) {
        if (getChildCount() == 0) {
            return 0;
        }
        ensureLayoutState();
        return ap.a(acVar, this.mOrientationHelper, findFirstVisibleChildClosestToStart(!this.mSmoothScrollbarEnabled, true), findFirstVisibleChildClosestToEnd(!this.mSmoothScrollbarEnabled, true), this, this.mSmoothScrollbarEnabled);
    }

    public final int o(RecyclerView.ac acVar) {
        if (getChildCount() == 0) {
            return 0;
        }
        ensureLayoutState();
        return ap.b(acVar, this.mOrientationHelper, findFirstVisibleChildClosestToStart(!this.mSmoothScrollbarEnabled, true), findFirstVisibleChildClosestToEnd(!this.mSmoothScrollbarEnabled, true), this, this.mSmoothScrollbarEnabled, this.mShouldReverseLayout);
    }

    public void onAnchorReady(RecyclerView.w wVar, RecyclerView.ac acVar, a aVar, int i) {
    }

    @Override // androidx.recyclerview.widget.RecyclerView.o
    @SuppressLint({"UnknownNullness"})
    public void onDetachedFromWindow(RecyclerView recyclerView, RecyclerView.w wVar) {
        onDetachedFromWindow(recyclerView);
        if (this.mRecycleChildrenOnDetach) {
            removeAndRecycleAllViews(wVar);
            wVar.a.clear();
            wVar.h();
        }
    }

    @Override // androidx.recyclerview.widget.RecyclerView.o
    @SuppressLint({"UnknownNullness"})
    public View onFocusSearchFailed(View view, int i, RecyclerView.w wVar, RecyclerView.ac acVar) {
        int iConvertFocusDirectionToLayoutDirection;
        v();
        if (getChildCount() != 0 && (iConvertFocusDirectionToLayoutDirection = convertFocusDirectionToLayoutDirection(i)) != Integer.MIN_VALUE) {
            ensureLayoutState();
            w(iConvertFocusDirectionToLayoutDirection, (int) (this.mOrientationHelper.n() * MAX_SCROLL_FACTOR), false, acVar);
            c cVar = this.mLayoutState;
            cVar.g = Integer.MIN_VALUE;
            cVar.a = false;
            fill(wVar, cVar, acVar, true);
            View viewFindOnePartiallyOrCompletelyInvisibleChild = iConvertFocusDirectionToLayoutDirection == -1 ? this.mShouldReverseLayout ? findOnePartiallyOrCompletelyInvisibleChild(getChildCount() - 1, -1) : findOnePartiallyOrCompletelyInvisibleChild(0, getChildCount()) : this.mShouldReverseLayout ? findOnePartiallyOrCompletelyInvisibleChild(0, getChildCount()) : findOnePartiallyOrCompletelyInvisibleChild(getChildCount() - 1, -1);
            View childClosestToStart = iConvertFocusDirectionToLayoutDirection == -1 ? getChildClosestToStart() : getChildClosestToEnd();
            if (!childClosestToStart.hasFocusable()) {
                return viewFindOnePartiallyOrCompletelyInvisibleChild;
            }
            if (viewFindOnePartiallyOrCompletelyInvisibleChild != null) {
                return childClosestToStart;
            }
        }
        return null;
    }

    @Override // androidx.recyclerview.widget.RecyclerView.o
    @SuppressLint({"UnknownNullness"})
    public void onInitializeAccessibilityEvent(AccessibilityEvent accessibilityEvent) {
        super.onInitializeAccessibilityEvent(accessibilityEvent);
        if (getChildCount() > 0) {
            accessibilityEvent.setFromIndex(findFirstVisibleItemPosition());
            accessibilityEvent.setToIndex(findLastVisibleItemPosition());
        }
    }

    /* JADX WARN: Removed duplicated region for block: B:116:0x01f8  */
    /* JADX WARN: Removed duplicated region for block: B:83:0x0175  */
    /* JADX WARN: Removed duplicated region for block: B:92:0x01a6  */
    @Override // androidx.recyclerview.widget.RecyclerView.o
    @SuppressLint({"UnknownNullness"})
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public void onLayoutChildren(RecyclerView.w wVar, RecyclerView.ac acVar) {
        View viewFindReferenceChild;
        int i;
        int i2;
        int i3;
        int i4;
        int i5;
        int iQ;
        int i6;
        View viewFindViewByPosition;
        int iG;
        int i7;
        int i8;
        int i9 = -1;
        if (!(this.mPendingSavedState == null && this.mPendingScrollPosition == -1) && acVar.b() == 0) {
            removeAndRecycleAllViews(wVar);
            return;
        }
        d dVar = this.mPendingSavedState;
        if (dVar != null && (i8 = dVar.a) >= 0) {
            this.mPendingScrollPosition = i8;
        }
        ensureLayoutState();
        this.mLayoutState.a = false;
        v();
        View focusedChild = getFocusedChild();
        a aVar = this.mAnchorInfo;
        if (!aVar.e || this.mPendingScrollPosition != -1 || this.mPendingSavedState != null) {
            aVar.d();
            a aVar2 = this.mAnchorInfo;
            aVar2.d = this.mShouldReverseLayout ^ this.mStackFromEnd;
            if (acVar.g || (i = this.mPendingScrollPosition) == -1) {
                if (getChildCount() != 0) {
                    View focusedChild2 = getFocusedChild();
                    if (focusedChild2 != null) {
                        RecyclerView.p pVar = (RecyclerView.p) focusedChild2.getLayoutParams();
                        if (pVar.a.isRemoved() || pVar.a.getLayoutPosition() < 0 || pVar.a.getLayoutPosition() >= acVar.b()) {
                            boolean z = this.mLastStackFromEnd;
                            boolean z2 = this.mStackFromEnd;
                            if (z == z2 && (viewFindReferenceChild = findReferenceChild(wVar, acVar, aVar2.d, z2)) != null) {
                                aVar2.b(getPosition(viewFindReferenceChild), viewFindReferenceChild);
                                if (!acVar.g && supportsPredictiveItemAnimations()) {
                                    int iG2 = this.mOrientationHelper.g(viewFindReferenceChild);
                                    int iD = this.mOrientationHelper.d(viewFindReferenceChild);
                                    int iM = this.mOrientationHelper.m();
                                    int i10 = this.mOrientationHelper.i();
                                    boolean z3 = iD <= iM && iG2 < iM;
                                    boolean z4 = iG2 >= i10 && iD > i10;
                                    if (z3 || z4) {
                                        if (aVar2.d) {
                                            iM = i10;
                                        }
                                        aVar2.c = iM;
                                    }
                                }
                            } else {
                                aVar2.a();
                                aVar2.b = this.mStackFromEnd ? acVar.b() - 1 : 0;
                            }
                        } else {
                            aVar2.c(getPosition(focusedChild2), focusedChild2);
                        }
                        this.mAnchorInfo.e = true;
                    }
                }
            } else if (i < 0 || i >= acVar.b()) {
                this.mPendingScrollPosition = -1;
                this.mPendingScrollPositionOffset = Integer.MIN_VALUE;
                if (getChildCount() != 0) {
                }
            } else {
                int i11 = this.mPendingScrollPosition;
                aVar2.b = i11;
                d dVar2 = this.mPendingSavedState;
                if (dVar2 != null && dVar2.a >= 0) {
                    boolean z5 = dVar2.c;
                    aVar2.d = z5;
                    if (z5) {
                        aVar2.c = this.mOrientationHelper.i() - this.mPendingSavedState.b;
                    } else {
                        aVar2.c = this.mOrientationHelper.m() + this.mPendingSavedState.b;
                    }
                } else if (this.mPendingScrollPositionOffset == Integer.MIN_VALUE) {
                    View viewFindViewByPosition2 = findViewByPosition(i11);
                    if (viewFindViewByPosition2 == null) {
                        if (getChildCount() > 0) {
                            aVar2.d = (this.mPendingScrollPosition < getPosition(getChildAt(0))) == this.mShouldReverseLayout;
                        }
                        aVar2.a();
                    } else if (this.mOrientationHelper.e(viewFindViewByPosition2) > this.mOrientationHelper.n()) {
                        aVar2.a();
                    } else if (this.mOrientationHelper.g(viewFindViewByPosition2) - this.mOrientationHelper.m() < 0) {
                        aVar2.c = this.mOrientationHelper.m();
                        aVar2.d = false;
                    } else if (this.mOrientationHelper.i() - this.mOrientationHelper.d(viewFindViewByPosition2) < 0) {
                        aVar2.c = this.mOrientationHelper.i();
                        aVar2.d = true;
                    } else {
                        aVar2.c = aVar2.d ? this.mOrientationHelper.o() + this.mOrientationHelper.d(viewFindViewByPosition2) : this.mOrientationHelper.g(viewFindViewByPosition2);
                    }
                } else {
                    boolean z6 = this.mShouldReverseLayout;
                    aVar2.d = z6;
                    if (z6) {
                        aVar2.c = this.mOrientationHelper.i() - this.mPendingScrollPositionOffset;
                    } else {
                        aVar2.c = this.mOrientationHelper.m() + this.mPendingScrollPositionOffset;
                    }
                }
                this.mAnchorInfo.e = true;
            }
        } else if (focusedChild != null && (this.mOrientationHelper.g(focusedChild) >= this.mOrientationHelper.i() || this.mOrientationHelper.d(focusedChild) <= this.mOrientationHelper.m())) {
            this.mAnchorInfo.c(getPosition(focusedChild), focusedChild);
        }
        c cVar = this.mLayoutState;
        cVar.f = cVar.j >= 0 ? 1 : -1;
        int[] iArr = this.mReusableIntPair;
        iArr[0] = 0;
        iArr[1] = 0;
        calculateExtraLayoutSpace(acVar, iArr);
        int iM2 = this.mOrientationHelper.m() + Math.max(0, this.mReusableIntPair[0]);
        int iJ = this.mOrientationHelper.j() + Math.max(0, this.mReusableIntPair[1]);
        if (acVar.g && (i6 = this.mPendingScrollPosition) != -1 && this.mPendingScrollPositionOffset != Integer.MIN_VALUE && (viewFindViewByPosition = findViewByPosition(i6)) != null) {
            if (this.mShouldReverseLayout) {
                i7 = this.mOrientationHelper.i() - this.mOrientationHelper.d(viewFindViewByPosition);
                iG = this.mPendingScrollPositionOffset;
            } else {
                iG = this.mOrientationHelper.g(viewFindViewByPosition) - this.mOrientationHelper.m();
                i7 = this.mPendingScrollPositionOffset;
            }
            int i12 = i7 - iG;
            if (i12 > 0) {
                iM2 += i12;
            } else {
                iJ -= i12;
            }
        }
        a aVar3 = this.mAnchorInfo;
        if (!aVar3.d ? !this.mShouldReverseLayout : this.mShouldReverseLayout) {
            i9 = 1;
        }
        onAnchorReady(wVar, acVar, aVar3, i9);
        detachAndScrapAttachedViews(wVar);
        this.mLayoutState.l = resolveIsInfinite();
        this.mLayoutState.getClass();
        this.mLayoutState.i = 0;
        a aVar4 = this.mAnchorInfo;
        if (aVar4.d) {
            y(aVar4.b, aVar4.c);
            c cVar2 = this.mLayoutState;
            cVar2.h = iM2;
            fill(wVar, cVar2, acVar, false);
            c cVar3 = this.mLayoutState;
            i3 = cVar3.b;
            int i13 = cVar3.d;
            int i14 = cVar3.c;
            if (i14 > 0) {
                iJ += i14;
            }
            a aVar5 = this.mAnchorInfo;
            x(aVar5.b, aVar5.c);
            c cVar4 = this.mLayoutState;
            cVar4.h = iJ;
            cVar4.d += cVar4.e;
            fill(wVar, cVar4, acVar, false);
            c cVar5 = this.mLayoutState;
            i2 = cVar5.b;
            int i15 = cVar5.c;
            if (i15 > 0) {
                y(i13, i3);
                c cVar6 = this.mLayoutState;
                cVar6.h = i15;
                fill(wVar, cVar6, acVar, false);
                i3 = this.mLayoutState.b;
            }
        } else {
            x(aVar4.b, aVar4.c);
            c cVar7 = this.mLayoutState;
            cVar7.h = iJ;
            fill(wVar, cVar7, acVar, false);
            c cVar8 = this.mLayoutState;
            i2 = cVar8.b;
            int i16 = cVar8.d;
            int i17 = cVar8.c;
            if (i17 > 0) {
                iM2 += i17;
            }
            a aVar6 = this.mAnchorInfo;
            y(aVar6.b, aVar6.c);
            c cVar9 = this.mLayoutState;
            cVar9.h = iM2;
            cVar9.d += cVar9.e;
            fill(wVar, cVar9, acVar, false);
            c cVar10 = this.mLayoutState;
            int i18 = cVar10.b;
            int i19 = cVar10.c;
            if (i19 > 0) {
                x(i16, i2);
                c cVar11 = this.mLayoutState;
                cVar11.h = i19;
                fill(wVar, cVar11, acVar, false);
                i2 = this.mLayoutState.b;
            }
            i3 = i18;
        }
        if (getChildCount() > 0) {
            if (this.mShouldReverseLayout ^ this.mStackFromEnd) {
                int iQ2 = q(i2, wVar, acVar, true);
                i4 = i3 + iQ2;
                i5 = i2 + iQ2;
                iQ = r(i4, wVar, acVar, false);
            } else {
                int iR = r(i3, wVar, acVar, true);
                i4 = i3 + iR;
                i5 = i2 + iR;
                iQ = q(i5, wVar, acVar, false);
            }
            i3 = i4 + iQ;
            i2 = i5 + iQ;
        }
        if (acVar.k && getChildCount() != 0 && !acVar.g && supportsPredictiveItemAnimations()) {
            List list = wVar.d;
            int size = list.size();
            int position = getPosition(getChildAt(0));
            int iE = 0;
            int iE2 = 0;
            for (int i20 = 0; i20 < size; i20++) {
                RecyclerView.ag agVar = (RecyclerView.ag) list.get(i20);
                if (!agVar.isRemoved()) {
                    if ((agVar.getLayoutPosition() < position) != this.mShouldReverseLayout) {
                        iE += this.mOrientationHelper.e(agVar.itemView);
                    } else {
                        iE2 += this.mOrientationHelper.e(agVar.itemView);
                    }
                }
            }
            this.mLayoutState.k = list;
            if (iE > 0) {
                y(getPosition(getChildClosestToStart()), i3);
                c cVar12 = this.mLayoutState;
                cVar12.h = iE;
                cVar12.c = 0;
                cVar12.a(null);
                fill(wVar, this.mLayoutState, acVar, false);
            }
            if (iE2 > 0) {
                x(getPosition(getChildClosestToEnd()), i2);
                c cVar13 = this.mLayoutState;
                cVar13.h = iE2;
                cVar13.c = 0;
                cVar13.a(null);
                fill(wVar, this.mLayoutState, acVar, false);
            }
            this.mLayoutState.k = null;
        }
        if (acVar.g) {
            this.mAnchorInfo.d();
        } else {
            ak akVar = this.mOrientationHelper;
            akVar.b = akVar.n();
        }
        this.mLastStackFromEnd = this.mStackFromEnd;
    }

    @Override // androidx.recyclerview.widget.RecyclerView.o
    @SuppressLint({"UnknownNullness"})
    public void onLayoutCompleted(RecyclerView.ac acVar) {
        this.mPendingSavedState = null;
        this.mPendingScrollPosition = -1;
        this.mPendingScrollPositionOffset = Integer.MIN_VALUE;
        this.mAnchorInfo.d();
    }

    @Override // androidx.recyclerview.widget.RecyclerView.o
    @SuppressLint({"UnknownNullness"})
    public void onRestoreInstanceState(Parcelable parcelable) {
        if (parcelable instanceof d) {
            d dVar = (d) parcelable;
            this.mPendingSavedState = dVar;
            if (this.mPendingScrollPosition != -1) {
                dVar.a = -1;
            }
            requestLayout();
        }
    }

    @Override // androidx.recyclerview.widget.RecyclerView.o
    @SuppressLint({"UnknownNullness"})
    public Parcelable onSaveInstanceState() {
        d dVar = this.mPendingSavedState;
        if (dVar != null) {
            d dVar2 = new d();
            dVar2.a = dVar.a;
            dVar2.b = dVar.b;
            dVar2.c = dVar.c;
            return dVar2;
        }
        d dVar3 = new d();
        if (getChildCount() <= 0) {
            dVar3.a = -1;
            return dVar3;
        }
        ensureLayoutState();
        boolean z = this.mLastStackFromEnd ^ this.mShouldReverseLayout;
        dVar3.c = z;
        if (z) {
            View childClosestToEnd = getChildClosestToEnd();
            dVar3.b = this.mOrientationHelper.i() - this.mOrientationHelper.d(childClosestToEnd);
            dVar3.a = getPosition(childClosestToEnd);
            return dVar3;
        }
        View childClosestToStart = getChildClosestToStart();
        dVar3.a = getPosition(childClosestToStart);
        dVar3.b = this.mOrientationHelper.g(childClosestToStart) - this.mOrientationHelper.m();
        return dVar3;
    }

    public final int p(RecyclerView.ac acVar) {
        if (getChildCount() == 0) {
            return 0;
        }
        ensureLayoutState();
        return ap.c(acVar, this.mOrientationHelper, findFirstVisibleChildClosestToStart(!this.mSmoothScrollbarEnabled, true), findFirstVisibleChildClosestToEnd(!this.mSmoothScrollbarEnabled, true), this, this.mSmoothScrollbarEnabled);
    }

    @Override // androidx.recyclerview.widget.x.g
    public void prepareForDrop(@vo6 View view, @vo6 View view2, int i, int i2) {
        assertNotInLayoutOrScroll("Cannot drop a view during a scroll or layout calculation");
        ensureLayoutState();
        v();
        int position = getPosition(view);
        int position2 = getPosition(view2);
        byte b2 = position < position2 ? (byte) 1 : (byte) -1;
        if (this.mShouldReverseLayout) {
            if (b2 == 1) {
                scrollToPositionWithOffset(position2, this.mOrientationHelper.i() - (this.mOrientationHelper.e(view) + this.mOrientationHelper.g(view2)));
                return;
            } else {
                scrollToPositionWithOffset(position2, this.mOrientationHelper.i() - this.mOrientationHelper.d(view2));
                return;
            }
        }
        if (b2 == -1) {
            scrollToPositionWithOffset(position2, this.mOrientationHelper.g(view2));
        } else {
            scrollToPositionWithOffset(position2, this.mOrientationHelper.d(view2) - this.mOrientationHelper.e(view));
        }
    }

    public final int q(int i, RecyclerView.w wVar, RecyclerView.ac acVar, boolean z) {
        int i2;
        int i3 = this.mOrientationHelper.i() - i;
        if (i3 <= 0) {
            return 0;
        }
        int i4 = -scrollBy(-i3, wVar, acVar);
        int i5 = i + i4;
        if (!z || (i2 = this.mOrientationHelper.i() - i5) <= 0) {
            return i4;
        }
        this.mOrientationHelper.r(i2);
        return i2 + i4;
    }

    public final int r(int i, RecyclerView.w wVar, RecyclerView.ac acVar, boolean z) {
        int iM;
        int iM2 = i - this.mOrientationHelper.m();
        if (iM2 <= 0) {
            return 0;
        }
        int i2 = -scrollBy(iM2, wVar, acVar);
        int i3 = i + i2;
        if (!z || (iM = i3 - this.mOrientationHelper.m()) <= 0) {
            return i2;
        }
        this.mOrientationHelper.r(-iM);
        return i2 - iM;
    }

    public boolean resolveIsInfinite() {
        return this.mOrientationHelper.k() == 0 && this.mOrientationHelper.h() == 0;
    }

    public final void s() {
        for (int i = 0; i < getChildCount(); i++) {
            View childAt = getChildAt(i);
            getPosition(childAt);
            this.mOrientationHelper.g(childAt);
        }
    }

    public int scrollBy(int i, RecyclerView.w wVar, RecyclerView.ac acVar) {
        if (getChildCount() == 0 || i == 0) {
            return 0;
        }
        ensureLayoutState();
        this.mLayoutState.a = true;
        int i2 = i > 0 ? 1 : -1;
        int iAbs = Math.abs(i);
        w(i2, iAbs, true, acVar);
        c cVar = this.mLayoutState;
        int iFill = fill(wVar, cVar, acVar, false) + cVar.g;
        if (iFill < 0) {
            return 0;
        }
        if (iAbs > iFill) {
            i = i2 * iFill;
        }
        this.mOrientationHelper.r(-i);
        this.mLayoutState.j = i;
        return i;
    }

    @Override // androidx.recyclerview.widget.RecyclerView.o
    @SuppressLint({"UnknownNullness"})
    public int scrollHorizontallyBy(int i, RecyclerView.w wVar, RecyclerView.ac acVar) {
        if (this.mOrientation == 1) {
            return 0;
        }
        return scrollBy(i, wVar, acVar);
    }

    @Override // androidx.recyclerview.widget.RecyclerView.o
    public void scrollToPosition(int i) {
        this.mPendingScrollPosition = i;
        this.mPendingScrollPositionOffset = Integer.MIN_VALUE;
        d dVar = this.mPendingSavedState;
        if (dVar != null) {
            dVar.a = -1;
        }
        requestLayout();
    }

    public void scrollToPositionWithOffset(int i, int i2) {
        this.mPendingScrollPosition = i;
        this.mPendingScrollPositionOffset = i2;
        d dVar = this.mPendingSavedState;
        if (dVar != null) {
            dVar.a = -1;
        }
        requestLayout();
    }

    @Override // androidx.recyclerview.widget.RecyclerView.o
    @SuppressLint({"UnknownNullness"})
    public int scrollVerticallyBy(int i, RecyclerView.w wVar, RecyclerView.ac acVar) {
        if (this.mOrientation == 0) {
            return 0;
        }
        return scrollBy(i, wVar, acVar);
    }

    public void setInitialPrefetchItemCount(int i) {
        this.mInitialPrefetchItemCount = i;
    }

    public void setOrientation(int i) {
        if (i != 0 && i != 1) {
            throw new IllegalArgumentException(n41.k("invalid orientation:", i));
        }
        assertNotInLayoutOrScroll(null);
        if (i != this.mOrientation || this.mOrientationHelper == null) {
            ak akVarB = ak.b(this, i);
            this.mOrientationHelper = akVarB;
            this.mAnchorInfo.a = akVarB;
            this.mOrientation = i;
            requestLayout();
        }
    }

    public void setRecycleChildrenOnDetach(boolean z) {
        this.mRecycleChildrenOnDetach = z;
    }

    public void setReverseLayout(boolean z) {
        assertNotInLayoutOrScroll(null);
        if (z == this.mReverseLayout) {
            return;
        }
        this.mReverseLayout = z;
        requestLayout();
    }

    public void setSmoothScrollbarEnabled(boolean z) {
        this.mSmoothScrollbarEnabled = z;
    }

    public void setStackFromEnd(boolean z) {
        assertNotInLayoutOrScroll(null);
        if (this.mStackFromEnd == z) {
            return;
        }
        this.mStackFromEnd = z;
        requestLayout();
    }

    @Override // androidx.recyclerview.widget.RecyclerView.o
    public boolean shouldMeasureTwice() {
        return (getHeightMode() == 1073741824 || getWidthMode() == 1073741824 || !hasFlexibleChildInBothOrientations()) ? false : true;
    }

    @Override // androidx.recyclerview.widget.RecyclerView.o
    public void smoothScrollToPosition(RecyclerView recyclerView, RecyclerView.ac acVar, int i) {
        ad adVar = new ad(recyclerView.getContext());
        adVar.setTargetPosition(i);
        startSmoothScroll(adVar);
    }

    @Override // androidx.recyclerview.widget.RecyclerView.o
    public boolean supportsPredictiveItemAnimations() {
        return this.mPendingSavedState == null && this.mLastStackFromEnd == this.mStackFromEnd;
    }

    public final void t(RecyclerView.w wVar, c cVar) {
        if (!cVar.a || cVar.l) {
            return;
        }
        int i = cVar.g;
        int i2 = cVar.i;
        if (cVar.f == -1) {
            int childCount = getChildCount();
            if (i < 0) {
                return;
            }
            int iH = (this.mOrientationHelper.h() - i) + i2;
            if (this.mShouldReverseLayout) {
                for (int i3 = 0; i3 < childCount; i3++) {
                    View childAt = getChildAt(i3);
                    if (this.mOrientationHelper.g(childAt) < iH || this.mOrientationHelper.q(childAt) < iH) {
                        u(wVar, 0, i3);
                        return;
                    }
                }
                return;
            }
            int i4 = childCount - 1;
            for (int i5 = i4; i5 >= 0; i5--) {
                View childAt2 = getChildAt(i5);
                if (this.mOrientationHelper.g(childAt2) < iH || this.mOrientationHelper.q(childAt2) < iH) {
                    u(wVar, i4, i5);
                    return;
                }
            }
            return;
        }
        if (i < 0) {
            return;
        }
        int i6 = i - i2;
        int childCount2 = getChildCount();
        if (!this.mShouldReverseLayout) {
            for (int i7 = 0; i7 < childCount2; i7++) {
                View childAt3 = getChildAt(i7);
                if (this.mOrientationHelper.d(childAt3) > i6 || this.mOrientationHelper.p(childAt3) > i6) {
                    u(wVar, 0, i7);
                    return;
                }
            }
            return;
        }
        int i8 = childCount2 - 1;
        for (int i9 = i8; i9 >= 0; i9--) {
            View childAt4 = getChildAt(i9);
            if (this.mOrientationHelper.d(childAt4) > i6 || this.mOrientationHelper.p(childAt4) > i6) {
                u(wVar, i8, i9);
                return;
            }
        }
    }

    public final void u(RecyclerView.w wVar, int i, int i2) {
        if (i == i2) {
            return;
        }
        if (i2 <= i) {
            while (i > i2) {
                removeAndRecycleViewAt(i, wVar);
                i--;
            }
        } else {
            for (int i3 = i2 - 1; i3 >= i; i3--) {
                removeAndRecycleViewAt(i3, wVar);
            }
        }
    }

    public final void v() {
        if (this.mOrientation == 1 || !isLayoutRTL()) {
            this.mShouldReverseLayout = this.mReverseLayout;
        } else {
            this.mShouldReverseLayout = !this.mReverseLayout;
        }
    }

    public void validateChildOrder() {
        getChildCount();
        if (getChildCount() < 1) {
            return;
        }
        int position = getPosition(getChildAt(0));
        int iG = this.mOrientationHelper.g(getChildAt(0));
        if (this.mShouldReverseLayout) {
            for (int i = 1; i < getChildCount(); i++) {
                View childAt = getChildAt(i);
                int position2 = getPosition(childAt);
                int iG2 = this.mOrientationHelper.g(childAt);
                if (position2 < position) {
                    s();
                    StringBuilder sb = new StringBuilder("detected invalid position. loc invalid? ");
                    sb.append(iG2 < iG);
                    throw new RuntimeException(sb.toString());
                }
                if (iG2 > iG) {
                    s();
                    throw new RuntimeException("detected invalid location");
                }
            }
            return;
        }
        for (int i2 = 1; i2 < getChildCount(); i2++) {
            View childAt2 = getChildAt(i2);
            int position3 = getPosition(childAt2);
            int iG3 = this.mOrientationHelper.g(childAt2);
            if (position3 < position) {
                s();
                StringBuilder sb2 = new StringBuilder("detected invalid position. loc invalid? ");
                sb2.append(iG3 < iG);
                throw new RuntimeException(sb2.toString());
            }
            if (iG3 < iG) {
                s();
                throw new RuntimeException("detected invalid location");
            }
        }
    }

    public final void w(int i, int i2, boolean z, RecyclerView.ac acVar) {
        int iM;
        this.mLayoutState.l = resolveIsInfinite();
        this.mLayoutState.f = i;
        int[] iArr = this.mReusableIntPair;
        iArr[0] = 0;
        iArr[1] = 0;
        calculateExtraLayoutSpace(acVar, iArr);
        int iMax = Math.max(0, this.mReusableIntPair[0]);
        int iMax2 = Math.max(0, this.mReusableIntPair[1]);
        boolean z2 = i == 1;
        c cVar = this.mLayoutState;
        int i3 = z2 ? iMax2 : iMax;
        cVar.h = i3;
        if (!z2) {
            iMax = iMax2;
        }
        cVar.i = iMax;
        if (z2) {
            cVar.h = this.mOrientationHelper.j() + i3;
            View childClosestToEnd = getChildClosestToEnd();
            c cVar2 = this.mLayoutState;
            cVar2.e = this.mShouldReverseLayout ? -1 : 1;
            int position = getPosition(childClosestToEnd);
            c cVar3 = this.mLayoutState;
            cVar2.d = position + cVar3.e;
            cVar3.b = this.mOrientationHelper.d(childClosestToEnd);
            iM = this.mOrientationHelper.d(childClosestToEnd) - this.mOrientationHelper.i();
        } else {
            View childClosestToStart = getChildClosestToStart();
            c cVar4 = this.mLayoutState;
            cVar4.h = this.mOrientationHelper.m() + cVar4.h;
            c cVar5 = this.mLayoutState;
            cVar5.e = this.mShouldReverseLayout ? 1 : -1;
            int position2 = getPosition(childClosestToStart);
            c cVar6 = this.mLayoutState;
            cVar5.d = position2 + cVar6.e;
            cVar6.b = this.mOrientationHelper.g(childClosestToStart);
            iM = (-this.mOrientationHelper.g(childClosestToStart)) + this.mOrientationHelper.m();
        }
        c cVar7 = this.mLayoutState;
        cVar7.c = i2;
        if (z) {
            cVar7.c = i2 - iM;
        }
        cVar7.g = iM;
    }

    public final void x(int i, int i2) {
        this.mLayoutState.c = this.mOrientationHelper.i() - i2;
        c cVar = this.mLayoutState;
        cVar.e = this.mShouldReverseLayout ? -1 : 1;
        cVar.d = i;
        cVar.f = 1;
        cVar.b = i2;
        cVar.g = Integer.MIN_VALUE;
    }

    public final void y(int i, int i2) {
        this.mLayoutState.c = i2 - this.mOrientationHelper.m();
        c cVar = this.mLayoutState;
        cVar.d = i;
        cVar.e = this.mShouldReverseLayout ? 1 : -1;
        cVar.f = -1;
        cVar.b = i2;
        cVar.g = Integer.MIN_VALUE;
    }

    public LinearLayoutManager(int i, boolean z) {
        this.mOrientation = 1;
        this.mReverseLayout = false;
        this.mShouldReverseLayout = false;
        this.mStackFromEnd = false;
        this.mSmoothScrollbarEnabled = true;
        this.mPendingScrollPosition = -1;
        this.mPendingScrollPositionOffset = Integer.MIN_VALUE;
        this.mPendingSavedState = null;
        this.mAnchorInfo = new a();
        this.mLayoutChunkResult = new b();
        this.mInitialPrefetchItemCount = 2;
        this.mReusableIntPair = new int[2];
        setOrientation(i);
        setReverseLayout(z);
    }

    @SuppressLint({"UnknownNullness"})
    public LinearLayoutManager(Context context, AttributeSet attributeSet, int i, int i2) {
        this.mOrientation = 1;
        this.mReverseLayout = false;
        this.mShouldReverseLayout = false;
        this.mStackFromEnd = false;
        this.mSmoothScrollbarEnabled = true;
        this.mPendingScrollPosition = -1;
        this.mPendingScrollPositionOffset = Integer.MIN_VALUE;
        this.mPendingSavedState = null;
        this.mAnchorInfo = new a();
        this.mLayoutChunkResult = new b();
        this.mInitialPrefetchItemCount = 2;
        this.mReusableIntPair = new int[2];
        RecyclerView.o.d properties = RecyclerView.o.getProperties(context, attributeSet, i, i2);
        setOrientation(properties.a);
        setReverseLayout(properties.c);
        setStackFromEnd(properties.d);
    }
}
