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.recyclerview.widget.LinearLayoutManager; import androidx.recyclerview.widget.RecyclerView; import z.a0; /* loaded from: classes.dex */ public class GridLayoutManager extends LinearLayoutManager { boolean I; int J; int[] K; View[] L; final SparseIntArray M; final SparseIntArray N; c O; final Rect P; private boolean Q; public static final class a extends c { @Override // androidx.recyclerview.widget.GridLayoutManager.c public int e(int i10, int i11) { return i10 % i11; } @Override // androidx.recyclerview.widget.GridLayoutManager.c public int f(int i10) { return 1; } } public static abstract class c { /* renamed from: a, reason: collision with root package name */ final SparseIntArray f2175a = new SparseIntArray(); /* renamed from: b, reason: collision with root package name */ final SparseIntArray f2176b = new SparseIntArray(); /* renamed from: c, reason: collision with root package name */ private boolean f2177c = false; /* renamed from: d, reason: collision with root package name */ private boolean f2178d = false; static int a(SparseIntArray sparseIntArray, int i10) { int size = sparseIntArray.size() - 1; int i11 = 0; while (i11 <= size) { int i12 = (i11 + size) >>> 1; if (sparseIntArray.keyAt(i12) < i10) { i11 = i12 + 1; } else { size = i12 - 1; } } int i13 = i11 - 1; if (i13 < 0 || i13 >= sparseIntArray.size()) { return -1; } return sparseIntArray.keyAt(i13); } int b(int i10, int i11) { if (!this.f2178d) { return d(i10, i11); } int i12 = this.f2176b.get(i10, -1); if (i12 != -1) { return i12; } int d10 = d(i10, i11); this.f2176b.put(i10, d10); return d10; } int c(int i10, int i11) { if (!this.f2177c) { return e(i10, i11); } int i12 = this.f2175a.get(i10, -1); if (i12 != -1) { return i12; } int e10 = e(i10, i11); this.f2175a.put(i10, e10); return e10; } /* JADX WARN: Removed duplicated region for block: B:11:0x002d */ /* JADX WARN: Removed duplicated region for block: B:23:0x0043 */ /* JADX WARN: Removed duplicated region for block: B:26:? A[RETURN, SYNTHETIC] */ /* Code decompiled incorrectly, please refer to instructions dump. To view partially-correct code enable 'Show inconsistent code' option in preferences */ public int d(int r7, int r8) { /* r6 = this; boolean r0 = r6.f2178d r1 = 0 if (r0 == 0) goto L24 android.util.SparseIntArray r0 = r6.f2176b int r0 = a(r0, r7) r2 = -1 if (r0 == r2) goto L24 android.util.SparseIntArray r2 = r6.f2176b int r2 = r2.get(r0) int r3 = r0 + 1 int r4 = r6.c(r0, r8) int r0 = r6.f(r0) int r4 = r4 + r0 if (r4 != r8) goto L27 int r2 = r2 + 1 goto L26 L24: r2 = 0 r3 = 0 L26: r4 = 0 L27: int r0 = r6.f(r7) L2b: if (r3 >= r7) goto L40 int r5 = r6.f(r3) int r4 = r4 + r5 if (r4 != r8) goto L38 int r2 = r2 + 1 r4 = 0 goto L3d L38: if (r4 <= r8) goto L3d int r2 = r2 + 1 r4 = r5 L3d: int r3 = r3 + 1 goto L2b L40: int r4 = r4 + r0 if (r4 <= r8) goto L45 int r2 = r2 + 1 L45: return r2 */ throw new UnsupportedOperationException("Method not decompiled: androidx.recyclerview.widget.GridLayoutManager.c.d(int, int):int"); } public abstract int e(int i10, int i11); public abstract int f(int i10); public void g() { this.f2176b.clear(); } public void h() { this.f2175a.clear(); } } public GridLayoutManager(Context context, AttributeSet attributeSet, int i10, int i11) { super(context, attributeSet, i10, i11); this.I = false; this.J = -1; this.M = new SparseIntArray(); this.N = new SparseIntArray(); this.O = new a(); this.P = new Rect(); d3(RecyclerView.o.i0(context, attributeSet, i10, i11).f2294b); } private void N2(RecyclerView.v vVar, RecyclerView.a0 a0Var, int i10, boolean z10) { int i11; int i12; int i13; int i14 = 0; if (z10) { i12 = i10; i11 = 0; i13 = 1; } else { i11 = i10 - 1; i12 = -1; i13 = -1; } while (i11 != i12) { View view = this.L[i11]; b bVar = (b) view.getLayoutParams(); int Z2 = Z2(vVar, a0Var, h0(view)); bVar.f2174f = Z2; bVar.f2173e = i14; i14 += Z2; i11 += i13; } } private void O2() { int J = J(); for (int i10 = 0; i10 < J; i10++) { b bVar = (b) I(i10).getLayoutParams(); int a10 = bVar.a(); this.M.put(a10, bVar.f()); this.N.put(a10, bVar.e()); } } private void P2(int i10) { this.K = Q2(this.K, this.J, i10); } static int[] Q2(int[] iArr, int i10, int i11) { int i12; if (iArr == null || iArr.length != i10 + 1 || iArr[iArr.length - 1] != i11) { iArr = new int[i10 + 1]; } int i13 = 0; iArr[0] = 0; int i14 = i11 / i10; int i15 = i11 % i10; int i16 = 0; for (int i17 = 1; i17 <= i10; i17++) { i13 += i15; if (i13 <= 0 || i10 - i13 >= i15) { i12 = i14; } else { i12 = i14 + 1; i13 -= i10; } i16 += i12; iArr[i17] = i16; } return iArr; } private void R2() { this.M.clear(); this.N.clear(); } private int S2(RecyclerView.a0 a0Var) { if (J() != 0 && a0Var.b() != 0) { T1(); boolean r22 = r2(); View Y1 = Y1(!r22, true); View X1 = X1(!r22, true); if (Y1 != null && X1 != null) { int b10 = this.O.b(h0(Y1), this.J); int b11 = this.O.b(h0(X1), this.J); int max = this.f2184x ? Math.max(0, ((this.O.b(a0Var.b() - 1, this.J) + 1) - Math.max(b10, b11)) - 1) : Math.max(0, Math.min(b10, b11)); if (r22) { return Math.round((max * (Math.abs(this.f2181u.d(X1) - this.f2181u.g(Y1)) / ((this.O.b(h0(X1), this.J) - this.O.b(h0(Y1), this.J)) + 1))) + (this.f2181u.m() - this.f2181u.g(Y1))); } return max; } } return 0; } private int T2(RecyclerView.a0 a0Var) { if (J() != 0 && a0Var.b() != 0) { T1(); View Y1 = Y1(!r2(), true); View X1 = X1(!r2(), true); if (Y1 != null && X1 != null) { if (!r2()) { return this.O.b(a0Var.b() - 1, this.J) + 1; } int d10 = this.f2181u.d(X1) - this.f2181u.g(Y1); int b10 = this.O.b(h0(Y1), this.J); return (int) ((d10 / ((this.O.b(h0(X1), this.J) - b10) + 1)) * (this.O.b(a0Var.b() - 1, this.J) + 1)); } } return 0; } private void U2(RecyclerView.v vVar, RecyclerView.a0 a0Var, LinearLayoutManager.a aVar, int i10) { boolean z10 = i10 == 1; int Y2 = Y2(vVar, a0Var, aVar.f2188b); if (z10) { while (Y2 > 0) { int i11 = aVar.f2188b; if (i11 <= 0) { return; } int i12 = i11 - 1; aVar.f2188b = i12; Y2 = Y2(vVar, a0Var, i12); } return; } int b10 = a0Var.b() - 1; int i13 = aVar.f2188b; while (i13 < b10) { int i14 = i13 + 1; int Y22 = Y2(vVar, a0Var, i14); if (Y22 <= Y2) { break; } i13 = i14; Y2 = Y22; } aVar.f2188b = i13; } private void V2() { View[] viewArr = this.L; if (viewArr == null || viewArr.length != this.J) { this.L = new View[this.J]; } } private int X2(RecyclerView.v vVar, RecyclerView.a0 a0Var, int i10) { if (!a0Var.e()) { return this.O.b(i10, this.J); } int f10 = vVar.f(i10); if (f10 != -1) { return this.O.b(f10, this.J); } Log.w("GridLayoutManager", "Cannot find span size for pre layout position. " + i10); return 0; } private int Y2(RecyclerView.v vVar, RecyclerView.a0 a0Var, int i10) { if (!a0Var.e()) { return this.O.c(i10, this.J); } int i11 = this.N.get(i10, -1); if (i11 != -1) { return i11; } int f10 = vVar.f(i10); if (f10 != -1) { return this.O.c(f10, this.J); } Log.w("GridLayoutManager", "Cannot find span size for pre layout position. It is not cached, not in the adapter. Pos:" + i10); return 0; } private int Z2(RecyclerView.v vVar, RecyclerView.a0 a0Var, int i10) { if (!a0Var.e()) { return this.O.f(i10); } int i11 = this.M.get(i10, -1); if (i11 != -1) { return i11; } int f10 = vVar.f(i10); if (f10 != -1) { return this.O.f(f10); } Log.w("GridLayoutManager", "Cannot find span size for pre layout position. It is not cached, not in the adapter. Pos:" + i10); return 1; } private void a3(float f10, int i10) { P2(Math.max(Math.round(f10 * this.J), i10)); } private void b3(View view, int i10, boolean z10) { int i11; int i12; b bVar = (b) view.getLayoutParams(); Rect rect = bVar.f2298b; int i13 = rect.top + rect.bottom + ((ViewGroup.MarginLayoutParams) bVar).topMargin + ((ViewGroup.MarginLayoutParams) bVar).bottomMargin; int i14 = rect.left + rect.right + ((ViewGroup.MarginLayoutParams) bVar).leftMargin + ((ViewGroup.MarginLayoutParams) bVar).rightMargin; int W2 = W2(bVar.f2173e, bVar.f2174f); if (this.f2179s == 1) { i12 = RecyclerView.o.K(W2, i10, i14, ((ViewGroup.MarginLayoutParams) bVar).width, false); i11 = RecyclerView.o.K(this.f2181u.n(), X(), i13, ((ViewGroup.MarginLayoutParams) bVar).height, true); } else { int K = RecyclerView.o.K(W2, i10, i13, ((ViewGroup.MarginLayoutParams) bVar).height, false); int K2 = RecyclerView.o.K(this.f2181u.n(), p0(), i14, ((ViewGroup.MarginLayoutParams) bVar).width, true); i11 = K; i12 = K2; } c3(view, i12, i11, z10); } private void c3(View view, int i10, int i11, boolean z10) { RecyclerView.p pVar = (RecyclerView.p) view.getLayoutParams(); if (z10 ? H1(view, i10, i11, pVar) : F1(view, i10, i11, pVar)) { view.measure(i10, i11); } } private void e3() { int W; int g02; if (p2() == 1) { W = o0() - f0(); g02 = e0(); } else { W = W() - d0(); g02 = g0(); } P2(W - g02); } @Override // androidx.recyclerview.widget.RecyclerView.o public void C1(Rect rect, int i10, int i11) { int n10; int n11; if (this.K == null) { super.C1(rect, i10, i11); } int e02 = e0() + f0(); int g02 = g0() + d0(); if (this.f2179s == 1) { n11 = RecyclerView.o.n(i11, rect.height() + g02, b0()); int[] iArr = this.K; n10 = RecyclerView.o.n(i10, iArr[iArr.length - 1] + e02, c0()); } else { n10 = RecyclerView.o.n(i10, rect.width() + e02, c0()); int[] iArr2 = this.K; n11 = RecyclerView.o.n(i11, iArr2[iArr2.length - 1] + g02, b0()); } B1(n10, n11); } @Override // androidx.recyclerview.widget.LinearLayoutManager, androidx.recyclerview.widget.RecyclerView.o public RecyclerView.p D() { return this.f2179s == 0 ? new b(-2, -1) : new b(-1, -2); } @Override // androidx.recyclerview.widget.RecyclerView.o public RecyclerView.p E(Context context, AttributeSet attributeSet) { return new b(context, attributeSet); } @Override // androidx.recyclerview.widget.LinearLayoutManager public void E2(boolean z10) { if (z10) { throw new UnsupportedOperationException("GridLayoutManager does not support stack from end. Consider using reverse layout"); } super.E2(false); } @Override // androidx.recyclerview.widget.RecyclerView.o public RecyclerView.p F(ViewGroup.LayoutParams layoutParams) { return layoutParams instanceof ViewGroup.MarginLayoutParams ? new b((ViewGroup.MarginLayoutParams) layoutParams) : new b(layoutParams); } /* JADX WARN: Code restructure failed: missing block: B:68:0x00d6, code lost: if (r13 == (r2 > r15)) goto L49; */ /* JADX WARN: Code restructure failed: missing block: B:83:0x00f6, code lost: if (r13 == (r2 > r7)) goto L50; */ /* JADX WARN: Removed duplicated region for block: B:53:0x0107 */ @Override // androidx.recyclerview.widget.LinearLayoutManager, androidx.recyclerview.widget.RecyclerView.o /* Code decompiled incorrectly, please refer to instructions dump. To view partially-correct code enable 'Show inconsistent code' option in preferences */ public android.view.View J0(android.view.View r24, int r25, androidx.recyclerview.widget.RecyclerView.v r26, androidx.recyclerview.widget.RecyclerView.a0 r27) { /* Method dump skipped, instructions count: 337 To view this dump change 'Code comments level' option to 'DEBUG' */ throw new UnsupportedOperationException("Method not decompiled: androidx.recyclerview.widget.GridLayoutManager.J0(android.view.View, int, androidx.recyclerview.widget.RecyclerView$v, androidx.recyclerview.widget.RecyclerView$a0):android.view.View"); } @Override // androidx.recyclerview.widget.LinearLayoutManager, androidx.recyclerview.widget.RecyclerView.o public boolean L1() { return this.D == null && !this.I; } @Override // androidx.recyclerview.widget.RecyclerView.o public int N(RecyclerView.v vVar, RecyclerView.a0 a0Var) { if (this.f2179s == 1) { return this.J; } if (a0Var.b() < 1) { return 0; } return X2(vVar, a0Var, a0Var.b() - 1) + 1; } @Override // androidx.recyclerview.widget.LinearLayoutManager void N1(RecyclerView.a0 a0Var, LinearLayoutManager.c cVar, RecyclerView.o.c cVar2) { int i10 = this.J; for (int i11 = 0; i11 < this.J && cVar.c(a0Var) && i10 > 0; i11++) { int i12 = cVar.f2199d; cVar2.a(i12, Math.max(0, cVar.f2202g)); i10 -= this.O.f(i12); cVar.f2199d += cVar.f2200e; } } @Override // androidx.recyclerview.widget.RecyclerView.o public void P0(RecyclerView.v vVar, RecyclerView.a0 a0Var, View view, a0 a0Var2) { ViewGroup.LayoutParams layoutParams = view.getLayoutParams(); if (!(layoutParams instanceof b)) { super.O0(view, a0Var2); return; } b bVar = (b) layoutParams; int X2 = X2(vVar, a0Var, bVar.a()); if (this.f2179s == 0) { a0Var2.Z(a0.c.a(bVar.e(), bVar.f(), X2, 1, false, false)); } else { a0Var2.Z(a0.c.a(X2, 1, bVar.e(), bVar.f(), false, false)); } } @Override // androidx.recyclerview.widget.RecyclerView.o public void R0(RecyclerView recyclerView, int i10, int i11) { this.O.h(); this.O.g(); } @Override // androidx.recyclerview.widget.RecyclerView.o public void S0(RecyclerView recyclerView) { this.O.h(); this.O.g(); } @Override // androidx.recyclerview.widget.RecyclerView.o public void T0(RecyclerView recyclerView, int i10, int i11, int i12) { this.O.h(); this.O.g(); } @Override // androidx.recyclerview.widget.RecyclerView.o public void U0(RecyclerView recyclerView, int i10, int i11) { this.O.h(); this.O.g(); } @Override // androidx.recyclerview.widget.RecyclerView.o public void W0(RecyclerView recyclerView, int i10, int i11, Object obj) { this.O.h(); this.O.g(); } int W2(int i10, int i11) { if (this.f2179s != 1 || !q2()) { int[] iArr = this.K; return iArr[i11 + i10] - iArr[i10]; } int[] iArr2 = this.K; int i12 = this.J; return iArr2[i12 - i10] - iArr2[(i12 - i10) - i11]; } @Override // androidx.recyclerview.widget.LinearLayoutManager, androidx.recyclerview.widget.RecyclerView.o public void X0(RecyclerView.v vVar, RecyclerView.a0 a0Var) { if (a0Var.e()) { O2(); } super.X0(vVar, a0Var); R2(); } @Override // androidx.recyclerview.widget.LinearLayoutManager, androidx.recyclerview.widget.RecyclerView.o public void Y0(RecyclerView.a0 a0Var) { super.Y0(a0Var); this.I = false; } public void d3(int i10) { if (i10 == this.J) { return; } this.I = true; if (i10 >= 1) { this.J = i10; this.O.h(); t1(); } else { throw new IllegalArgumentException("Span count should be at least 1. Provided " + i10); } } @Override // androidx.recyclerview.widget.LinearLayoutManager View h2(RecyclerView.v vVar, RecyclerView.a0 a0Var, int i10, int i11, int i12) { T1(); int m10 = this.f2181u.m(); int i13 = this.f2181u.i(); int i14 = i11 > i10 ? 1 : -1; View view = null; View view2 = null; while (i10 != i11) { View I = I(i10); int h02 = h0(I); if (h02 >= 0 && h02 < i12 && Y2(vVar, a0Var, h02) == 0) { if (((RecyclerView.p) I.getLayoutParams()).c()) { if (view2 == null) { view2 = I; } } else { if (this.f2181u.g(I) < i13 && this.f2181u.d(I) >= m10) { return I; } if (view == null) { view = I; } } } i10 += i14; } return view != null ? view : view2; } @Override // androidx.recyclerview.widget.RecyclerView.o public int k0(RecyclerView.v vVar, RecyclerView.a0 a0Var) { if (this.f2179s == 0) { return this.J; } if (a0Var.b() < 1) { return 0; } return X2(vVar, a0Var, a0Var.b() - 1) + 1; } @Override // androidx.recyclerview.widget.RecyclerView.o public boolean m(RecyclerView.p pVar) { return pVar instanceof b; } @Override // androidx.recyclerview.widget.LinearLayoutManager, androidx.recyclerview.widget.RecyclerView.o public int r(RecyclerView.a0 a0Var) { return this.Q ? S2(a0Var) : super.r(a0Var); } @Override // androidx.recyclerview.widget.LinearLayoutManager, androidx.recyclerview.widget.RecyclerView.o public int s(RecyclerView.a0 a0Var) { return this.Q ? T2(a0Var) : super.s(a0Var); } /* JADX WARN: Code restructure failed: missing block: B:30:0x009f, code lost: r21.f2193b = true; */ /* JADX WARN: Code restructure failed: missing block: B:31:0x00a1, 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 s2(androidx.recyclerview.widget.RecyclerView.v r18, androidx.recyclerview.widget.RecyclerView.a0 r19, androidx.recyclerview.widget.LinearLayoutManager.c r20, androidx.recyclerview.widget.LinearLayoutManager.b r21) { /* Method dump skipped, instructions count: 557 To view this dump change 'Code comments level' option to 'DEBUG' */ throw new UnsupportedOperationException("Method not decompiled: androidx.recyclerview.widget.GridLayoutManager.s2(androidx.recyclerview.widget.RecyclerView$v, androidx.recyclerview.widget.RecyclerView$a0, androidx.recyclerview.widget.LinearLayoutManager$c, androidx.recyclerview.widget.LinearLayoutManager$b):void"); } @Override // androidx.recyclerview.widget.LinearLayoutManager, androidx.recyclerview.widget.RecyclerView.o public int u(RecyclerView.a0 a0Var) { return this.Q ? S2(a0Var) : super.u(a0Var); } @Override // androidx.recyclerview.widget.LinearLayoutManager void u2(RecyclerView.v vVar, RecyclerView.a0 a0Var, LinearLayoutManager.a aVar, int i10) { super.u2(vVar, a0Var, aVar, i10); e3(); if (a0Var.b() > 0 && !a0Var.e()) { U2(vVar, a0Var, aVar, i10); } V2(); } @Override // androidx.recyclerview.widget.LinearLayoutManager, androidx.recyclerview.widget.RecyclerView.o public int v(RecyclerView.a0 a0Var) { return this.Q ? T2(a0Var) : super.v(a0Var); } @Override // androidx.recyclerview.widget.LinearLayoutManager, androidx.recyclerview.widget.RecyclerView.o public int w1(int i10, RecyclerView.v vVar, RecyclerView.a0 a0Var) { e3(); V2(); return super.w1(i10, vVar, a0Var); } @Override // androidx.recyclerview.widget.LinearLayoutManager, androidx.recyclerview.widget.RecyclerView.o public int y1(int i10, RecyclerView.v vVar, RecyclerView.a0 a0Var) { e3(); V2(); return super.y1(i10, vVar, a0Var); } public static class b extends RecyclerView.p { /* renamed from: e, reason: collision with root package name */ int f2173e; /* renamed from: f, reason: collision with root package name */ int f2174f; public b(Context context, AttributeSet attributeSet) { super(context, attributeSet); this.f2173e = -1; this.f2174f = 0; } public int e() { return this.f2173e; } public int f() { return this.f2174f; } public b(int i10, int i11) { super(i10, i11); this.f2173e = -1; this.f2174f = 0; } public b(ViewGroup.MarginLayoutParams marginLayoutParams) { super(marginLayoutParams); this.f2173e = -1; this.f2174f = 0; } public b(ViewGroup.LayoutParams layoutParams) { super(layoutParams); this.f2173e = -1; this.f2174f = 0; } } public GridLayoutManager(Context context, int i10, int i11, boolean z10) { super(context, i11, z10); this.I = false; this.J = -1; this.M = new SparseIntArray(); this.N = new SparseIntArray(); this.O = new a(); this.P = new Rect(); d3(i10); } }