jimu-decompiled/sources/androidx/recyclerview/widget/GridLayoutManager.java
2025-05-13 19:24:51 +02:00

704 lines
24 KiB
Java

package androidx.recyclerview.widget;
import android.content.Context;
import android.graphics.Rect;
import android.util.AttributeSet;
import android.util.Log;
import android.util.SparseIntArray;
import android.view.View;
import android.view.ViewGroup;
import androidx.core.view.accessibility.AccessibilityNodeInfoCompat;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
/* loaded from: classes.dex */
public class GridLayoutManager extends LinearLayoutManager {
boolean H;
int I;
int[] J;
View[] K;
final SparseIntArray L;
final SparseIntArray M;
SpanSizeLookup N;
final Rect O;
public static final class DefaultSpanSizeLookup extends SpanSizeLookup {
@Override // androidx.recyclerview.widget.GridLayoutManager.SpanSizeLookup
public int getSpanIndex(int i, int i2) {
return i % i2;
}
@Override // androidx.recyclerview.widget.GridLayoutManager.SpanSizeLookup
public int getSpanSize(int i) {
return 1;
}
}
public static abstract class SpanSizeLookup {
final SparseIntArray mSpanIndexCache = new SparseIntArray();
private boolean mCacheSpanIndices = false;
int findReferenceIndexFromCache(int i) {
int size = this.mSpanIndexCache.size() - 1;
int i2 = 0;
while (i2 <= size) {
int i3 = (i2 + size) >>> 1;
if (this.mSpanIndexCache.keyAt(i3) < i) {
i2 = i3 + 1;
} else {
size = i3 - 1;
}
}
int i4 = i2 - 1;
if (i4 < 0 || i4 >= this.mSpanIndexCache.size()) {
return -1;
}
return this.mSpanIndexCache.keyAt(i4);
}
int getCachedSpanIndex(int i, int i2) {
if (!this.mCacheSpanIndices) {
return getSpanIndex(i, i2);
}
int i3 = this.mSpanIndexCache.get(i, -1);
if (i3 != -1) {
return i3;
}
int spanIndex = getSpanIndex(i, i2);
this.mSpanIndexCache.put(i, spanIndex);
return spanIndex;
}
public int getSpanGroupIndex(int i, int i2) {
int spanSize = getSpanSize(i);
int i3 = 0;
int i4 = 0;
for (int i5 = 0; i5 < i; i5++) {
int spanSize2 = getSpanSize(i5);
i3 += spanSize2;
if (i3 == i2) {
i4++;
i3 = 0;
} else if (i3 > i2) {
i4++;
i3 = spanSize2;
}
}
return i3 + spanSize > i2 ? i4 + 1 : i4;
}
/* JADX WARN: Removed duplicated region for block: B:14:0x002a */
/* JADX WARN: Removed duplicated region for block: B:19:0x0039 */
/* JADX WARN: Unsupported multi-entry loop pattern (BACK_EDGE: B:16:0x0031 -> B:12:0x0036). Please report as a decompilation issue!!! */
/* JADX WARN: Unsupported multi-entry loop pattern (BACK_EDGE: B:17:0x0033 -> B:12:0x0036). Please report as a decompilation issue!!! */
/* JADX WARN: Unsupported multi-entry loop pattern (BACK_EDGE: B:18:0x0035 -> B:12:0x0036). Please report as a decompilation issue!!! */
/*
Code decompiled incorrectly, please refer to instructions dump.
To view partially-correct code enable 'Show inconsistent code' option in preferences
*/
public int getSpanIndex(int r6, int r7) {
/*
r5 = this;
int r0 = r5.getSpanSize(r6)
r1 = 0
if (r0 != r7) goto L8
return r1
L8:
boolean r2 = r5.mCacheSpanIndices
if (r2 == 0) goto L26
android.util.SparseIntArray r2 = r5.mSpanIndexCache
int r2 = r2.size()
if (r2 <= 0) goto L26
int r2 = r5.findReferenceIndexFromCache(r6)
if (r2 < 0) goto L26
android.util.SparseIntArray r3 = r5.mSpanIndexCache
int r3 = r3.get(r2)
int r4 = r5.getSpanSize(r2)
int r3 = r3 + r4
goto L36
L26:
r2 = 0
r3 = 0
L28:
if (r2 >= r6) goto L39
int r4 = r5.getSpanSize(r2)
int r3 = r3 + r4
if (r3 != r7) goto L33
r3 = 0
goto L36
L33:
if (r3 <= r7) goto L36
r3 = r4
L36:
int r2 = r2 + 1
goto L28
L39:
int r0 = r0 + r3
if (r0 > r7) goto L3d
return r3
L3d:
return r1
*/
throw new UnsupportedOperationException("Method not decompiled: androidx.recyclerview.widget.GridLayoutManager.SpanSizeLookup.getSpanIndex(int, int):int");
}
public abstract int getSpanSize(int i);
public void invalidateSpanIndexCache() {
this.mSpanIndexCache.clear();
}
public boolean isSpanIndexCacheEnabled() {
return this.mCacheSpanIndices;
}
public void setSpanIndexCacheEnabled(boolean z) {
this.mCacheSpanIndices = z;
}
}
public GridLayoutManager(Context context, AttributeSet attributeSet, int i, int i2) {
super(context, attributeSet, i, i2);
this.H = false;
this.I = -1;
this.L = new SparseIntArray();
this.M = new SparseIntArray();
this.N = new DefaultSpanSizeLookup();
this.O = new Rect();
l(RecyclerView.LayoutManager.a(context, attributeSet, i, i2).spanCount);
}
private void P() {
int e = e();
for (int i = 0; i < e; i++) {
LayoutParams layoutParams = (LayoutParams) d(i).getLayoutParams();
int a = layoutParams.a();
this.L.put(a, layoutParams.f());
this.M.put(a, layoutParams.e());
}
}
private void Q() {
this.L.clear();
this.M.clear();
}
private void R() {
View[] viewArr = this.K;
if (viewArr == null || viewArr.length != this.I) {
this.K = new View[this.I];
}
}
private void S() {
int h;
int q;
if (K() == 1) {
h = r() - p();
q = o();
} else {
h = h() - n();
q = q();
}
m(h - q);
}
private void m(int i) {
this.J = a(this.J, this.I, i);
}
@Override // androidx.recyclerview.widget.LinearLayoutManager, androidx.recyclerview.widget.RecyclerView.LayoutManager
public boolean D() {
return this.D == null && !this.H;
}
public int N() {
return this.I;
}
public SpanSizeLookup O() {
return this.N;
}
@Override // androidx.recyclerview.widget.RecyclerView.LayoutManager
public int a(RecyclerView.Recycler recycler, RecyclerView.State state) {
if (this.s == 1) {
return this.I;
}
if (state.a() < 1) {
return 0;
}
return a(recycler, state, state.a() - 1) + 1;
}
@Override // androidx.recyclerview.widget.LinearLayoutManager
public void b(boolean z) {
if (z) {
throw new UnsupportedOperationException("GridLayoutManager does not support stack from end. Consider using reverse layout");
}
super.b(false);
}
@Override // androidx.recyclerview.widget.LinearLayoutManager, androidx.recyclerview.widget.RecyclerView.LayoutManager
public RecyclerView.LayoutParams c() {
return this.s == 0 ? new LayoutParams(-2, -1) : new LayoutParams(-1, -2);
}
@Override // androidx.recyclerview.widget.RecyclerView.LayoutManager
public void d(RecyclerView recyclerView) {
this.N.invalidateSpanIndexCache();
}
@Override // androidx.recyclerview.widget.LinearLayoutManager, androidx.recyclerview.widget.RecyclerView.LayoutManager
public void e(RecyclerView.Recycler recycler, RecyclerView.State state) {
if (state.d()) {
P();
}
super.e(recycler, state);
Q();
}
@Override // androidx.recyclerview.widget.LinearLayoutManager, androidx.recyclerview.widget.RecyclerView.LayoutManager
public void g(RecyclerView.State state) {
super.g(state);
this.H = false;
}
public void l(int i) {
if (i == this.I) {
return;
}
this.H = true;
if (i >= 1) {
this.I = i;
this.N.invalidateSpanIndexCache();
z();
} else {
throw new IllegalArgumentException("Span count should be at least 1. Provided " + i);
}
}
public static class LayoutParams extends RecyclerView.LayoutParams {
int e;
int f;
public LayoutParams(Context context, AttributeSet attributeSet) {
super(context, attributeSet);
this.e = -1;
this.f = 0;
}
public int e() {
return this.e;
}
public int f() {
return this.f;
}
public LayoutParams(int i, int i2) {
super(i, i2);
this.e = -1;
this.f = 0;
}
public LayoutParams(ViewGroup.MarginLayoutParams marginLayoutParams) {
super(marginLayoutParams);
this.e = -1;
this.f = 0;
}
public LayoutParams(ViewGroup.LayoutParams layoutParams) {
super(layoutParams);
this.e = -1;
this.f = 0;
}
}
@Override // androidx.recyclerview.widget.RecyclerView.LayoutManager
public int b(RecyclerView.Recycler recycler, RecyclerView.State state) {
if (this.s == 0) {
return this.I;
}
if (state.a() < 1) {
return 0;
}
return a(recycler, state, state.a() - 1) + 1;
}
int g(int i, int i2) {
if (this.s == 1 && L()) {
int[] iArr = this.J;
int i3 = this.I;
return iArr[i3 - i] - iArr[(i3 - i) - i2];
}
int[] iArr2 = this.J;
return iArr2[i2 + i] - iArr2[i];
}
private int c(RecyclerView.Recycler recycler, RecyclerView.State state, int i) {
if (!state.d()) {
return this.N.getSpanSize(i);
}
int i2 = this.L.get(i, -1);
if (i2 != -1) {
return i2;
}
int a = recycler.a(i);
if (a == -1) {
Log.w("GridLayoutManager", "Cannot find span size for pre layout position. It is not cached, not in the adapter. Pos:" + i);
return 1;
}
return this.N.getSpanSize(a);
}
@Override // androidx.recyclerview.widget.RecyclerView.LayoutManager
public void a(RecyclerView.Recycler recycler, RecyclerView.State state, View view, AccessibilityNodeInfoCompat accessibilityNodeInfoCompat) {
ViewGroup.LayoutParams layoutParams = view.getLayoutParams();
if (!(layoutParams instanceof LayoutParams)) {
super.a(view, accessibilityNodeInfoCompat);
return;
}
LayoutParams layoutParams2 = (LayoutParams) layoutParams;
int a = a(recycler, state, layoutParams2.a());
if (this.s == 0) {
accessibilityNodeInfoCompat.b(AccessibilityNodeInfoCompat.CollectionItemInfoCompat.a(layoutParams2.e(), layoutParams2.f(), a, 1, this.I > 1 && layoutParams2.f() == this.I, false));
} else {
accessibilityNodeInfoCompat.b(AccessibilityNodeInfoCompat.CollectionItemInfoCompat.a(a, 1, layoutParams2.e(), layoutParams2.f(), this.I > 1 && layoutParams2.f() == this.I, false));
}
}
@Override // androidx.recyclerview.widget.RecyclerView.LayoutManager
public void b(RecyclerView recyclerView, int i, int i2) {
this.N.invalidateSpanIndexCache();
}
@Override // androidx.recyclerview.widget.LinearLayoutManager, androidx.recyclerview.widget.RecyclerView.LayoutManager
public int b(int i, RecyclerView.Recycler recycler, RecyclerView.State state) {
S();
R();
return super.b(i, recycler, state);
}
public GridLayoutManager(Context context, int i) {
super(context);
this.H = false;
this.I = -1;
this.L = new SparseIntArray();
this.M = new SparseIntArray();
this.N = new DefaultSpanSizeLookup();
this.O = new Rect();
l(i);
}
private void b(RecyclerView.Recycler recycler, RecyclerView.State state, LinearLayoutManager.AnchorInfo anchorInfo, int i) {
boolean z = i == 1;
int b = b(recycler, state, anchorInfo.b);
if (z) {
while (b > 0) {
int i2 = anchorInfo.b;
if (i2 <= 0) {
return;
}
anchorInfo.b = i2 - 1;
b = b(recycler, state, anchorInfo.b);
}
return;
}
int a = state.a() - 1;
int i3 = anchorInfo.b;
while (i3 < a) {
int i4 = i3 + 1;
int b2 = b(recycler, state, i4);
if (b2 <= b) {
break;
}
i3 = i4;
b = b2;
}
anchorInfo.b = i3;
}
@Override // androidx.recyclerview.widget.RecyclerView.LayoutManager
public void a(RecyclerView recyclerView, int i, int i2) {
this.N.invalidateSpanIndexCache();
}
public GridLayoutManager(Context context, int i, int i2, boolean z) {
super(context, i2, z);
this.H = false;
this.I = -1;
this.L = new SparseIntArray();
this.M = new SparseIntArray();
this.N = new DefaultSpanSizeLookup();
this.O = new Rect();
l(i);
}
@Override // androidx.recyclerview.widget.RecyclerView.LayoutManager
public void a(RecyclerView recyclerView, int i, int i2, Object obj) {
this.N.invalidateSpanIndexCache();
}
private int b(RecyclerView.Recycler recycler, RecyclerView.State state, int i) {
if (!state.d()) {
return this.N.getCachedSpanIndex(i, this.I);
}
int i2 = this.M.get(i, -1);
if (i2 != -1) {
return i2;
}
int a = recycler.a(i);
if (a == -1) {
Log.w("GridLayoutManager", "Cannot find span size for pre layout position. It is not cached, not in the adapter. Pos:" + i);
return 0;
}
return this.N.getCachedSpanIndex(a, this.I);
}
@Override // androidx.recyclerview.widget.RecyclerView.LayoutManager
public void a(RecyclerView recyclerView, int i, int i2, int i3) {
this.N.invalidateSpanIndexCache();
}
@Override // androidx.recyclerview.widget.RecyclerView.LayoutManager
public RecyclerView.LayoutParams a(Context context, AttributeSet attributeSet) {
return new LayoutParams(context, attributeSet);
}
@Override // androidx.recyclerview.widget.RecyclerView.LayoutManager
public RecyclerView.LayoutParams a(ViewGroup.LayoutParams layoutParams) {
if (layoutParams instanceof ViewGroup.MarginLayoutParams) {
return new LayoutParams((ViewGroup.MarginLayoutParams) layoutParams);
}
return new LayoutParams(layoutParams);
}
@Override // androidx.recyclerview.widget.RecyclerView.LayoutManager
public boolean a(RecyclerView.LayoutParams layoutParams) {
return layoutParams instanceof LayoutParams;
}
public void a(SpanSizeLookup spanSizeLookup) {
this.N = spanSizeLookup;
}
@Override // androidx.recyclerview.widget.RecyclerView.LayoutManager
public void a(Rect rect, int i, int i2) {
int a;
int a2;
if (this.J == null) {
super.a(rect, i, i2);
}
int o = o() + p();
int q = q() + n();
if (this.s == 1) {
a2 = RecyclerView.LayoutManager.a(i2, rect.height() + q, l());
int[] iArr = this.J;
a = RecyclerView.LayoutManager.a(i, iArr[iArr.length - 1] + o, m());
} else {
a = RecyclerView.LayoutManager.a(i, rect.width() + o, m());
int[] iArr2 = this.J;
a2 = RecyclerView.LayoutManager.a(i2, iArr2[iArr2.length - 1] + q, l());
}
c(a, a2);
}
static int[] a(int[] iArr, int i, int i2) {
int i3;
if (iArr == null || iArr.length != i + 1 || iArr[iArr.length - 1] != i2) {
iArr = new int[i + 1];
}
int i4 = 0;
iArr[0] = 0;
int i5 = i2 / i;
int i6 = i2 % i;
int i7 = 0;
for (int i8 = 1; i8 <= i; i8++) {
i4 += i6;
if (i4 <= 0 || i - i4 >= i6) {
i3 = i5;
} else {
i3 = i5 + 1;
i4 -= i;
}
i7 += i3;
iArr[i8] = i7;
}
return iArr;
}
@Override // androidx.recyclerview.widget.LinearLayoutManager
void a(RecyclerView.Recycler recycler, RecyclerView.State state, LinearLayoutManager.AnchorInfo anchorInfo, int i) {
super.a(recycler, state, anchorInfo, i);
S();
if (state.a() > 0 && !state.d()) {
b(recycler, state, anchorInfo, i);
}
R();
}
@Override // androidx.recyclerview.widget.LinearLayoutManager, androidx.recyclerview.widget.RecyclerView.LayoutManager
public int a(int i, RecyclerView.Recycler recycler, RecyclerView.State state) {
S();
R();
return super.a(i, recycler, state);
}
@Override // androidx.recyclerview.widget.LinearLayoutManager
View a(RecyclerView.Recycler recycler, RecyclerView.State state, int i, int i2, int i3) {
F();
int f = this.u.f();
int b = this.u.b();
int i4 = i2 > i ? 1 : -1;
View view = null;
View view2 = null;
while (i != i2) {
View d = d(i);
int l = l(d);
if (l >= 0 && l < i3 && b(recycler, state, l) == 0) {
if (((RecyclerView.LayoutParams) d.getLayoutParams()).c()) {
if (view2 == null) {
view2 = d;
}
} else {
if (this.u.d(d) < b && this.u.a(d) >= f) {
return d;
}
if (view == null) {
view = d;
}
}
}
i += i4;
}
return view != null ? view : view2;
}
private int a(RecyclerView.Recycler recycler, RecyclerView.State state, int i) {
if (!state.d()) {
return this.N.getSpanGroupIndex(i, this.I);
}
int a = recycler.a(i);
if (a == -1) {
Log.w("GridLayoutManager", "Cannot find span size for pre layout position. " + i);
return 0;
}
return this.N.getSpanGroupIndex(a, this.I);
}
@Override // androidx.recyclerview.widget.LinearLayoutManager
void a(RecyclerView.State state, LinearLayoutManager.LayoutState layoutState, RecyclerView.LayoutManager.LayoutPrefetchRegistry layoutPrefetchRegistry) {
int i = this.I;
for (int i2 = 0; i2 < this.I && layoutState.a(state) && i > 0; i2++) {
int i3 = layoutState.d;
layoutPrefetchRegistry.a(i3, Math.max(0, layoutState.g));
i -= this.N.getSpanSize(i3);
layoutState.d += layoutState.e;
}
}
/* JADX WARN: Code restructure failed: missing block: B:30:0x00a1, code lost:
r22.b = true;
*/
/* JADX WARN: Code restructure failed: missing block: B:31:0x00a3, code lost:
return;
*/
@Override // androidx.recyclerview.widget.LinearLayoutManager
/*
Code decompiled incorrectly, please refer to instructions dump.
To view partially-correct code enable 'Show inconsistent code' option in preferences
*/
void a(androidx.recyclerview.widget.RecyclerView.Recycler r19, androidx.recyclerview.widget.RecyclerView.State r20, androidx.recyclerview.widget.LinearLayoutManager.LayoutState r21, androidx.recyclerview.widget.LinearLayoutManager.LayoutChunkResult r22) {
/*
Method dump skipped, instructions count: 574
To view this dump change 'Code comments level' option to 'DEBUG'
*/
throw new UnsupportedOperationException("Method not decompiled: androidx.recyclerview.widget.GridLayoutManager.a(androidx.recyclerview.widget.RecyclerView$Recycler, androidx.recyclerview.widget.RecyclerView$State, androidx.recyclerview.widget.LinearLayoutManager$LayoutState, androidx.recyclerview.widget.LinearLayoutManager$LayoutChunkResult):void");
}
private void a(View view, int i, boolean z) {
int i2;
int i3;
LayoutParams layoutParams = (LayoutParams) view.getLayoutParams();
Rect rect = layoutParams.b;
int i4 = rect.top + rect.bottom + ((ViewGroup.MarginLayoutParams) layoutParams).topMargin + ((ViewGroup.MarginLayoutParams) layoutParams).bottomMargin;
int i5 = rect.left + rect.right + ((ViewGroup.MarginLayoutParams) layoutParams).leftMargin + ((ViewGroup.MarginLayoutParams) layoutParams).rightMargin;
int g = g(layoutParams.e, layoutParams.f);
if (this.s == 1) {
i3 = RecyclerView.LayoutManager.a(g, i, i5, ((ViewGroup.MarginLayoutParams) layoutParams).width, false);
i2 = RecyclerView.LayoutManager.a(this.u.g(), i(), i4, ((ViewGroup.MarginLayoutParams) layoutParams).height, true);
} else {
int a = RecyclerView.LayoutManager.a(g, i, i4, ((ViewGroup.MarginLayoutParams) layoutParams).height, false);
int a2 = RecyclerView.LayoutManager.a(this.u.g(), s(), i5, ((ViewGroup.MarginLayoutParams) layoutParams).width, true);
i2 = a;
i3 = a2;
}
a(view, i3, i2, z);
}
private void a(float f, int i) {
m(Math.max(Math.round(f * this.I), i));
}
private void a(View view, int i, int i2, boolean z) {
boolean a;
RecyclerView.LayoutParams layoutParams = (RecyclerView.LayoutParams) view.getLayoutParams();
if (z) {
a = b(view, i, i2, layoutParams);
} else {
a = a(view, i, i2, layoutParams);
}
if (a) {
view.measure(i, i2);
}
}
private void a(RecyclerView.Recycler recycler, RecyclerView.State state, int i, int i2, boolean z) {
int i3;
int i4;
int i5 = 0;
int i6 = -1;
if (z) {
i6 = i;
i3 = 0;
i4 = 1;
} else {
i3 = i - 1;
i4 = -1;
}
while (i3 != i6) {
View view = this.K[i3];
LayoutParams layoutParams = (LayoutParams) view.getLayoutParams();
layoutParams.f = c(recycler, state, l(view));
layoutParams.e = i5;
i5 += layoutParams.f;
i3 += i4;
}
}
/* JADX WARN: Code restructure failed: missing block: B:69:0x00d7, code lost:
if (r13 == (r2 > r8)) goto L54;
*/
/* JADX WARN: Code restructure failed: missing block: B:83:0x00f7, code lost:
if (r13 == (r2 > r10)) goto L50;
*/
/* JADX WARN: Removed duplicated region for block: B:53:0x0105 */
@Override // androidx.recyclerview.widget.LinearLayoutManager, androidx.recyclerview.widget.RecyclerView.LayoutManager
/*
Code decompiled incorrectly, please refer to instructions dump.
To view partially-correct code enable 'Show inconsistent code' option in preferences
*/
public android.view.View a(android.view.View r24, int r25, androidx.recyclerview.widget.RecyclerView.Recycler r26, androidx.recyclerview.widget.RecyclerView.State r27) {
/*
Method dump skipped, instructions count: 335
To view this dump change 'Code comments level' option to 'DEBUG'
*/
throw new UnsupportedOperationException("Method not decompiled: androidx.recyclerview.widget.GridLayoutManager.a(android.view.View, int, androidx.recyclerview.widget.RecyclerView$Recycler, androidx.recyclerview.widget.RecyclerView$State):android.view.View");
}
}