package androidx.recyclerview.widget; import android.annotation.SuppressLint; import android.content.Context; import android.graphics.PointF; import android.graphics.Rect; import android.os.Parcel; import android.os.Parcelable; import android.util.AttributeSet; import android.view.View; import android.view.ViewGroup; import android.view.accessibility.AccessibilityEvent; import androidx.annotation.NonNull; import androidx.annotation.Nullable; import androidx.annotation.RestrictTo; import androidx.core.view.accessibility.AccessibilityNodeInfoCompat; import androidx.recyclerview.widget.RecyclerView; import c.d.b.a.a; import java.util.ArrayList; import java.util.Arrays; import java.util.BitSet; import java.util.List; public class StaggeredGridLayoutManager extends RecyclerView.LayoutManager implements RecyclerView.SmoothScroller.ScrollVectorProvider { public static final boolean DEBUG = false; @Deprecated public static final int GAP_HANDLING_LAZY = 1; public static final int GAP_HANDLING_MOVE_ITEMS_BETWEEN_SPANS = 2; public static final int GAP_HANDLING_NONE = 0; 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 = "StaggeredGridLManager"; public static final int VERTICAL = 1; private final AnchorInfo mAnchorInfo = new AnchorInfo(); private final Runnable mCheckForGapsRunnable = new AnonymousClass1(); private int mFullSizeSpec; private int mGapStrategy = 2; private boolean mLaidOutInvalidFullSpan = false; private boolean mLastLayoutFromEnd; private boolean mLastLayoutRTL; @NonNull private final LayoutState mLayoutState; public LazySpanLookup mLazySpanLookup = new LazySpanLookup(); private int mOrientation; private SavedState mPendingSavedState; public int mPendingScrollPosition = -1; public int mPendingScrollPositionOffset = Integer.MIN_VALUE; private int[] mPrefetchDistances; @NonNull public OrientationHelper mPrimaryOrientation; private BitSet mRemainingSpans; public boolean mReverseLayout = false; @NonNull public OrientationHelper mSecondaryOrientation; public boolean mShouldReverseLayout = false; private int mSizePerSpan; private boolean mSmoothScrollbarEnabled = true; private int mSpanCount = -1; public Span[] mSpans; private final Rect mTmpRect = new Rect(); /* renamed from: androidx.recyclerview.widget.StaggeredGridLayoutManager$1 reason: invalid class name */ public class AnonymousClass1 implements Runnable { public AnonymousClass1() { } @Override // java.lang.Runnable public void run() { StaggeredGridLayoutManager.this.checkForGaps(); } } public class AnchorInfo { public boolean mInvalidateOffsets; public boolean mLayoutFromEnd; public int mOffset; public int mPosition; public int[] mSpanReferenceLines; public boolean mValid; public AnchorInfo() { reset(); } public void assignCoordinateFromPadding() { this.mOffset = this.mLayoutFromEnd ? StaggeredGridLayoutManager.this.mPrimaryOrientation.getEndAfterPadding() : StaggeredGridLayoutManager.this.mPrimaryOrientation.getStartAfterPadding(); } public void assignCoordinateFromPadding(int i) { if (this.mLayoutFromEnd) { this.mOffset = StaggeredGridLayoutManager.this.mPrimaryOrientation.getEndAfterPadding() - i; } else { this.mOffset = StaggeredGridLayoutManager.this.mPrimaryOrientation.getStartAfterPadding() + i; } } public void reset() { this.mPosition = -1; this.mOffset = Integer.MIN_VALUE; this.mLayoutFromEnd = false; this.mInvalidateOffsets = false; this.mValid = false; int[] iArr = this.mSpanReferenceLines; if (iArr != null) { Arrays.fill(iArr, -1); } } public void saveSpanReferenceLines(Span[] spanArr) { int length = spanArr.length; int[] iArr = this.mSpanReferenceLines; if (iArr == null || iArr.length < length) { this.mSpanReferenceLines = new int[StaggeredGridLayoutManager.this.mSpans.length]; } for (int i = 0; i < length; i++) { this.mSpanReferenceLines[i] = spanArr[i].getStartLine(Integer.MIN_VALUE); } } } public static class LayoutParams extends RecyclerView.LayoutParams { public static final int INVALID_SPAN_ID = -1; public boolean mFullSpan; public Span mSpan; public LayoutParams(int i, int i2) { super(i, i2); } public LayoutParams(Context context, AttributeSet attributeSet) { super(context, attributeSet); } public LayoutParams(ViewGroup.LayoutParams layoutParams) { super(layoutParams); } public LayoutParams(ViewGroup.MarginLayoutParams marginLayoutParams) { super(marginLayoutParams); } public LayoutParams(RecyclerView.LayoutParams layoutParams) { super(layoutParams); } public final int getSpanIndex() { Span span = this.mSpan; if (span == null) { return -1; } return span.mIndex; } public boolean isFullSpan() { return this.mFullSpan; } public void setFullSpan(boolean z2) { this.mFullSpan = z2; } } public static class LazySpanLookup { private static final int MIN_SIZE = 10; public int[] mData; public List mFullSpanItems; @SuppressLint({"BanParcelableUsage"}) public static class FullSpanItem implements Parcelable { public static final Parcelable.Creator CREATOR = new AnonymousClass1(); public int mGapDir; public int[] mGapPerSpan; public boolean mHasUnwantedGapAfter; public int mPosition; /* renamed from: androidx.recyclerview.widget.StaggeredGridLayoutManager$LazySpanLookup$FullSpanItem$1 reason: invalid class name */ public static class AnonymousClass1 implements Parcelable.Creator { @Override // android.os.Parcelable.Creator public FullSpanItem createFromParcel(Parcel parcel) { return new FullSpanItem(parcel); } @Override // android.os.Parcelable.Creator public FullSpanItem[] newArray(int i) { return new FullSpanItem[i]; } } public FullSpanItem() { } public FullSpanItem(Parcel parcel) { this.mPosition = parcel.readInt(); this.mGapDir = parcel.readInt(); this.mHasUnwantedGapAfter = parcel.readInt() != 1 ? false : true; int readInt = parcel.readInt(); if (readInt > 0) { int[] iArr = new int[readInt]; this.mGapPerSpan = iArr; parcel.readIntArray(iArr); } } @Override // android.os.Parcelable public int describeContents() { return 0; } public int getGapForSpan(int i) { int[] iArr = this.mGapPerSpan; if (iArr == null) { return 0; } return iArr[i]; } @Override // java.lang.Object public String toString() { StringBuilder L = a.L("FullSpanItem{mPosition="); L.append(this.mPosition); L.append(", mGapDir="); L.append(this.mGapDir); L.append(", mHasUnwantedGapAfter="); L.append(this.mHasUnwantedGapAfter); L.append(", mGapPerSpan="); L.append(Arrays.toString(this.mGapPerSpan)); L.append('}'); return L.toString(); } @Override // android.os.Parcelable public void writeToParcel(Parcel parcel, int i) { parcel.writeInt(this.mPosition); parcel.writeInt(this.mGapDir); parcel.writeInt(this.mHasUnwantedGapAfter ? 1 : 0); int[] iArr = this.mGapPerSpan; if (iArr == null || iArr.length <= 0) { parcel.writeInt(0); return; } parcel.writeInt(iArr.length); parcel.writeIntArray(this.mGapPerSpan); } } private int invalidateFullSpansAfter(int i) { if (this.mFullSpanItems == null) { return -1; } FullSpanItem fullSpanItem = getFullSpanItem(i); if (fullSpanItem != null) { this.mFullSpanItems.remove(fullSpanItem); } int size = this.mFullSpanItems.size(); int i2 = 0; while (true) { if (i2 >= size) { i2 = -1; break; } else if (this.mFullSpanItems.get(i2).mPosition >= i) { break; } else { i2++; } } if (i2 == -1) { return -1; } this.mFullSpanItems.remove(i2); return this.mFullSpanItems.get(i2).mPosition; } private void offsetFullSpansForAddition(int i, int i2) { List list = this.mFullSpanItems; if (list != null) { for (int size = list.size() - 1; size >= 0; size--) { FullSpanItem fullSpanItem = this.mFullSpanItems.get(size); int i3 = fullSpanItem.mPosition; if (i3 >= i) { fullSpanItem.mPosition = i3 + i2; } } } } private void offsetFullSpansForRemoval(int i, int i2) { List list = this.mFullSpanItems; if (list != null) { int i3 = i + i2; for (int size = list.size() - 1; size >= 0; size--) { FullSpanItem fullSpanItem = this.mFullSpanItems.get(size); int i4 = fullSpanItem.mPosition; if (i4 >= i) { if (i4 < i3) { this.mFullSpanItems.remove(size); } else { fullSpanItem.mPosition = i4 - i2; } } } } } public void addFullSpanItem(FullSpanItem fullSpanItem) { if (this.mFullSpanItems == null) { this.mFullSpanItems = new ArrayList(); } int size = this.mFullSpanItems.size(); for (int i = 0; i < size; i++) { FullSpanItem fullSpanItem2 = this.mFullSpanItems.get(i); if (fullSpanItem2.mPosition == fullSpanItem.mPosition) { this.mFullSpanItems.remove(i); } if (fullSpanItem2.mPosition >= fullSpanItem.mPosition) { this.mFullSpanItems.add(i, fullSpanItem); return; } } this.mFullSpanItems.add(fullSpanItem); } public void clear() { int[] iArr = this.mData; if (iArr != null) { Arrays.fill(iArr, -1); } this.mFullSpanItems = null; } public void ensureSize(int i) { int[] iArr = this.mData; if (iArr == null) { int[] iArr2 = new int[(Math.max(i, 10) + 1)]; this.mData = iArr2; Arrays.fill(iArr2, -1); } else if (i >= iArr.length) { int[] iArr3 = new int[sizeForPosition(i)]; this.mData = iArr3; System.arraycopy(iArr, 0, iArr3, 0, iArr.length); int[] iArr4 = this.mData; Arrays.fill(iArr4, iArr.length, iArr4.length, -1); } } public int forceInvalidateAfter(int i) { List list = this.mFullSpanItems; if (list != null) { for (int size = list.size() - 1; size >= 0; size--) { if (this.mFullSpanItems.get(size).mPosition >= i) { this.mFullSpanItems.remove(size); } } } return invalidateAfter(i); } public FullSpanItem getFirstFullSpanItemInRange(int i, int i2, int i3, boolean z2) { List list = this.mFullSpanItems; if (list == null) { return null; } int size = list.size(); for (int i4 = 0; i4 < size; i4++) { FullSpanItem fullSpanItem = this.mFullSpanItems.get(i4); int i5 = fullSpanItem.mPosition; if (i5 >= i2) { return null; } if (i5 >= i && (i3 == 0 || fullSpanItem.mGapDir == i3 || (z2 && fullSpanItem.mHasUnwantedGapAfter))) { return fullSpanItem; } } return null; } public FullSpanItem getFullSpanItem(int i) { List list = this.mFullSpanItems; if (list == null) { return null; } for (int size = list.size() - 1; size >= 0; size--) { FullSpanItem fullSpanItem = this.mFullSpanItems.get(size); if (fullSpanItem.mPosition == i) { return fullSpanItem; } } return null; } public int getSpan(int i) { int[] iArr = this.mData; if (iArr == null || i >= iArr.length) { return -1; } return iArr[i]; } public int invalidateAfter(int i) { int[] iArr = this.mData; if (iArr == null || i >= iArr.length) { return -1; } int invalidateFullSpansAfter = invalidateFullSpansAfter(i); if (invalidateFullSpansAfter == -1) { int[] iArr2 = this.mData; Arrays.fill(iArr2, i, iArr2.length, -1); return this.mData.length; } int i2 = invalidateFullSpansAfter + 1; Arrays.fill(this.mData, i, i2, -1); return i2; } public void offsetForAddition(int i, int i2) { int[] iArr = this.mData; if (iArr != null && i < iArr.length) { int i3 = i + i2; ensureSize(i3); int[] iArr2 = this.mData; System.arraycopy(iArr2, i, iArr2, i3, (iArr2.length - i) - i2); Arrays.fill(this.mData, i, i3, -1); offsetFullSpansForAddition(i, i2); } } public void offsetForRemoval(int i, int i2) { int[] iArr = this.mData; if (iArr != null && i < iArr.length) { int i3 = i + i2; ensureSize(i3); int[] iArr2 = this.mData; System.arraycopy(iArr2, i3, iArr2, i, (iArr2.length - i) - i2); int[] iArr3 = this.mData; Arrays.fill(iArr3, iArr3.length - i2, iArr3.length, -1); offsetFullSpansForRemoval(i, i2); } } public void setSpan(int i, Span span) { ensureSize(i); this.mData[i] = span.mIndex; } public int sizeForPosition(int i) { int length = this.mData.length; while (length <= i) { length *= 2; } return length; } } @SuppressLint({"BanParcelableUsage"}) @RestrictTo({RestrictTo.Scope.LIBRARY}) public static class SavedState implements Parcelable { public static final Parcelable.Creator CREATOR = new AnonymousClass1(); public boolean mAnchorLayoutFromEnd; public int mAnchorPosition; public List mFullSpanItems; public boolean mLastLayoutRTL; public boolean mReverseLayout; public int[] mSpanLookup; public int mSpanLookupSize; public int[] mSpanOffsets; public int mSpanOffsetsSize; public int mVisibleAnchorPosition; /* renamed from: androidx.recyclerview.widget.StaggeredGridLayoutManager$SavedState$1 reason: invalid class name */ public static class AnonymousClass1 implements Parcelable.Creator { @Override // android.os.Parcelable.Creator public SavedState createFromParcel(Parcel parcel) { return new SavedState(parcel); } @Override // android.os.Parcelable.Creator public SavedState[] newArray(int i) { return new SavedState[i]; } } public SavedState() { } public SavedState(Parcel parcel) { this.mAnchorPosition = parcel.readInt(); this.mVisibleAnchorPosition = parcel.readInt(); int readInt = parcel.readInt(); this.mSpanOffsetsSize = readInt; if (readInt > 0) { int[] iArr = new int[readInt]; this.mSpanOffsets = iArr; parcel.readIntArray(iArr); } int readInt2 = parcel.readInt(); this.mSpanLookupSize = readInt2; if (readInt2 > 0) { int[] iArr2 = new int[readInt2]; this.mSpanLookup = iArr2; parcel.readIntArray(iArr2); } boolean z2 = false; this.mReverseLayout = parcel.readInt() == 1; this.mAnchorLayoutFromEnd = parcel.readInt() == 1; this.mLastLayoutRTL = parcel.readInt() == 1 ? true : z2; this.mFullSpanItems = parcel.readArrayList(LazySpanLookup.FullSpanItem.class.getClassLoader()); } public SavedState(SavedState savedState) { this.mSpanOffsetsSize = savedState.mSpanOffsetsSize; this.mAnchorPosition = savedState.mAnchorPosition; this.mVisibleAnchorPosition = savedState.mVisibleAnchorPosition; this.mSpanOffsets = savedState.mSpanOffsets; this.mSpanLookupSize = savedState.mSpanLookupSize; this.mSpanLookup = savedState.mSpanLookup; this.mReverseLayout = savedState.mReverseLayout; this.mAnchorLayoutFromEnd = savedState.mAnchorLayoutFromEnd; this.mLastLayoutRTL = savedState.mLastLayoutRTL; this.mFullSpanItems = savedState.mFullSpanItems; } @Override // android.os.Parcelable public int describeContents() { return 0; } public void invalidateAnchorPositionInfo() { this.mSpanOffsets = null; this.mSpanOffsetsSize = 0; this.mAnchorPosition = -1; this.mVisibleAnchorPosition = -1; } public void invalidateSpanInfo() { this.mSpanOffsets = null; this.mSpanOffsetsSize = 0; this.mSpanLookupSize = 0; this.mSpanLookup = null; this.mFullSpanItems = null; } @Override // android.os.Parcelable public void writeToParcel(Parcel parcel, int i) { parcel.writeInt(this.mAnchorPosition); parcel.writeInt(this.mVisibleAnchorPosition); parcel.writeInt(this.mSpanOffsetsSize); if (this.mSpanOffsetsSize > 0) { parcel.writeIntArray(this.mSpanOffsets); } parcel.writeInt(this.mSpanLookupSize); if (this.mSpanLookupSize > 0) { parcel.writeIntArray(this.mSpanLookup); } parcel.writeInt(this.mReverseLayout ? 1 : 0); parcel.writeInt(this.mAnchorLayoutFromEnd ? 1 : 0); parcel.writeInt(this.mLastLayoutRTL ? 1 : 0); parcel.writeList(this.mFullSpanItems); } } public class Span { public static final int INVALID_LINE = Integer.MIN_VALUE; public int mCachedEnd = Integer.MIN_VALUE; public int mCachedStart = Integer.MIN_VALUE; public int mDeletedSize = 0; public final int mIndex; public ArrayList mViews = new ArrayList<>(); public Span(int i) { this.mIndex = i; } public void appendToSpan(View view) { LayoutParams layoutParams = getLayoutParams(view); layoutParams.mSpan = this; this.mViews.add(view); this.mCachedEnd = Integer.MIN_VALUE; if (this.mViews.size() == 1) { this.mCachedStart = Integer.MIN_VALUE; } if (layoutParams.isItemRemoved() || layoutParams.isItemChanged()) { this.mDeletedSize = StaggeredGridLayoutManager.this.mPrimaryOrientation.getDecoratedMeasurement(view) + this.mDeletedSize; } } public void cacheReferenceLineAndClear(boolean z2, int i) { int endLine = z2 ? getEndLine(Integer.MIN_VALUE) : getStartLine(Integer.MIN_VALUE); clear(); if (endLine != Integer.MIN_VALUE) { if (z2 && endLine < StaggeredGridLayoutManager.this.mPrimaryOrientation.getEndAfterPadding()) { return; } if (z2 || endLine <= StaggeredGridLayoutManager.this.mPrimaryOrientation.getStartAfterPadding()) { if (i != Integer.MIN_VALUE) { endLine += i; } this.mCachedEnd = endLine; this.mCachedStart = endLine; } } } public void calculateCachedEnd() { LazySpanLookup.FullSpanItem fullSpanItem; ArrayList arrayList = this.mViews; View view = arrayList.get(arrayList.size() - 1); LayoutParams layoutParams = getLayoutParams(view); this.mCachedEnd = StaggeredGridLayoutManager.this.mPrimaryOrientation.getDecoratedEnd(view); if (layoutParams.mFullSpan && (fullSpanItem = StaggeredGridLayoutManager.this.mLazySpanLookup.getFullSpanItem(layoutParams.getViewLayoutPosition())) != null && fullSpanItem.mGapDir == 1) { this.mCachedEnd = fullSpanItem.getGapForSpan(this.mIndex) + this.mCachedEnd; } } public void calculateCachedStart() { LazySpanLookup.FullSpanItem fullSpanItem; View view = this.mViews.get(0); LayoutParams layoutParams = getLayoutParams(view); this.mCachedStart = StaggeredGridLayoutManager.this.mPrimaryOrientation.getDecoratedStart(view); if (layoutParams.mFullSpan && (fullSpanItem = StaggeredGridLayoutManager.this.mLazySpanLookup.getFullSpanItem(layoutParams.getViewLayoutPosition())) != null && fullSpanItem.mGapDir == -1) { this.mCachedStart -= fullSpanItem.getGapForSpan(this.mIndex); } } public void clear() { this.mViews.clear(); invalidateCache(); this.mDeletedSize = 0; } public int findFirstCompletelyVisibleItemPosition() { return StaggeredGridLayoutManager.this.mReverseLayout ? findOneVisibleChild(this.mViews.size() - 1, -1, true) : findOneVisibleChild(0, this.mViews.size(), true); } public int findFirstPartiallyVisibleItemPosition() { return StaggeredGridLayoutManager.this.mReverseLayout ? findOnePartiallyVisibleChild(this.mViews.size() - 1, -1, true) : findOnePartiallyVisibleChild(0, this.mViews.size(), true); } public int findFirstVisibleItemPosition() { return StaggeredGridLayoutManager.this.mReverseLayout ? findOneVisibleChild(this.mViews.size() - 1, -1, false) : findOneVisibleChild(0, this.mViews.size(), false); } public int findLastCompletelyVisibleItemPosition() { return StaggeredGridLayoutManager.this.mReverseLayout ? findOneVisibleChild(0, this.mViews.size(), true) : findOneVisibleChild(this.mViews.size() - 1, -1, true); } public int findLastPartiallyVisibleItemPosition() { return StaggeredGridLayoutManager.this.mReverseLayout ? findOnePartiallyVisibleChild(0, this.mViews.size(), true) : findOnePartiallyVisibleChild(this.mViews.size() - 1, -1, true); } public int findLastVisibleItemPosition() { return StaggeredGridLayoutManager.this.mReverseLayout ? findOneVisibleChild(0, this.mViews.size(), false) : findOneVisibleChild(this.mViews.size() - 1, -1, false); } public int findOnePartiallyOrCompletelyVisibleChild(int i, int i2, boolean z2, boolean z3, boolean z4) { int startAfterPadding = StaggeredGridLayoutManager.this.mPrimaryOrientation.getStartAfterPadding(); int endAfterPadding = StaggeredGridLayoutManager.this.mPrimaryOrientation.getEndAfterPadding(); int i3 = i2 > i ? 1 : -1; while (i != i2) { View view = this.mViews.get(i); int decoratedStart = StaggeredGridLayoutManager.this.mPrimaryOrientation.getDecoratedStart(view); int decoratedEnd = StaggeredGridLayoutManager.this.mPrimaryOrientation.getDecoratedEnd(view); boolean z5 = false; boolean z6 = !z4 ? decoratedStart < endAfterPadding : decoratedStart <= endAfterPadding; if (!z4 ? decoratedEnd > startAfterPadding : decoratedEnd >= startAfterPadding) { z5 = true; } if (z6 && z5) { if (!z2 || !z3) { if (z3) { return StaggeredGridLayoutManager.this.getPosition(view); } if (decoratedStart < startAfterPadding || decoratedEnd > endAfterPadding) { return StaggeredGridLayoutManager.this.getPosition(view); } } else if (decoratedStart >= startAfterPadding && decoratedEnd <= endAfterPadding) { return StaggeredGridLayoutManager.this.getPosition(view); } } i += i3; } return -1; } public int findOnePartiallyVisibleChild(int i, int i2, boolean z2) { return findOnePartiallyOrCompletelyVisibleChild(i, i2, false, false, z2); } public int findOneVisibleChild(int i, int i2, boolean z2) { return findOnePartiallyOrCompletelyVisibleChild(i, i2, z2, true, false); } public int getDeletedSize() { return this.mDeletedSize; } public int getEndLine() { int i = this.mCachedEnd; if (i != Integer.MIN_VALUE) { return i; } calculateCachedEnd(); return this.mCachedEnd; } public int getEndLine(int i) { int i2 = this.mCachedEnd; if (i2 != Integer.MIN_VALUE) { return i2; } if (this.mViews.size() == 0) { return i; } calculateCachedEnd(); return this.mCachedEnd; } public View getFocusableViewAfter(int i, int i2) { View view = null; if (i2 != -1) { int size = this.mViews.size() - 1; while (size >= 0) { View view2 = this.mViews.get(size); StaggeredGridLayoutManager staggeredGridLayoutManager = StaggeredGridLayoutManager.this; if (staggeredGridLayoutManager.mReverseLayout && staggeredGridLayoutManager.getPosition(view2) >= i) { break; } StaggeredGridLayoutManager staggeredGridLayoutManager2 = StaggeredGridLayoutManager.this; if ((!staggeredGridLayoutManager2.mReverseLayout && staggeredGridLayoutManager2.getPosition(view2) <= i) || !view2.hasFocusable()) { break; } size--; view = view2; } } else { int size2 = this.mViews.size(); int i3 = 0; while (i3 < size2) { View view3 = this.mViews.get(i3); StaggeredGridLayoutManager staggeredGridLayoutManager3 = StaggeredGridLayoutManager.this; if (staggeredGridLayoutManager3.mReverseLayout && staggeredGridLayoutManager3.getPosition(view3) <= i) { break; } StaggeredGridLayoutManager staggeredGridLayoutManager4 = StaggeredGridLayoutManager.this; if ((!staggeredGridLayoutManager4.mReverseLayout && staggeredGridLayoutManager4.getPosition(view3) >= i) || !view3.hasFocusable()) { break; } i3++; view = view3; } } return view; } public LayoutParams getLayoutParams(View view) { return (LayoutParams) view.getLayoutParams(); } public int getStartLine() { int i = this.mCachedStart; if (i != Integer.MIN_VALUE) { return i; } calculateCachedStart(); return this.mCachedStart; } public int getStartLine(int i) { int i2 = this.mCachedStart; if (i2 != Integer.MIN_VALUE) { return i2; } if (this.mViews.size() == 0) { return i; } calculateCachedStart(); return this.mCachedStart; } public void invalidateCache() { this.mCachedStart = Integer.MIN_VALUE; this.mCachedEnd = Integer.MIN_VALUE; } public void onOffset(int i) { int i2 = this.mCachedStart; if (i2 != Integer.MIN_VALUE) { this.mCachedStart = i2 + i; } int i3 = this.mCachedEnd; if (i3 != Integer.MIN_VALUE) { this.mCachedEnd = i3 + i; } } public void popEnd() { int size = this.mViews.size(); View remove = this.mViews.remove(size - 1); LayoutParams layoutParams = getLayoutParams(remove); layoutParams.mSpan = null; if (layoutParams.isItemRemoved() || layoutParams.isItemChanged()) { this.mDeletedSize -= StaggeredGridLayoutManager.this.mPrimaryOrientation.getDecoratedMeasurement(remove); } if (size == 1) { this.mCachedStart = Integer.MIN_VALUE; } this.mCachedEnd = Integer.MIN_VALUE; } public void popStart() { View remove = this.mViews.remove(0); LayoutParams layoutParams = getLayoutParams(remove); layoutParams.mSpan = null; if (this.mViews.size() == 0) { this.mCachedEnd = Integer.MIN_VALUE; } if (layoutParams.isItemRemoved() || layoutParams.isItemChanged()) { this.mDeletedSize -= StaggeredGridLayoutManager.this.mPrimaryOrientation.getDecoratedMeasurement(remove); } this.mCachedStart = Integer.MIN_VALUE; } public void prependToSpan(View view) { LayoutParams layoutParams = getLayoutParams(view); layoutParams.mSpan = this; this.mViews.add(0, view); this.mCachedStart = Integer.MIN_VALUE; if (this.mViews.size() == 1) { this.mCachedEnd = Integer.MIN_VALUE; } if (layoutParams.isItemRemoved() || layoutParams.isItemChanged()) { this.mDeletedSize = StaggeredGridLayoutManager.this.mPrimaryOrientation.getDecoratedMeasurement(view) + this.mDeletedSize; } } public void setLine(int i) { this.mCachedStart = i; this.mCachedEnd = i; } } public StaggeredGridLayoutManager(int i, int i2) { this.mOrientation = i2; setSpanCount(i); this.mLayoutState = new LayoutState(); createOrientationHelpers(); } public StaggeredGridLayoutManager(Context context, AttributeSet attributeSet, int i, int i2) { RecyclerView.LayoutManager.Properties properties = RecyclerView.LayoutManager.getProperties(context, attributeSet, i, i2); setOrientation(properties.orientation); setSpanCount(properties.spanCount); setReverseLayout(properties.reverseLayout); this.mLayoutState = new LayoutState(); createOrientationHelpers(); } private void appendViewToAllSpans(View view) { for (int i = this.mSpanCount - 1; i >= 0; i--) { this.mSpans[i].appendToSpan(view); } } private void applyPendingSavedState(AnchorInfo anchorInfo) { SavedState savedState = this.mPendingSavedState; int i = savedState.mSpanOffsetsSize; if (i > 0) { if (i == this.mSpanCount) { for (int i2 = 0; i2 < this.mSpanCount; i2++) { this.mSpans[i2].clear(); SavedState savedState2 = this.mPendingSavedState; int i3 = savedState2.mSpanOffsets[i2]; if (i3 != Integer.MIN_VALUE) { i3 += savedState2.mAnchorLayoutFromEnd ? this.mPrimaryOrientation.getEndAfterPadding() : this.mPrimaryOrientation.getStartAfterPadding(); } this.mSpans[i2].setLine(i3); } } else { savedState.invalidateSpanInfo(); SavedState savedState3 = this.mPendingSavedState; savedState3.mAnchorPosition = savedState3.mVisibleAnchorPosition; } } SavedState savedState4 = this.mPendingSavedState; this.mLastLayoutRTL = savedState4.mLastLayoutRTL; setReverseLayout(savedState4.mReverseLayout); resolveShouldLayoutReverse(); SavedState savedState5 = this.mPendingSavedState; int i4 = savedState5.mAnchorPosition; if (i4 != -1) { this.mPendingScrollPosition = i4; anchorInfo.mLayoutFromEnd = savedState5.mAnchorLayoutFromEnd; } else { anchorInfo.mLayoutFromEnd = this.mShouldReverseLayout; } if (savedState5.mSpanLookupSize > 1) { LazySpanLookup lazySpanLookup = this.mLazySpanLookup; lazySpanLookup.mData = savedState5.mSpanLookup; lazySpanLookup.mFullSpanItems = savedState5.mFullSpanItems; } } private void attachViewToSpans(View view, LayoutParams layoutParams, LayoutState layoutState) { if (layoutState.mLayoutDirection == 1) { if (layoutParams.mFullSpan) { appendViewToAllSpans(view); } else { layoutParams.mSpan.appendToSpan(view); } } else if (layoutParams.mFullSpan) { prependViewToAllSpans(view); } else { layoutParams.mSpan.prependToSpan(view); } } private int calculateScrollDirectionForPosition(int i) { if (getChildCount() == 0) { return this.mShouldReverseLayout ? 1 : -1; } return (i < getFirstChildPosition()) != this.mShouldReverseLayout ? -1 : 1; } private boolean checkSpanForGap(Span span) { if (this.mShouldReverseLayout) { if (span.getEndLine() < this.mPrimaryOrientation.getEndAfterPadding()) { ArrayList arrayList = span.mViews; return !span.getLayoutParams(arrayList.get(arrayList.size() - 1)).mFullSpan; } } else if (span.getStartLine() > this.mPrimaryOrientation.getStartAfterPadding()) { return !span.getLayoutParams(span.mViews.get(0)).mFullSpan; } return false; } private int computeScrollExtent(RecyclerView.State state) { if (getChildCount() == 0) { return 0; } return ScrollbarHelper.computeScrollExtent(state, this.mPrimaryOrientation, findFirstVisibleItemClosestToStart(!this.mSmoothScrollbarEnabled), findFirstVisibleItemClosestToEnd(!this.mSmoothScrollbarEnabled), this, this.mSmoothScrollbarEnabled); } private int computeScrollOffset(RecyclerView.State state) { if (getChildCount() == 0) { return 0; } return ScrollbarHelper.computeScrollOffset(state, this.mPrimaryOrientation, findFirstVisibleItemClosestToStart(!this.mSmoothScrollbarEnabled), findFirstVisibleItemClosestToEnd(!this.mSmoothScrollbarEnabled), this, this.mSmoothScrollbarEnabled, this.mShouldReverseLayout); } private int computeScrollRange(RecyclerView.State state) { if (getChildCount() == 0) { return 0; } return ScrollbarHelper.computeScrollRange(state, this.mPrimaryOrientation, findFirstVisibleItemClosestToStart(!this.mSmoothScrollbarEnabled), findFirstVisibleItemClosestToEnd(!this.mSmoothScrollbarEnabled), this, this.mSmoothScrollbarEnabled); } private 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; } private LazySpanLookup.FullSpanItem createFullSpanItemFromEnd(int i) { LazySpanLookup.FullSpanItem fullSpanItem = new LazySpanLookup.FullSpanItem(); fullSpanItem.mGapPerSpan = new int[this.mSpanCount]; for (int i2 = 0; i2 < this.mSpanCount; i2++) { fullSpanItem.mGapPerSpan[i2] = i - this.mSpans[i2].getEndLine(i); } return fullSpanItem; } private LazySpanLookup.FullSpanItem createFullSpanItemFromStart(int i) { LazySpanLookup.FullSpanItem fullSpanItem = new LazySpanLookup.FullSpanItem(); fullSpanItem.mGapPerSpan = new int[this.mSpanCount]; for (int i2 = 0; i2 < this.mSpanCount; i2++) { fullSpanItem.mGapPerSpan[i2] = this.mSpans[i2].getStartLine(i) - i; } return fullSpanItem; } private void createOrientationHelpers() { this.mPrimaryOrientation = OrientationHelper.createOrientationHelper(this, this.mOrientation); this.mSecondaryOrientation = OrientationHelper.createOrientationHelper(this, 1 - this.mOrientation); } private int fill(RecyclerView.Recycler recycler, LayoutState layoutState, RecyclerView.State state) { int i; Span span; int i2; int i3; int i4; int i5; boolean z2 = false; this.mRemainingSpans.set(0, this.mSpanCount, true); if (this.mLayoutState.mInfinite) { i = layoutState.mLayoutDirection == 1 ? Integer.MAX_VALUE : Integer.MIN_VALUE; } else { i = layoutState.mLayoutDirection == 1 ? layoutState.mEndLine + layoutState.mAvailable : layoutState.mStartLine - layoutState.mAvailable; } updateAllRemainingSpans(layoutState.mLayoutDirection, i); int endAfterPadding = this.mShouldReverseLayout ? this.mPrimaryOrientation.getEndAfterPadding() : this.mPrimaryOrientation.getStartAfterPadding(); boolean z3 = false; while (layoutState.hasMore(state) && (this.mLayoutState.mInfinite || !this.mRemainingSpans.isEmpty())) { View next = layoutState.next(recycler); LayoutParams layoutParams = (LayoutParams) next.getLayoutParams(); int viewLayoutPosition = layoutParams.getViewLayoutPosition(); int span2 = this.mLazySpanLookup.getSpan(viewLayoutPosition); boolean z4 = span2 == -1; if (z4) { if (layoutParams.mFullSpan) { Span[] spanArr = this.mSpans; char c2 = z2 ? 1 : 0; char c3 = z2 ? 1 : 0; char c4 = z2 ? 1 : 0; span = spanArr[c2]; } else { span = getNextSpan(layoutState); } this.mLazySpanLookup.setSpan(viewLayoutPosition, span); } else { span = this.mSpans[span2]; } layoutParams.mSpan = span; if (layoutState.mLayoutDirection == 1) { addView(next); } else { int i6 = z2 ? 1 : 0; int i7 = z2 ? 1 : 0; int i8 = z2 ? 1 : 0; addView(next, i6); } measureChildWithDecorationsAndMargin(next, layoutParams, z2); if (layoutState.mLayoutDirection == 1) { int maxEnd = layoutParams.mFullSpan ? getMaxEnd(endAfterPadding) : span.getEndLine(endAfterPadding); int decoratedMeasurement = this.mPrimaryOrientation.getDecoratedMeasurement(next) + maxEnd; if (z4 && layoutParams.mFullSpan) { LazySpanLookup.FullSpanItem createFullSpanItemFromEnd = createFullSpanItemFromEnd(maxEnd); createFullSpanItemFromEnd.mGapDir = -1; createFullSpanItemFromEnd.mPosition = viewLayoutPosition; this.mLazySpanLookup.addFullSpanItem(createFullSpanItemFromEnd); } i2 = decoratedMeasurement; i3 = maxEnd; } else { int minStart = layoutParams.mFullSpan ? getMinStart(endAfterPadding) : span.getStartLine(endAfterPadding); i3 = minStart - this.mPrimaryOrientation.getDecoratedMeasurement(next); if (z4 && layoutParams.mFullSpan) { LazySpanLookup.FullSpanItem createFullSpanItemFromStart = createFullSpanItemFromStart(minStart); createFullSpanItemFromStart.mGapDir = 1; createFullSpanItemFromStart.mPosition = viewLayoutPosition; this.mLazySpanLookup.addFullSpanItem(createFullSpanItemFromStart); } i2 = minStart; } if (layoutParams.mFullSpan && layoutState.mItemDirection == -1) { if (z4) { this.mLaidOutInvalidFullSpan = true; } else { if (!(layoutState.mLayoutDirection == 1 ? areAllEndsEqual() : areAllStartsEqual())) { LazySpanLookup.FullSpanItem fullSpanItem = this.mLazySpanLookup.getFullSpanItem(viewLayoutPosition); if (fullSpanItem != null) { fullSpanItem.mHasUnwantedGapAfter = true; } this.mLaidOutInvalidFullSpan = true; } } } attachViewToSpans(next, layoutParams, layoutState); if (!isLayoutRTL() || this.mOrientation != 1) { int startAfterPadding = layoutParams.mFullSpan ? this.mSecondaryOrientation.getStartAfterPadding() : (span.mIndex * this.mSizePerSpan) + this.mSecondaryOrientation.getStartAfterPadding(); i5 = startAfterPadding; i4 = this.mSecondaryOrientation.getDecoratedMeasurement(next) + startAfterPadding; } else { int endAfterPadding2 = layoutParams.mFullSpan ? this.mSecondaryOrientation.getEndAfterPadding() : this.mSecondaryOrientation.getEndAfterPadding() - (((this.mSpanCount - 1) - span.mIndex) * this.mSizePerSpan); i4 = endAfterPadding2; i5 = endAfterPadding2 - this.mSecondaryOrientation.getDecoratedMeasurement(next); } if (this.mOrientation == 1) { layoutDecoratedWithMargins(next, i5, i3, i4, i2); } else { layoutDecoratedWithMargins(next, i3, i5, i2, i4); } if (layoutParams.mFullSpan) { updateAllRemainingSpans(this.mLayoutState.mLayoutDirection, i); } else { updateRemainingSpans(span, this.mLayoutState.mLayoutDirection, i); } recycle(recycler, this.mLayoutState); if (this.mLayoutState.mStopInFocusable && next.hasFocusable()) { if (layoutParams.mFullSpan) { this.mRemainingSpans.clear(); } else { this.mRemainingSpans.set(span.mIndex, false); z3 = true; z2 = false; } } z3 = true; z2 = false; } if (!z3) { recycle(recycler, this.mLayoutState); } int startAfterPadding2 = this.mLayoutState.mLayoutDirection == -1 ? this.mPrimaryOrientation.getStartAfterPadding() - getMinStart(this.mPrimaryOrientation.getStartAfterPadding()) : getMaxEnd(this.mPrimaryOrientation.getEndAfterPadding()) - this.mPrimaryOrientation.getEndAfterPadding(); if (startAfterPadding2 > 0) { return Math.min(layoutState.mAvailable, startAfterPadding2); } return 0; } private int findFirstReferenceChildPosition(int i) { int childCount = getChildCount(); for (int i2 = 0; i2 < childCount; i2++) { int position = getPosition(getChildAt(i2)); if (position >= 0 && position < i) { return position; } } return 0; } private int findLastReferenceChildPosition(int i) { for (int childCount = getChildCount() - 1; childCount >= 0; childCount--) { int position = getPosition(getChildAt(childCount)); if (position >= 0 && position < i) { return position; } } return 0; } private void fixEndGap(RecyclerView.Recycler recycler, RecyclerView.State state, boolean z2) { int endAfterPadding; int maxEnd = getMaxEnd(Integer.MIN_VALUE); if (maxEnd != Integer.MIN_VALUE && (endAfterPadding = this.mPrimaryOrientation.getEndAfterPadding() - maxEnd) > 0) { int i = endAfterPadding - (-scrollBy(-endAfterPadding, recycler, state)); if (z2 && i > 0) { this.mPrimaryOrientation.offsetChildren(i); } } } private void fixStartGap(RecyclerView.Recycler recycler, RecyclerView.State state, boolean z2) { int startAfterPadding; int minStart = getMinStart(Integer.MAX_VALUE); if (minStart != Integer.MAX_VALUE && (startAfterPadding = minStart - this.mPrimaryOrientation.getStartAfterPadding()) > 0) { int scrollBy = startAfterPadding - scrollBy(startAfterPadding, recycler, state); if (z2 && scrollBy > 0) { this.mPrimaryOrientation.offsetChildren(-scrollBy); } } } private int getMaxEnd(int i) { int endLine = this.mSpans[0].getEndLine(i); for (int i2 = 1; i2 < this.mSpanCount; i2++) { int endLine2 = this.mSpans[i2].getEndLine(i); if (endLine2 > endLine) { endLine = endLine2; } } return endLine; } private int getMaxStart(int i) { int startLine = this.mSpans[0].getStartLine(i); for (int i2 = 1; i2 < this.mSpanCount; i2++) { int startLine2 = this.mSpans[i2].getStartLine(i); if (startLine2 > startLine) { startLine = startLine2; } } return startLine; } private int getMinEnd(int i) { int endLine = this.mSpans[0].getEndLine(i); for (int i2 = 1; i2 < this.mSpanCount; i2++) { int endLine2 = this.mSpans[i2].getEndLine(i); if (endLine2 < endLine) { endLine = endLine2; } } return endLine; } private int getMinStart(int i) { int startLine = this.mSpans[0].getStartLine(i); for (int i2 = 1; i2 < this.mSpanCount; i2++) { int startLine2 = this.mSpans[i2].getStartLine(i); if (startLine2 < startLine) { startLine = startLine2; } } return startLine; } private Span getNextSpan(LayoutState layoutState) { int i; int i2; int i3 = -1; if (preferLastSpan(layoutState.mLayoutDirection)) { i2 = this.mSpanCount - 1; i = -1; } else { i2 = 0; i3 = this.mSpanCount; i = 1; } Span span = null; if (layoutState.mLayoutDirection == 1) { int i4 = Integer.MAX_VALUE; int startAfterPadding = this.mPrimaryOrientation.getStartAfterPadding(); while (i2 != i3) { Span span2 = this.mSpans[i2]; int endLine = span2.getEndLine(startAfterPadding); if (endLine < i4) { span = span2; i4 = endLine; } i2 += i; } return span; } int i5 = Integer.MIN_VALUE; int endAfterPadding = this.mPrimaryOrientation.getEndAfterPadding(); while (i2 != i3) { Span span3 = this.mSpans[i2]; int startLine = span3.getStartLine(endAfterPadding); if (startLine > i5) { span = span3; i5 = startLine; } i2 += i; } return span; } /* JADX WARNING: Removed duplicated region for block: B:13:0x0025 */ /* JADX WARNING: Removed duplicated region for block: B:18:0x003c */ /* JADX WARNING: Removed duplicated region for block: B:20:0x0043 A[RETURN] */ /* JADX WARNING: Removed duplicated region for block: B:21:0x0044 */ private void handleUpdate(int i, int i2, int i3) { int i4; int i5; int lastChildPosition = this.mShouldReverseLayout ? getLastChildPosition() : getFirstChildPosition(); if (i3 != 8) { i5 = i + i2; } else if (i < i2) { i5 = i2 + 1; } else { i5 = i + 1; i4 = i2; this.mLazySpanLookup.invalidateAfter(i4); if (i3 != 1) { this.mLazySpanLookup.offsetForAddition(i, i2); } else if (i3 == 2) { this.mLazySpanLookup.offsetForRemoval(i, i2); } else if (i3 == 8) { this.mLazySpanLookup.offsetForRemoval(i, 1); this.mLazySpanLookup.offsetForAddition(i2, 1); } if (i5 <= lastChildPosition) { if (i4 <= (this.mShouldReverseLayout ? getFirstChildPosition() : getLastChildPosition())) { requestLayout(); return; } return; } return; } i4 = i; this.mLazySpanLookup.invalidateAfter(i4); if (i3 != 1) { } if (i5 <= lastChildPosition) { } } private void measureChildWithDecorationsAndMargin(View view, int i, int i2, boolean z2) { calculateItemDecorationsForChild(view, this.mTmpRect); LayoutParams layoutParams = (LayoutParams) view.getLayoutParams(); int i3 = ((ViewGroup.MarginLayoutParams) layoutParams).leftMargin; Rect rect = this.mTmpRect; int updateSpecWithExtra = updateSpecWithExtra(i, i3 + rect.left, ((ViewGroup.MarginLayoutParams) layoutParams).rightMargin + rect.right); int i4 = ((ViewGroup.MarginLayoutParams) layoutParams).topMargin; Rect rect2 = this.mTmpRect; int updateSpecWithExtra2 = updateSpecWithExtra(i2, i4 + rect2.top, ((ViewGroup.MarginLayoutParams) layoutParams).bottomMargin + rect2.bottom); if (z2 ? shouldReMeasureChild(view, updateSpecWithExtra, updateSpecWithExtra2, layoutParams) : shouldMeasureChild(view, updateSpecWithExtra, updateSpecWithExtra2, layoutParams)) { view.measure(updateSpecWithExtra, updateSpecWithExtra2); } } private void measureChildWithDecorationsAndMargin(View view, LayoutParams layoutParams, boolean z2) { if (layoutParams.mFullSpan) { if (this.mOrientation == 1) { measureChildWithDecorationsAndMargin(view, this.mFullSizeSpec, RecyclerView.LayoutManager.getChildMeasureSpec(getHeight(), getHeightMode(), getPaddingBottom() + getPaddingTop(), ((ViewGroup.MarginLayoutParams) layoutParams).height, true), z2); return; } measureChildWithDecorationsAndMargin(view, RecyclerView.LayoutManager.getChildMeasureSpec(getWidth(), getWidthMode(), getPaddingRight() + getPaddingLeft(), ((ViewGroup.MarginLayoutParams) layoutParams).width, true), this.mFullSizeSpec, z2); } else if (this.mOrientation == 1) { measureChildWithDecorationsAndMargin(view, RecyclerView.LayoutManager.getChildMeasureSpec(this.mSizePerSpan, getWidthMode(), 0, ((ViewGroup.MarginLayoutParams) layoutParams).width, false), RecyclerView.LayoutManager.getChildMeasureSpec(getHeight(), getHeightMode(), getPaddingBottom() + getPaddingTop(), ((ViewGroup.MarginLayoutParams) layoutParams).height, true), z2); } else { measureChildWithDecorationsAndMargin(view, RecyclerView.LayoutManager.getChildMeasureSpec(getWidth(), getWidthMode(), getPaddingRight() + getPaddingLeft(), ((ViewGroup.MarginLayoutParams) layoutParams).width, true), RecyclerView.LayoutManager.getChildMeasureSpec(this.mSizePerSpan, getHeightMode(), 0, ((ViewGroup.MarginLayoutParams) layoutParams).height, false), z2); } } /* JADX WARNING: Code restructure failed: missing block: B:83:0x0157, code lost: if (checkForGaps() != false) goto L_0x015b; */ private void onLayoutChildren(RecyclerView.Recycler recycler, RecyclerView.State state, boolean z2) { SavedState savedState; AnchorInfo anchorInfo = this.mAnchorInfo; if (!(this.mPendingSavedState == null && this.mPendingScrollPosition == -1) && state.getItemCount() == 0) { removeAndRecycleAllViews(recycler); anchorInfo.reset(); return; } boolean z3 = true; boolean z4 = (anchorInfo.mValid && this.mPendingScrollPosition == -1 && this.mPendingSavedState == null) ? false : true; if (z4) { anchorInfo.reset(); if (this.mPendingSavedState != null) { applyPendingSavedState(anchorInfo); } else { resolveShouldLayoutReverse(); anchorInfo.mLayoutFromEnd = this.mShouldReverseLayout; } updateAnchorInfoForLayout(state, anchorInfo); anchorInfo.mValid = true; } if (this.mPendingSavedState == null && this.mPendingScrollPosition == -1 && !(anchorInfo.mLayoutFromEnd == this.mLastLayoutFromEnd && isLayoutRTL() == this.mLastLayoutRTL)) { this.mLazySpanLookup.clear(); anchorInfo.mInvalidateOffsets = true; } if (getChildCount() > 0 && ((savedState = this.mPendingSavedState) == null || savedState.mSpanOffsetsSize < 1)) { if (anchorInfo.mInvalidateOffsets) { for (int i = 0; i < this.mSpanCount; i++) { this.mSpans[i].clear(); int i2 = anchorInfo.mOffset; if (i2 != Integer.MIN_VALUE) { this.mSpans[i].setLine(i2); } } } else if (z4 || this.mAnchorInfo.mSpanReferenceLines == null) { for (int i3 = 0; i3 < this.mSpanCount; i3++) { this.mSpans[i3].cacheReferenceLineAndClear(this.mShouldReverseLayout, anchorInfo.mOffset); } this.mAnchorInfo.saveSpanReferenceLines(this.mSpans); } else { for (int i4 = 0; i4 < this.mSpanCount; i4++) { Span span = this.mSpans[i4]; span.clear(); span.setLine(this.mAnchorInfo.mSpanReferenceLines[i4]); } } } detachAndScrapAttachedViews(recycler); this.mLayoutState.mRecycle = false; this.mLaidOutInvalidFullSpan = false; updateMeasureSpecs(this.mSecondaryOrientation.getTotalSpace()); updateLayoutState(anchorInfo.mPosition, state); if (anchorInfo.mLayoutFromEnd) { setLayoutStateDirection(-1); fill(recycler, this.mLayoutState, state); setLayoutStateDirection(1); LayoutState layoutState = this.mLayoutState; layoutState.mCurrentPosition = anchorInfo.mPosition + layoutState.mItemDirection; fill(recycler, layoutState, state); } else { setLayoutStateDirection(1); fill(recycler, this.mLayoutState, state); setLayoutStateDirection(-1); LayoutState layoutState2 = this.mLayoutState; layoutState2.mCurrentPosition = anchorInfo.mPosition + layoutState2.mItemDirection; fill(recycler, layoutState2, state); } repositionToWrapContentIfNecessary(); if (getChildCount() > 0) { if (this.mShouldReverseLayout) { fixEndGap(recycler, state, true); fixStartGap(recycler, state, false); } else { fixStartGap(recycler, state, true); fixEndGap(recycler, state, false); } } if (z2 && !state.isPreLayout()) { if (this.mGapStrategy != 0 && getChildCount() > 0 && (this.mLaidOutInvalidFullSpan || hasGapsToFix() != null)) { removeCallbacks(this.mCheckForGapsRunnable); } } z3 = false; if (state.isPreLayout()) { this.mAnchorInfo.reset(); } this.mLastLayoutFromEnd = anchorInfo.mLayoutFromEnd; this.mLastLayoutRTL = isLayoutRTL(); if (z3) { this.mAnchorInfo.reset(); onLayoutChildren(recycler, state, false); } } private boolean preferLastSpan(int i) { if (this.mOrientation == 0) { return (i == -1) != this.mShouldReverseLayout; } return ((i == -1) == this.mShouldReverseLayout) == isLayoutRTL(); } private void prependViewToAllSpans(View view) { for (int i = this.mSpanCount - 1; i >= 0; i--) { this.mSpans[i].prependToSpan(view); } } private void recycle(RecyclerView.Recycler recycler, LayoutState layoutState) { if (layoutState.mRecycle && !layoutState.mInfinite) { if (layoutState.mAvailable == 0) { if (layoutState.mLayoutDirection == -1) { recycleFromEnd(recycler, layoutState.mEndLine); } else { recycleFromStart(recycler, layoutState.mStartLine); } } else if (layoutState.mLayoutDirection == -1) { int i = layoutState.mStartLine; int maxStart = i - getMaxStart(i); recycleFromEnd(recycler, maxStart < 0 ? layoutState.mEndLine : layoutState.mEndLine - Math.min(maxStart, layoutState.mAvailable)); } else { int minEnd = getMinEnd(layoutState.mEndLine) - layoutState.mEndLine; recycleFromStart(recycler, minEnd < 0 ? layoutState.mStartLine : Math.min(minEnd, layoutState.mAvailable) + layoutState.mStartLine); } } } private void recycleFromEnd(RecyclerView.Recycler recycler, int i) { for (int childCount = getChildCount() - 1; childCount >= 0; childCount--) { View childAt = getChildAt(childCount); if (this.mPrimaryOrientation.getDecoratedStart(childAt) >= i && this.mPrimaryOrientation.getTransformedStartWithDecoration(childAt) >= i) { LayoutParams layoutParams = (LayoutParams) childAt.getLayoutParams(); if (layoutParams.mFullSpan) { for (int i2 = 0; i2 < this.mSpanCount; i2++) { if (this.mSpans[i2].mViews.size() == 1) { return; } } for (int i3 = 0; i3 < this.mSpanCount; i3++) { this.mSpans[i3].popEnd(); } } else if (layoutParams.mSpan.mViews.size() != 1) { layoutParams.mSpan.popEnd(); } else { return; } removeAndRecycleView(childAt, recycler); } else { return; } } } private void recycleFromStart(RecyclerView.Recycler recycler, int i) { while (getChildCount() > 0) { View childAt = getChildAt(0); if (this.mPrimaryOrientation.getDecoratedEnd(childAt) <= i && this.mPrimaryOrientation.getTransformedEndWithDecoration(childAt) <= i) { LayoutParams layoutParams = (LayoutParams) childAt.getLayoutParams(); if (layoutParams.mFullSpan) { for (int i2 = 0; i2 < this.mSpanCount; i2++) { if (this.mSpans[i2].mViews.size() == 1) { return; } } for (int i3 = 0; i3 < this.mSpanCount; i3++) { this.mSpans[i3].popStart(); } } else if (layoutParams.mSpan.mViews.size() != 1) { layoutParams.mSpan.popStart(); } else { return; } removeAndRecycleView(childAt, recycler); } else { return; } } } private void repositionToWrapContentIfNecessary() { if (this.mSecondaryOrientation.getMode() != 1073741824) { float f = 0.0f; int childCount = getChildCount(); for (int i = 0; i < childCount; i++) { View childAt = getChildAt(i); float decoratedMeasurement = (float) this.mSecondaryOrientation.getDecoratedMeasurement(childAt); if (decoratedMeasurement >= f) { if (((LayoutParams) childAt.getLayoutParams()).isFullSpan()) { decoratedMeasurement = (decoratedMeasurement * 1.0f) / ((float) this.mSpanCount); } f = Math.max(f, decoratedMeasurement); } } int i2 = this.mSizePerSpan; int round = Math.round(f * ((float) this.mSpanCount)); if (this.mSecondaryOrientation.getMode() == Integer.MIN_VALUE) { round = Math.min(round, this.mSecondaryOrientation.getTotalSpace()); } updateMeasureSpecs(round); if (this.mSizePerSpan != i2) { for (int i3 = 0; i3 < childCount; i3++) { View childAt2 = getChildAt(i3); LayoutParams layoutParams = (LayoutParams) childAt2.getLayoutParams(); if (!layoutParams.mFullSpan) { if (!isLayoutRTL() || this.mOrientation != 1) { int i4 = layoutParams.mSpan.mIndex; int i5 = this.mSizePerSpan * i4; int i6 = i4 * i2; if (this.mOrientation == 1) { childAt2.offsetLeftAndRight(i5 - i6); } else { childAt2.offsetTopAndBottom(i5 - i6); } } else { int i7 = this.mSpanCount; int i8 = layoutParams.mSpan.mIndex; childAt2.offsetLeftAndRight(((-((i7 - 1) - i8)) * this.mSizePerSpan) - ((-((i7 - 1) - i8)) * i2)); } } } } } } private void resolveShouldLayoutReverse() { if (this.mOrientation == 1 || !isLayoutRTL()) { this.mShouldReverseLayout = this.mReverseLayout; } else { this.mShouldReverseLayout = !this.mReverseLayout; } } private void setLayoutStateDirection(int i) { LayoutState layoutState = this.mLayoutState; layoutState.mLayoutDirection = i; int i2 = 1; if (this.mShouldReverseLayout != (i == -1)) { i2 = -1; } layoutState.mItemDirection = i2; } private void updateAllRemainingSpans(int i, int i2) { for (int i3 = 0; i3 < this.mSpanCount; i3++) { if (!this.mSpans[i3].mViews.isEmpty()) { updateRemainingSpans(this.mSpans[i3], i, i2); } } } private boolean updateAnchorFromChildren(RecyclerView.State state, AnchorInfo anchorInfo) { anchorInfo.mPosition = this.mLastLayoutFromEnd ? findLastReferenceChildPosition(state.getItemCount()) : findFirstReferenceChildPosition(state.getItemCount()); anchorInfo.mOffset = Integer.MIN_VALUE; return true; } /* JADX WARNING: Removed duplicated region for block: B:15:0x0036 */ /* JADX WARNING: Removed duplicated region for block: B:16:0x004d */ private void updateLayoutState(int i, RecyclerView.State state) { int i2; int i3; int targetScrollPosition; LayoutState layoutState = this.mLayoutState; boolean z2 = false; layoutState.mAvailable = 0; layoutState.mCurrentPosition = i; if (!isSmoothScrolling() || (targetScrollPosition = state.getTargetScrollPosition()) == -1) { i3 = 0; } else { if (this.mShouldReverseLayout == (targetScrollPosition < i)) { i3 = this.mPrimaryOrientation.getTotalSpace(); } else { i2 = this.mPrimaryOrientation.getTotalSpace(); i3 = 0; if (!getClipToPadding()) { this.mLayoutState.mStartLine = this.mPrimaryOrientation.getStartAfterPadding() - i2; this.mLayoutState.mEndLine = this.mPrimaryOrientation.getEndAfterPadding() + i3; } else { this.mLayoutState.mEndLine = this.mPrimaryOrientation.getEnd() + i3; this.mLayoutState.mStartLine = -i2; } LayoutState layoutState2 = this.mLayoutState; layoutState2.mStopInFocusable = false; layoutState2.mRecycle = true; if (this.mPrimaryOrientation.getMode() == 0 && this.mPrimaryOrientation.getEnd() == 0) { z2 = true; } layoutState2.mInfinite = z2; } } i2 = 0; if (!getClipToPadding()) { } LayoutState layoutState2 = this.mLayoutState; layoutState2.mStopInFocusable = false; layoutState2.mRecycle = true; z2 = true; layoutState2.mInfinite = z2; } private void updateRemainingSpans(Span span, int i, int i2) { int deletedSize = span.getDeletedSize(); if (i == -1) { if (span.getStartLine() + deletedSize <= i2) { this.mRemainingSpans.set(span.mIndex, false); } } else if (span.getEndLine() - deletedSize >= i2) { this.mRemainingSpans.set(span.mIndex, false); } } private int updateSpecWithExtra(int i, int i2, int i3) { if (i2 == 0 && i3 == 0) { return i; } int mode = View.MeasureSpec.getMode(i); return (mode == Integer.MIN_VALUE || mode == 1073741824) ? View.MeasureSpec.makeMeasureSpec(Math.max(0, (View.MeasureSpec.getSize(i) - i2) - i3), mode) : i; } public boolean areAllEndsEqual() { int endLine = this.mSpans[0].getEndLine(Integer.MIN_VALUE); for (int i = 1; i < this.mSpanCount; i++) { if (this.mSpans[i].getEndLine(Integer.MIN_VALUE) != endLine) { return false; } } return true; } public boolean areAllStartsEqual() { int startLine = this.mSpans[0].getStartLine(Integer.MIN_VALUE); for (int i = 1; i < this.mSpanCount; i++) { if (this.mSpans[i].getStartLine(Integer.MIN_VALUE) != startLine) { return false; } } return true; } @Override // androidx.recyclerview.widget.RecyclerView.LayoutManager public void assertNotInLayoutOrScroll(String str) { if (this.mPendingSavedState == null) { super.assertNotInLayoutOrScroll(str); } } @Override // androidx.recyclerview.widget.RecyclerView.LayoutManager public boolean canScrollHorizontally() { return this.mOrientation == 0; } @Override // androidx.recyclerview.widget.RecyclerView.LayoutManager public boolean canScrollVertically() { return this.mOrientation == 1; } public boolean checkForGaps() { int i; int i2; if (getChildCount() == 0 || this.mGapStrategy == 0 || !isAttachedToWindow()) { return false; } if (this.mShouldReverseLayout) { i2 = getLastChildPosition(); i = getFirstChildPosition(); } else { i2 = getFirstChildPosition(); i = getLastChildPosition(); } if (i2 == 0 && hasGapsToFix() != null) { this.mLazySpanLookup.clear(); requestSimpleAnimationsInNextLayout(); requestLayout(); return true; } else if (!this.mLaidOutInvalidFullSpan) { return false; } else { int i3 = this.mShouldReverseLayout ? -1 : 1; int i4 = i + 1; LazySpanLookup.FullSpanItem firstFullSpanItemInRange = this.mLazySpanLookup.getFirstFullSpanItemInRange(i2, i4, i3, true); if (firstFullSpanItemInRange == null) { this.mLaidOutInvalidFullSpan = false; this.mLazySpanLookup.forceInvalidateAfter(i4); return false; } LazySpanLookup.FullSpanItem firstFullSpanItemInRange2 = this.mLazySpanLookup.getFirstFullSpanItemInRange(i2, firstFullSpanItemInRange.mPosition, i3 * -1, true); if (firstFullSpanItemInRange2 == null) { this.mLazySpanLookup.forceInvalidateAfter(firstFullSpanItemInRange.mPosition); } else { this.mLazySpanLookup.forceInvalidateAfter(firstFullSpanItemInRange2.mPosition + 1); } requestSimpleAnimationsInNextLayout(); requestLayout(); return true; } } @Override // androidx.recyclerview.widget.RecyclerView.LayoutManager public boolean checkLayoutParams(RecyclerView.LayoutParams layoutParams) { return layoutParams instanceof LayoutParams; } @Override // androidx.recyclerview.widget.RecyclerView.LayoutManager @RestrictTo({RestrictTo.Scope.LIBRARY}) public void collectAdjacentPrefetchPositions(int i, int i2, RecyclerView.State state, RecyclerView.LayoutManager.LayoutPrefetchRegistry layoutPrefetchRegistry) { int i3; int i4; if (this.mOrientation != 0) { i = i2; } if (!(getChildCount() == 0 || i == 0)) { prepareLayoutStateForDelta(i, state); int[] iArr = this.mPrefetchDistances; if (iArr == null || iArr.length < this.mSpanCount) { this.mPrefetchDistances = new int[this.mSpanCount]; } int i5 = 0; for (int i6 = 0; i6 < this.mSpanCount; i6++) { LayoutState layoutState = this.mLayoutState; if (layoutState.mItemDirection == -1) { i4 = layoutState.mStartLine; i3 = this.mSpans[i6].getStartLine(i4); } else { i4 = this.mSpans[i6].getEndLine(layoutState.mEndLine); i3 = this.mLayoutState.mEndLine; } int i7 = i4 - i3; if (i7 >= 0) { this.mPrefetchDistances[i5] = i7; i5++; } } Arrays.sort(this.mPrefetchDistances, 0, i5); for (int i8 = 0; i8 < i5 && this.mLayoutState.hasMore(state); i8++) { layoutPrefetchRegistry.addPosition(this.mLayoutState.mCurrentPosition, this.mPrefetchDistances[i8]); LayoutState layoutState2 = this.mLayoutState; layoutState2.mCurrentPosition += layoutState2.mItemDirection; } } } @Override // androidx.recyclerview.widget.RecyclerView.LayoutManager public int computeHorizontalScrollExtent(RecyclerView.State state) { return computeScrollExtent(state); } @Override // androidx.recyclerview.widget.RecyclerView.LayoutManager public int computeHorizontalScrollOffset(RecyclerView.State state) { return computeScrollOffset(state); } @Override // androidx.recyclerview.widget.RecyclerView.LayoutManager public int computeHorizontalScrollRange(RecyclerView.State state) { return computeScrollRange(state); } @Override // androidx.recyclerview.widget.RecyclerView.SmoothScroller.ScrollVectorProvider public PointF computeScrollVectorForPosition(int i) { int calculateScrollDirectionForPosition = calculateScrollDirectionForPosition(i); PointF pointF = new PointF(); if (calculateScrollDirectionForPosition == 0) { return null; } if (this.mOrientation == 0) { pointF.x = (float) calculateScrollDirectionForPosition; pointF.y = 0.0f; } else { pointF.x = 0.0f; pointF.y = (float) calculateScrollDirectionForPosition; } return pointF; } @Override // androidx.recyclerview.widget.RecyclerView.LayoutManager public int computeVerticalScrollExtent(RecyclerView.State state) { return computeScrollExtent(state); } @Override // androidx.recyclerview.widget.RecyclerView.LayoutManager public int computeVerticalScrollOffset(RecyclerView.State state) { return computeScrollOffset(state); } @Override // androidx.recyclerview.widget.RecyclerView.LayoutManager public int computeVerticalScrollRange(RecyclerView.State state) { return computeScrollRange(state); } public int[] findFirstCompletelyVisibleItemPositions(int[] iArr) { if (iArr == null) { iArr = new int[this.mSpanCount]; } else if (iArr.length < this.mSpanCount) { StringBuilder L = a.L("Provided int[]'s size must be more than or equal to span count. Expected:"); L.append(this.mSpanCount); L.append(", array size:"); L.append(iArr.length); throw new IllegalArgumentException(L.toString()); } for (int i = 0; i < this.mSpanCount; i++) { iArr[i] = this.mSpans[i].findFirstCompletelyVisibleItemPosition(); } return iArr; } public View findFirstVisibleItemClosestToEnd(boolean z2) { int startAfterPadding = this.mPrimaryOrientation.getStartAfterPadding(); int endAfterPadding = this.mPrimaryOrientation.getEndAfterPadding(); View view = null; for (int childCount = getChildCount() - 1; childCount >= 0; childCount--) { View childAt = getChildAt(childCount); int decoratedStart = this.mPrimaryOrientation.getDecoratedStart(childAt); int decoratedEnd = this.mPrimaryOrientation.getDecoratedEnd(childAt); if (decoratedEnd > startAfterPadding && decoratedStart < endAfterPadding) { if (decoratedEnd <= endAfterPadding || !z2) { return childAt; } if (view == null) { view = childAt; } } } return view; } public View findFirstVisibleItemClosestToStart(boolean z2) { int startAfterPadding = this.mPrimaryOrientation.getStartAfterPadding(); int endAfterPadding = this.mPrimaryOrientation.getEndAfterPadding(); int childCount = getChildCount(); View view = null; for (int i = 0; i < childCount; i++) { View childAt = getChildAt(i); int decoratedStart = this.mPrimaryOrientation.getDecoratedStart(childAt); if (this.mPrimaryOrientation.getDecoratedEnd(childAt) > startAfterPadding && decoratedStart < endAfterPadding) { if (decoratedStart >= startAfterPadding || !z2) { return childAt; } if (view == null) { view = childAt; } } } return view; } public int findFirstVisibleItemPositionInt() { View findFirstVisibleItemClosestToEnd = this.mShouldReverseLayout ? findFirstVisibleItemClosestToEnd(true) : findFirstVisibleItemClosestToStart(true); if (findFirstVisibleItemClosestToEnd == null) { return -1; } return getPosition(findFirstVisibleItemClosestToEnd); } public int[] findFirstVisibleItemPositions(int[] iArr) { if (iArr == null) { iArr = new int[this.mSpanCount]; } else if (iArr.length < this.mSpanCount) { StringBuilder L = a.L("Provided int[]'s size must be more than or equal to span count. Expected:"); L.append(this.mSpanCount); L.append(", array size:"); L.append(iArr.length); throw new IllegalArgumentException(L.toString()); } for (int i = 0; i < this.mSpanCount; i++) { iArr[i] = this.mSpans[i].findFirstVisibleItemPosition(); } return iArr; } public int[] findLastCompletelyVisibleItemPositions(int[] iArr) { if (iArr == null) { iArr = new int[this.mSpanCount]; } else if (iArr.length < this.mSpanCount) { StringBuilder L = a.L("Provided int[]'s size must be more than or equal to span count. Expected:"); L.append(this.mSpanCount); L.append(", array size:"); L.append(iArr.length); throw new IllegalArgumentException(L.toString()); } for (int i = 0; i < this.mSpanCount; i++) { iArr[i] = this.mSpans[i].findLastCompletelyVisibleItemPosition(); } return iArr; } public int[] findLastVisibleItemPositions(int[] iArr) { if (iArr == null) { iArr = new int[this.mSpanCount]; } else if (iArr.length < this.mSpanCount) { StringBuilder L = a.L("Provided int[]'s size must be more than or equal to span count. Expected:"); L.append(this.mSpanCount); L.append(", array size:"); L.append(iArr.length); throw new IllegalArgumentException(L.toString()); } for (int i = 0; i < this.mSpanCount; i++) { iArr[i] = this.mSpans[i].findLastVisibleItemPosition(); } return iArr; } @Override // androidx.recyclerview.widget.RecyclerView.LayoutManager public RecyclerView.LayoutParams generateDefaultLayoutParams() { return this.mOrientation == 0 ? new LayoutParams(-2, -1) : new LayoutParams(-1, -2); } @Override // androidx.recyclerview.widget.RecyclerView.LayoutManager public RecyclerView.LayoutParams generateLayoutParams(Context context, AttributeSet attributeSet) { return new LayoutParams(context, attributeSet); } @Override // androidx.recyclerview.widget.RecyclerView.LayoutManager public RecyclerView.LayoutParams generateLayoutParams(ViewGroup.LayoutParams layoutParams) { return layoutParams instanceof ViewGroup.MarginLayoutParams ? new LayoutParams((ViewGroup.MarginLayoutParams) layoutParams) : new LayoutParams(layoutParams); } @Override // androidx.recyclerview.widget.RecyclerView.LayoutManager public int getColumnCountForAccessibility(RecyclerView.Recycler recycler, RecyclerView.State state) { return this.mOrientation == 1 ? this.mSpanCount : super.getColumnCountForAccessibility(recycler, state); } public int getFirstChildPosition() { if (getChildCount() == 0) { return 0; } return getPosition(getChildAt(0)); } public int getGapStrategy() { return this.mGapStrategy; } public int getLastChildPosition() { int childCount = getChildCount(); if (childCount == 0) { return 0; } return getPosition(getChildAt(childCount - 1)); } public int getOrientation() { return this.mOrientation; } public boolean getReverseLayout() { return this.mReverseLayout; } @Override // androidx.recyclerview.widget.RecyclerView.LayoutManager public int getRowCountForAccessibility(RecyclerView.Recycler recycler, RecyclerView.State state) { return this.mOrientation == 0 ? this.mSpanCount : super.getRowCountForAccessibility(recycler, state); } public int getSpanCount() { return this.mSpanCount; } /* JADX WARNING: Code restructure failed: missing block: B:28:0x0074, code lost: if (r10 == r11) goto L_0x0088; */ /* JADX WARNING: Code restructure failed: missing block: B:32:0x0086, code lost: if (r10 == r11) goto L_0x0088; */ /* JADX WARNING: Code restructure failed: missing block: B:34:0x008a, code lost: r10 = false; */ public View hasGapsToFix() { int i; int i2; int childCount = getChildCount() - 1; BitSet bitSet = new BitSet(this.mSpanCount); bitSet.set(0, this.mSpanCount, true); int i3 = -1; char c2 = (this.mOrientation != 1 || !isLayoutRTL()) ? (char) 65535 : 1; if (this.mShouldReverseLayout) { i = -1; } else { i = childCount + 1; childCount = 0; } if (childCount < i) { i3 = 1; } while (childCount != i) { View childAt = getChildAt(childCount); LayoutParams layoutParams = (LayoutParams) childAt.getLayoutParams(); if (bitSet.get(layoutParams.mSpan.mIndex)) { if (checkSpanForGap(layoutParams.mSpan)) { return childAt; } bitSet.clear(layoutParams.mSpan.mIndex); } if (!layoutParams.mFullSpan && (i2 = childCount + i3) != i) { View childAt2 = getChildAt(i2); if (this.mShouldReverseLayout) { int decoratedEnd = this.mPrimaryOrientation.getDecoratedEnd(childAt); int decoratedEnd2 = this.mPrimaryOrientation.getDecoratedEnd(childAt2); if (decoratedEnd < decoratedEnd2) { return childAt; } } else { int decoratedStart = this.mPrimaryOrientation.getDecoratedStart(childAt); int decoratedStart2 = this.mPrimaryOrientation.getDecoratedStart(childAt2); if (decoratedStart > decoratedStart2) { return childAt; } } boolean z2 = true; if (!z2) { continue; } else { if ((layoutParams.mSpan.mIndex - ((LayoutParams) childAt2.getLayoutParams()).mSpan.mIndex < 0) != (c2 < 0)) { return childAt; } } } childCount += i3; } return null; } public void invalidateSpanAssignments() { this.mLazySpanLookup.clear(); requestLayout(); } @Override // androidx.recyclerview.widget.RecyclerView.LayoutManager public boolean isAutoMeasureEnabled() { return this.mGapStrategy != 0; } public boolean isLayoutRTL() { return getLayoutDirection() == 1; } @Override // androidx.recyclerview.widget.RecyclerView.LayoutManager public void offsetChildrenHorizontal(int i) { super.offsetChildrenHorizontal(i); for (int i2 = 0; i2 < this.mSpanCount; i2++) { this.mSpans[i2].onOffset(i); } } @Override // androidx.recyclerview.widget.RecyclerView.LayoutManager public void offsetChildrenVertical(int i) { super.offsetChildrenVertical(i); for (int i2 = 0; i2 < this.mSpanCount; i2++) { this.mSpans[i2].onOffset(i); } } @Override // androidx.recyclerview.widget.RecyclerView.LayoutManager public void onDetachedFromWindow(RecyclerView recyclerView, RecyclerView.Recycler recycler) { super.onDetachedFromWindow(recyclerView, recycler); removeCallbacks(this.mCheckForGapsRunnable); for (int i = 0; i < this.mSpanCount; i++) { this.mSpans[i].clear(); } recyclerView.requestLayout(); } @Override // androidx.recyclerview.widget.RecyclerView.LayoutManager @Nullable public View onFocusSearchFailed(View view, int i, RecyclerView.Recycler recycler, RecyclerView.State state) { View findContainingItemView; View focusableViewAfter; if (getChildCount() == 0 || (findContainingItemView = findContainingItemView(view)) == null) { return null; } resolveShouldLayoutReverse(); int convertFocusDirectionToLayoutDirection = convertFocusDirectionToLayoutDirection(i); if (convertFocusDirectionToLayoutDirection == Integer.MIN_VALUE) { return null; } LayoutParams layoutParams = (LayoutParams) findContainingItemView.getLayoutParams(); boolean z2 = layoutParams.mFullSpan; Span span = layoutParams.mSpan; int lastChildPosition = convertFocusDirectionToLayoutDirection == 1 ? getLastChildPosition() : getFirstChildPosition(); updateLayoutState(lastChildPosition, state); setLayoutStateDirection(convertFocusDirectionToLayoutDirection); LayoutState layoutState = this.mLayoutState; layoutState.mCurrentPosition = layoutState.mItemDirection + lastChildPosition; layoutState.mAvailable = (int) (((float) this.mPrimaryOrientation.getTotalSpace()) * 0.33333334f); LayoutState layoutState2 = this.mLayoutState; layoutState2.mStopInFocusable = true; layoutState2.mRecycle = false; fill(recycler, layoutState2, state); this.mLastLayoutFromEnd = this.mShouldReverseLayout; if (!(z2 || (focusableViewAfter = span.getFocusableViewAfter(lastChildPosition, convertFocusDirectionToLayoutDirection)) == null || focusableViewAfter == findContainingItemView)) { return focusableViewAfter; } if (preferLastSpan(convertFocusDirectionToLayoutDirection)) { for (int i2 = this.mSpanCount - 1; i2 >= 0; i2--) { View focusableViewAfter2 = this.mSpans[i2].getFocusableViewAfter(lastChildPosition, convertFocusDirectionToLayoutDirection); if (!(focusableViewAfter2 == null || focusableViewAfter2 == findContainingItemView)) { return focusableViewAfter2; } } } else { for (int i3 = 0; i3 < this.mSpanCount; i3++) { View focusableViewAfter3 = this.mSpans[i3].getFocusableViewAfter(lastChildPosition, convertFocusDirectionToLayoutDirection); if (!(focusableViewAfter3 == null || focusableViewAfter3 == findContainingItemView)) { return focusableViewAfter3; } } } boolean z3 = (this.mReverseLayout ^ true) == (convertFocusDirectionToLayoutDirection == -1); if (!z2) { View findViewByPosition = findViewByPosition(z3 ? span.findFirstPartiallyVisibleItemPosition() : span.findLastPartiallyVisibleItemPosition()); if (!(findViewByPosition == null || findViewByPosition == findContainingItemView)) { return findViewByPosition; } } if (preferLastSpan(convertFocusDirectionToLayoutDirection)) { for (int i4 = this.mSpanCount - 1; i4 >= 0; i4--) { if (i4 != span.mIndex) { View findViewByPosition2 = findViewByPosition(z3 ? this.mSpans[i4].findFirstPartiallyVisibleItemPosition() : this.mSpans[i4].findLastPartiallyVisibleItemPosition()); if (!(findViewByPosition2 == null || findViewByPosition2 == findContainingItemView)) { return findViewByPosition2; } } } } else { for (int i5 = 0; i5 < this.mSpanCount; i5++) { View findViewByPosition3 = findViewByPosition(z3 ? this.mSpans[i5].findFirstPartiallyVisibleItemPosition() : this.mSpans[i5].findLastPartiallyVisibleItemPosition()); if (!(findViewByPosition3 == null || findViewByPosition3 == findContainingItemView)) { return findViewByPosition3; } } } return null; } @Override // androidx.recyclerview.widget.RecyclerView.LayoutManager public void onInitializeAccessibilityEvent(AccessibilityEvent accessibilityEvent) { super.onInitializeAccessibilityEvent(accessibilityEvent); if (getChildCount() > 0) { View findFirstVisibleItemClosestToStart = findFirstVisibleItemClosestToStart(false); View findFirstVisibleItemClosestToEnd = findFirstVisibleItemClosestToEnd(false); if (findFirstVisibleItemClosestToStart != null && findFirstVisibleItemClosestToEnd != null) { int position = getPosition(findFirstVisibleItemClosestToStart); int position2 = getPosition(findFirstVisibleItemClosestToEnd); if (position < position2) { accessibilityEvent.setFromIndex(position); accessibilityEvent.setToIndex(position2); return; } accessibilityEvent.setFromIndex(position2); accessibilityEvent.setToIndex(position); } } } @Override // androidx.recyclerview.widget.RecyclerView.LayoutManager public void onInitializeAccessibilityNodeInfoForItem(RecyclerView.Recycler recycler, RecyclerView.State state, View view, AccessibilityNodeInfoCompat accessibilityNodeInfoCompat) { ViewGroup.LayoutParams layoutParams = view.getLayoutParams(); if (!(layoutParams instanceof LayoutParams)) { super.onInitializeAccessibilityNodeInfoForItem(view, accessibilityNodeInfoCompat); return; } LayoutParams layoutParams2 = (LayoutParams) layoutParams; if (this.mOrientation == 0) { accessibilityNodeInfoCompat.setCollectionItemInfo(AccessibilityNodeInfoCompat.CollectionItemInfoCompat.obtain(layoutParams2.getSpanIndex(), layoutParams2.mFullSpan ? this.mSpanCount : 1, -1, -1, false, false)); } else { accessibilityNodeInfoCompat.setCollectionItemInfo(AccessibilityNodeInfoCompat.CollectionItemInfoCompat.obtain(-1, -1, layoutParams2.getSpanIndex(), layoutParams2.mFullSpan ? this.mSpanCount : 1, false, false)); } } @Override // androidx.recyclerview.widget.RecyclerView.LayoutManager public void onItemsAdded(RecyclerView recyclerView, int i, int i2) { handleUpdate(i, i2, 1); } @Override // androidx.recyclerview.widget.RecyclerView.LayoutManager public void onItemsChanged(RecyclerView recyclerView) { this.mLazySpanLookup.clear(); requestLayout(); } @Override // androidx.recyclerview.widget.RecyclerView.LayoutManager public void onItemsMoved(RecyclerView recyclerView, int i, int i2, int i3) { handleUpdate(i, i2, 8); } @Override // androidx.recyclerview.widget.RecyclerView.LayoutManager public void onItemsRemoved(RecyclerView recyclerView, int i, int i2) { handleUpdate(i, i2, 2); } @Override // androidx.recyclerview.widget.RecyclerView.LayoutManager public void onItemsUpdated(RecyclerView recyclerView, int i, int i2, Object obj) { handleUpdate(i, i2, 4); } @Override // androidx.recyclerview.widget.RecyclerView.LayoutManager public void onLayoutChildren(RecyclerView.Recycler recycler, RecyclerView.State state) { onLayoutChildren(recycler, state, true); } @Override // androidx.recyclerview.widget.RecyclerView.LayoutManager public void onLayoutCompleted(RecyclerView.State state) { super.onLayoutCompleted(state); this.mPendingScrollPosition = -1; this.mPendingScrollPositionOffset = Integer.MIN_VALUE; this.mPendingSavedState = null; this.mAnchorInfo.reset(); } @Override // androidx.recyclerview.widget.RecyclerView.LayoutManager public void onRestoreInstanceState(Parcelable parcelable) { if (parcelable instanceof SavedState) { this.mPendingSavedState = (SavedState) parcelable; requestLayout(); } } @Override // androidx.recyclerview.widget.RecyclerView.LayoutManager public Parcelable onSaveInstanceState() { int i; int i2; int[] iArr; if (this.mPendingSavedState != null) { return new SavedState(this.mPendingSavedState); } SavedState savedState = new SavedState(); savedState.mReverseLayout = this.mReverseLayout; savedState.mAnchorLayoutFromEnd = this.mLastLayoutFromEnd; savedState.mLastLayoutRTL = this.mLastLayoutRTL; LazySpanLookup lazySpanLookup = this.mLazySpanLookup; if (lazySpanLookup == null || (iArr = lazySpanLookup.mData) == null) { savedState.mSpanLookupSize = 0; } else { savedState.mSpanLookup = iArr; savedState.mSpanLookupSize = iArr.length; savedState.mFullSpanItems = lazySpanLookup.mFullSpanItems; } if (getChildCount() > 0) { savedState.mAnchorPosition = this.mLastLayoutFromEnd ? getLastChildPosition() : getFirstChildPosition(); savedState.mVisibleAnchorPosition = findFirstVisibleItemPositionInt(); int i3 = this.mSpanCount; savedState.mSpanOffsetsSize = i3; savedState.mSpanOffsets = new int[i3]; for (int i4 = 0; i4 < this.mSpanCount; i4++) { if (this.mLastLayoutFromEnd) { i = this.mSpans[i4].getEndLine(Integer.MIN_VALUE); if (i != Integer.MIN_VALUE) { i2 = this.mPrimaryOrientation.getEndAfterPadding(); } else { savedState.mSpanOffsets[i4] = i; } } else { i = this.mSpans[i4].getStartLine(Integer.MIN_VALUE); if (i != Integer.MIN_VALUE) { i2 = this.mPrimaryOrientation.getStartAfterPadding(); } else { savedState.mSpanOffsets[i4] = i; } } i -= i2; savedState.mSpanOffsets[i4] = i; } } else { savedState.mAnchorPosition = -1; savedState.mVisibleAnchorPosition = -1; savedState.mSpanOffsetsSize = 0; } return savedState; } @Override // androidx.recyclerview.widget.RecyclerView.LayoutManager public void onScrollStateChanged(int i) { if (i == 0) { checkForGaps(); } } public void prepareLayoutStateForDelta(int i, RecyclerView.State state) { int i2; int i3; if (i > 0) { i3 = getLastChildPosition(); i2 = 1; } else { i3 = getFirstChildPosition(); i2 = -1; } this.mLayoutState.mRecycle = true; updateLayoutState(i3, state); setLayoutStateDirection(i2); LayoutState layoutState = this.mLayoutState; layoutState.mCurrentPosition = i3 + layoutState.mItemDirection; layoutState.mAvailable = Math.abs(i); } public int scrollBy(int i, RecyclerView.Recycler recycler, RecyclerView.State state) { if (getChildCount() == 0 || i == 0) { return 0; } prepareLayoutStateForDelta(i, state); int fill = fill(recycler, this.mLayoutState, state); if (this.mLayoutState.mAvailable >= fill) { i = i < 0 ? -fill : fill; } this.mPrimaryOrientation.offsetChildren(-i); this.mLastLayoutFromEnd = this.mShouldReverseLayout; LayoutState layoutState = this.mLayoutState; layoutState.mAvailable = 0; recycle(recycler, layoutState); return i; } @Override // androidx.recyclerview.widget.RecyclerView.LayoutManager public int scrollHorizontallyBy(int i, RecyclerView.Recycler recycler, RecyclerView.State state) { return scrollBy(i, recycler, state); } @Override // androidx.recyclerview.widget.RecyclerView.LayoutManager public void scrollToPosition(int i) { SavedState savedState = this.mPendingSavedState; if (!(savedState == null || savedState.mAnchorPosition == i)) { savedState.invalidateAnchorPositionInfo(); } this.mPendingScrollPosition = i; this.mPendingScrollPositionOffset = Integer.MIN_VALUE; requestLayout(); } public void scrollToPositionWithOffset(int i, int i2) { SavedState savedState = this.mPendingSavedState; if (savedState != null) { savedState.invalidateAnchorPositionInfo(); } this.mPendingScrollPosition = i; this.mPendingScrollPositionOffset = i2; requestLayout(); } @Override // androidx.recyclerview.widget.RecyclerView.LayoutManager public int scrollVerticallyBy(int i, RecyclerView.Recycler recycler, RecyclerView.State state) { return scrollBy(i, recycler, state); } public void setGapStrategy(int i) { assertNotInLayoutOrScroll(null); if (i != this.mGapStrategy) { if (i == 0 || i == 2) { this.mGapStrategy = i; requestLayout(); return; } throw new IllegalArgumentException("invalid gap strategy. Must be GAP_HANDLING_NONE or GAP_HANDLING_MOVE_ITEMS_BETWEEN_SPANS"); } } @Override // androidx.recyclerview.widget.RecyclerView.LayoutManager public void setMeasuredDimension(Rect rect, int i, int i2) { int i3; int i4; int paddingRight = getPaddingRight() + getPaddingLeft(); int paddingBottom = getPaddingBottom() + getPaddingTop(); if (this.mOrientation == 1) { i4 = RecyclerView.LayoutManager.chooseSize(i2, rect.height() + paddingBottom, getMinimumHeight()); i3 = RecyclerView.LayoutManager.chooseSize(i, (this.mSizePerSpan * this.mSpanCount) + paddingRight, getMinimumWidth()); } else { i3 = RecyclerView.LayoutManager.chooseSize(i, rect.width() + paddingRight, getMinimumWidth()); i4 = RecyclerView.LayoutManager.chooseSize(i2, (this.mSizePerSpan * this.mSpanCount) + paddingBottom, getMinimumHeight()); } setMeasuredDimension(i3, i4); } public void setOrientation(int i) { if (i == 0 || i == 1) { assertNotInLayoutOrScroll(null); if (i != this.mOrientation) { this.mOrientation = i; OrientationHelper orientationHelper = this.mPrimaryOrientation; this.mPrimaryOrientation = this.mSecondaryOrientation; this.mSecondaryOrientation = orientationHelper; requestLayout(); return; } return; } throw new IllegalArgumentException("invalid orientation."); } public void setReverseLayout(boolean z2) { assertNotInLayoutOrScroll(null); SavedState savedState = this.mPendingSavedState; if (!(savedState == null || savedState.mReverseLayout == z2)) { savedState.mReverseLayout = z2; } this.mReverseLayout = z2; requestLayout(); } public void setSpanCount(int i) { assertNotInLayoutOrScroll(null); if (i != this.mSpanCount) { invalidateSpanAssignments(); this.mSpanCount = i; this.mRemainingSpans = new BitSet(this.mSpanCount); this.mSpans = new Span[this.mSpanCount]; for (int i2 = 0; i2 < this.mSpanCount; i2++) { this.mSpans[i2] = new Span(i2); } requestLayout(); } } @Override // androidx.recyclerview.widget.RecyclerView.LayoutManager public void smoothScrollToPosition(RecyclerView recyclerView, RecyclerView.State state, int i) { LinearSmoothScroller linearSmoothScroller = new LinearSmoothScroller(recyclerView.getContext()); linearSmoothScroller.setTargetPosition(i); startSmoothScroll(linearSmoothScroller); } @Override // androidx.recyclerview.widget.RecyclerView.LayoutManager public boolean supportsPredictiveItemAnimations() { return this.mPendingSavedState == null; } public boolean updateAnchorFromPendingData(RecyclerView.State state, AnchorInfo anchorInfo) { int i; boolean z2 = false; if (!state.isPreLayout() && (i = this.mPendingScrollPosition) != -1) { if (i < 0 || i >= state.getItemCount()) { this.mPendingScrollPosition = -1; this.mPendingScrollPositionOffset = Integer.MIN_VALUE; } else { SavedState savedState = this.mPendingSavedState; if (savedState == null || savedState.mAnchorPosition == -1 || savedState.mSpanOffsetsSize < 1) { View findViewByPosition = findViewByPosition(this.mPendingScrollPosition); if (findViewByPosition != null) { anchorInfo.mPosition = this.mShouldReverseLayout ? getLastChildPosition() : getFirstChildPosition(); if (this.mPendingScrollPositionOffset != Integer.MIN_VALUE) { if (anchorInfo.mLayoutFromEnd) { anchorInfo.mOffset = (this.mPrimaryOrientation.getEndAfterPadding() - this.mPendingScrollPositionOffset) - this.mPrimaryOrientation.getDecoratedEnd(findViewByPosition); } else { anchorInfo.mOffset = (this.mPrimaryOrientation.getStartAfterPadding() + this.mPendingScrollPositionOffset) - this.mPrimaryOrientation.getDecoratedStart(findViewByPosition); } return true; } else if (this.mPrimaryOrientation.getDecoratedMeasurement(findViewByPosition) > this.mPrimaryOrientation.getTotalSpace()) { anchorInfo.mOffset = anchorInfo.mLayoutFromEnd ? this.mPrimaryOrientation.getEndAfterPadding() : this.mPrimaryOrientation.getStartAfterPadding(); return true; } else { int decoratedStart = this.mPrimaryOrientation.getDecoratedStart(findViewByPosition) - this.mPrimaryOrientation.getStartAfterPadding(); if (decoratedStart < 0) { anchorInfo.mOffset = -decoratedStart; return true; } int endAfterPadding = this.mPrimaryOrientation.getEndAfterPadding() - this.mPrimaryOrientation.getDecoratedEnd(findViewByPosition); if (endAfterPadding < 0) { anchorInfo.mOffset = endAfterPadding; return true; } anchorInfo.mOffset = Integer.MIN_VALUE; } } else { int i2 = this.mPendingScrollPosition; anchorInfo.mPosition = i2; int i3 = this.mPendingScrollPositionOffset; if (i3 == Integer.MIN_VALUE) { if (calculateScrollDirectionForPosition(i2) == 1) { z2 = true; } anchorInfo.mLayoutFromEnd = z2; anchorInfo.assignCoordinateFromPadding(); } else { anchorInfo.assignCoordinateFromPadding(i3); } anchorInfo.mInvalidateOffsets = true; } } else { anchorInfo.mOffset = Integer.MIN_VALUE; anchorInfo.mPosition = this.mPendingScrollPosition; } return true; } } return false; } public void updateAnchorInfoForLayout(RecyclerView.State state, AnchorInfo anchorInfo) { if (!updateAnchorFromPendingData(state, anchorInfo) && !updateAnchorFromChildren(state, anchorInfo)) { anchorInfo.assignCoordinateFromPadding(); anchorInfo.mPosition = 0; } } public void updateMeasureSpecs(int i) { this.mSizePerSpan = i / this.mSpanCount; this.mFullSizeSpec = View.MeasureSpec.makeMeasureSpec(i, this.mSecondaryOrientation.getMode()); } }