package androidx.recyclerview.widget; import android.content.Context; import android.graphics.Rect; import android.util.AttributeSet; import android.util.SparseIntArray; import android.view.View; import android.view.ViewGroup; import androidx.core.view.ViewCompat; import androidx.core.view.accessibility.AccessibilityNodeInfoCompat; import androidx.recyclerview.widget.LinearLayoutManager; import androidx.recyclerview.widget.RecyclerView; import com.google.android.gms.maps.model.BitmapDescriptorFactory; import java.util.Arrays; import o.Emo; /* loaded from: classes.dex */ public class GridLayoutManager extends LinearLayoutManager { private int[] A; private View[] C; private boolean D; public Sts a; final Rect b; final SparseIntArray c; final SparseIntArray d; public int e; private boolean z; public GridLayoutManager(Context context, AttributeSet attributeSet, int i, int i2) { super(context, attributeSet, i, i2); this.D = false; this.e = -1; this.c = new SparseIntArray(); this.d = new SparseIntArray(); this.a = new LWm(); this.b = new Rect(); k(Ai_(context, attributeSet, i, i2).d); } public GridLayoutManager(int i, byte b) { this.D = false; this.e = -1; this.c = new SparseIntArray(); this.d = new SparseIntArray(); this.a = new LWm(); this.b = new Rect(); k(i); } public GridLayoutManager(int i) { super(1, false); this.D = false; this.e = -1; this.c = new SparseIntArray(); this.d = new SparseIntArray(); this.a = new LWm(); this.b = new Rect(); k(i); } @Override // androidx.recyclerview.widget.LinearLayoutManager public final void a(boolean z) { if (z) { throw new UnsupportedOperationException("GridLayoutManager does not support stack from end. Consider using reverse layout"); } super.a(false); } @Override // androidx.recyclerview.widget.RecyclerView.tOB public final int d(RecyclerView.huo huoVar, RecyclerView.AcL acL) { if (this.h == 0) { return this.e; } if ((acL.c ? acL.i - acL.b : acL.h) <= 0) { return 0; } return b(huoVar, acL, (acL.c ? acL.i - acL.b : acL.h) - 1) + 1; } @Override // androidx.recyclerview.widget.RecyclerView.tOB public final int a(RecyclerView.huo huoVar, RecyclerView.AcL acL) { if (this.h == 1) { return this.e; } if ((acL.c ? acL.i - acL.b : acL.h) <= 0) { return 0; } return b(huoVar, acL, (acL.c ? acL.i - acL.b : acL.h) - 1) + 1; } @Override // androidx.recyclerview.widget.RecyclerView.tOB public final void b(RecyclerView.huo huoVar, RecyclerView.AcL acL, View view, AccessibilityNodeInfoCompat accessibilityNodeInfoCompat) { ViewGroup.LayoutParams layoutParams = view.getLayoutParams(); if (!(layoutParams instanceof HBt)) { super.d(view, accessibilityNodeInfoCompat); return; } HBt hBt = (HBt) layoutParams; int b = b(huoVar, acL, hBt.g.getLayoutPosition()); if (this.h == 0) { accessibilityNodeInfoCompat.d(AccessibilityNodeInfoCompat.CollectionItemInfoCompat.c(hBt.c, hBt.a, b, 1, false, false)); } else { accessibilityNodeInfoCompat.d(AccessibilityNodeInfoCompat.CollectionItemInfoCompat.c(b, 1, hBt.c, hBt.a, false, false)); } } @Override // androidx.recyclerview.widget.LinearLayoutManager, androidx.recyclerview.widget.RecyclerView.tOB public final void d(RecyclerView.AcL acL) { super.d(acL); this.D = false; } @Override // androidx.recyclerview.widget.RecyclerView.tOB public final void d(RecyclerView recyclerView, int i, int i2) { this.a.e.clear(); this.a.b.clear(); } @Override // androidx.recyclerview.widget.RecyclerView.tOB public final void l_() { this.a.e.clear(); this.a.b.clear(); } @Override // androidx.recyclerview.widget.RecyclerView.tOB public final void c(RecyclerView recyclerView, int i, int i2) { this.a.e.clear(); this.a.b.clear(); } @Override // androidx.recyclerview.widget.RecyclerView.tOB public final void a(RecyclerView recyclerView, int i, int i2, Object obj) { this.a.e.clear(); this.a.b.clear(); } @Override // androidx.recyclerview.widget.RecyclerView.tOB public final void b(RecyclerView recyclerView, int i, int i2, int i3) { this.a.e.clear(); this.a.b.clear(); } @Override // androidx.recyclerview.widget.LinearLayoutManager, androidx.recyclerview.widget.RecyclerView.tOB public final RecyclerView.saX e() { if (this.h == 0) { return new HBt(-2, -1); } return new HBt(-1, -2); } @Override // androidx.recyclerview.widget.RecyclerView.tOB public final RecyclerView.saX Hz_(Context context, AttributeSet attributeSet) { return new HBt(context, attributeSet); } @Override // androidx.recyclerview.widget.RecyclerView.tOB public final RecyclerView.saX AB_(ViewGroup.LayoutParams layoutParams) { if (layoutParams instanceof ViewGroup.MarginLayoutParams) { return new HBt((ViewGroup.MarginLayoutParams) layoutParams); } return new HBt(layoutParams); } @Override // androidx.recyclerview.widget.RecyclerView.tOB public final boolean b(RecyclerView.saX sax) { return sax instanceof HBt; } @Override // androidx.recyclerview.widget.RecyclerView.tOB public final void AF_(Rect rect, int i, int i2) { int a_; int a_2; if (this.A == null) { super.AF_(rect, i, i2); } int paddingLeft = getPaddingLeft() + getPaddingRight(); int paddingTop = getPaddingTop() + getPaddingBottom(); if (this.h == 1) { a_2 = a_(i2, rect.height() + paddingTop, ViewCompat.o(this.s)); int[] iArr = this.A; a_ = a_(i, iArr[iArr.length - 1] + paddingLeft, ViewCompat.p(this.s)); } else { a_ = a_(i, rect.width() + paddingLeft, ViewCompat.p(this.s)); int[] iArr2 = this.A; a_2 = a_(i2, iArr2[iArr2.length - 1] + paddingTop, ViewCompat.o(this.s)); } this.s.setMeasuredDimension(a_, a_2); } private int c(int i, int i2) { if (this.h == 1 && ViewCompat.m(this.s) == 1) { int[] iArr = this.A; int i3 = this.e - i; return iArr[i3] - iArr[i3 - i2]; } int[] iArr2 = this.A; return iArr2[i2 + i] - iArr2[i]; } /* JADX INFO: Access modifiers changed from: package-private */ @Override // androidx.recyclerview.widget.LinearLayoutManager public final void c(RecyclerView.huo huoVar, RecyclerView.AcL acL, LinearLayoutManager.RVV rvv, int i) { int i2; int a; super.c(huoVar, acL, rvv, i); s(); if ((acL.c ? acL.i - acL.b : acL.h) > 0 && !acL.c) { boolean z = i == 1; int a2 = a(huoVar, acL, rvv.b); if (!z) { int i3 = acL.c ? acL.i - acL.b : acL.h; int i4 = rvv.b; while (i4 < i3 - 1 && (a = a(huoVar, acL, (i2 = i4 + 1))) > a2) { i4 = i2; a2 = a; } rvv.b = i4; } else { while (a2 > 0 && rvv.b > 0) { rvv.b--; a2 = a(huoVar, acL, rvv.b); } } } View[] viewArr = this.C; if (viewArr == null || viewArr.length != this.e) { this.C = new View[this.e]; } } @Override // androidx.recyclerview.widget.LinearLayoutManager, androidx.recyclerview.widget.RecyclerView.tOB public final int b(int i, RecyclerView.huo huoVar, RecyclerView.AcL acL) { s(); View[] viewArr = this.C; if (viewArr == null || viewArr.length != this.e) { this.C = new View[this.e]; } return super.b(i, huoVar, acL); } @Override // androidx.recyclerview.widget.LinearLayoutManager, androidx.recyclerview.widget.RecyclerView.tOB public final int c(int i, RecyclerView.huo huoVar, RecyclerView.AcL acL) { s(); View[] viewArr = this.C; if (viewArr == null || viewArr.length != this.e) { this.C = new View[this.e]; } return super.c(i, huoVar, acL); } @Override // androidx.recyclerview.widget.LinearLayoutManager final View c(RecyclerView.huo huoVar, RecyclerView.AcL acL, boolean z, boolean z2) { Emo emo = this.k; int c = emo != null ? emo.d.c() - emo.b.size() : 0; int i = 1; if (z2) { Emo emo2 = this.k; r0 = (emo2 != null ? emo2.d.c() - emo2.b.size() : 0) - 1; c = -1; i = -1; } int i2 = acL.c ? acL.i - acL.b : acL.h; f(); int i3 = this.i.i(); int d = this.i.d(); View view = null; View view2 = null; while (r0 != c) { View f = f(r0); int layoutPosition = ((RecyclerView.saX) f.getLayoutParams()).g.getLayoutPosition(); if (layoutPosition >= 0 && layoutPosition < i2 && a(huoVar, acL, layoutPosition) == 0) { if (((RecyclerView.saX) f.getLayoutParams()).g.isRemoved()) { if (view2 == null) { view2 = f; } } else { if (this.i.c(f) < d && this.i.a(f) >= i3) { return f; } if (view == null) { view = f; } } } r0 += i; } return view != null ? view : view2; } @Override // androidx.recyclerview.widget.LinearLayoutManager final void c(RecyclerView.AcL acL, LinearLayoutManager.Sts sts, RecyclerView.tOB.Sts sts2) { int i; int i2 = this.e; for (int i3 = 0; i3 < this.e && (i = sts.e) >= 0; i3++) { if (i >= (acL.c ? acL.i - acL.b : acL.h) || i2 <= 0) { return; } int i4 = sts.e; sts2.c(i4, Math.max(0, sts.f6393o)); i2 -= this.a.e(i4); sts.e += sts.g; } } @Override // androidx.recyclerview.widget.LinearLayoutManager final void c(RecyclerView.huo huoVar, RecyclerView.AcL acL, LinearLayoutManager.Sts sts, LinearLayoutManager.IeS ieS) { int i; int i2; int i3; int i4; int i5; int i6; int i7; int i8; int i9; int paddingLeft; int b; int i10; int i11; int d; int i12; int i13; View d2; int f = this.i.f(); boolean z = f != 1073741824; Emo emo = this.k; int i14 = (emo == null || emo.d.c() - emo.b.size() <= 0) ? 0 : this.A[this.e]; if (z) { s(); } boolean z2 = sts.g == 1; int i15 = this.e; if (!z2) { i15 = a(huoVar, acL, sts.e) + e(huoVar, acL, sts.e); } int i16 = 0; while (i16 < this.e && (i13 = sts.e) >= 0) { if (i13 >= (acL.c ? acL.i - acL.b : acL.h) || i15 <= 0) { break; } int i17 = sts.e; int e = e(huoVar, acL, i17); if (e > this.e) { StringBuilder sb = new StringBuilder("Item at position "); sb.append(i17); sb.append(" requires "); sb.append(e); sb.append(" spans but GridLayoutManager has only "); sb.append(this.e); sb.append(" spans."); throw new IllegalArgumentException(sb.toString()); } i15 -= e; if (i15 < 0 || (d2 = sts.d(huoVar)) == null) { break; } this.C[i16] = d2; i16++; } if (i16 == 0) { ieS.c = true; return; } if (z2) { i4 = 1; i = 0; i2 = 0; i3 = i16; } else { i = i16 - 1; i2 = 0; i3 = -1; i4 = -1; } while (i != i3) { View view = this.C[i]; HBt hBt = (HBt) view.getLayoutParams(); hBt.a = e(huoVar, acL, ((RecyclerView.saX) view.getLayoutParams()).g.getLayoutPosition()); hBt.c = i2; i2 += hBt.a; i += i4; } float f2 = BitmapDescriptorFactory.HUE_RED; int i18 = 0; for (int i19 = 0; i19 < i16; i19++) { View view2 = this.C[i19]; if (sts.m == null) { if (z2) { a_(view2); } else { d(view2, 0); } } else if (z2) { e(view2); } else { c(view2); } Rect rect = this.b; RecyclerView recyclerView = this.s; if (recyclerView == null) { rect.set(0, 0, 0, 0); } else { rect.set(recyclerView.Ab_(view2)); } e(view2, f, false); int e2 = this.i.e(view2); if (e2 > i18) { i18 = e2; } float b2 = this.i.b(view2) / ((HBt) view2.getLayoutParams()).a; if (b2 > f2) { f2 = b2; } } if (z) { h(Math.max(Math.round(f2 * this.e), i14)); i18 = 0; for (int i20 = 0; i20 < i16; i20++) { View view3 = this.C[i20]; e(view3, 1073741824, true); int e3 = this.i.e(view3); if (e3 > i18) { i18 = e3; } } } for (int i21 = 0; i21 < i16; i21++) { View view4 = this.C[i21]; if (this.i.e(view4) != i18) { HBt hBt2 = (HBt) view4.getLayoutParams(); Rect rect2 = hBt2.d; int i22 = rect2.top + rect2.bottom + ((ViewGroup.MarginLayoutParams) hBt2).topMargin + ((ViewGroup.MarginLayoutParams) hBt2).bottomMargin; int i23 = rect2.left + rect2.right + ((ViewGroup.MarginLayoutParams) hBt2).leftMargin + ((ViewGroup.MarginLayoutParams) hBt2).rightMargin; int c = c(hBt2.c, hBt2.a); if (this.h == 1) { i12 = d(c, 1073741824, i23, ((ViewGroup.LayoutParams) hBt2).width, false); d = View.MeasureSpec.makeMeasureSpec(i18 - i22, 1073741824); } else { int makeMeasureSpec = View.MeasureSpec.makeMeasureSpec(i18 - i23, 1073741824); d = d(c, 1073741824, i22, ((ViewGroup.LayoutParams) hBt2).height, false); i12 = makeMeasureSpec; } a(view4, i12, d, true); } } ieS.d = i18; if (this.h == 1) { if (sts.h == -1) { i11 = sts.j; i10 = i11 - i18; } else { i10 = sts.j; i11 = i10 + i18; } i9 = i10; i7 = 0; i8 = i11; i6 = 0; } else { if (sts.h == -1) { i6 = sts.j; i5 = i6 - i18; } else { i5 = sts.j; i6 = i5 + i18; } i7 = i5; i8 = 0; i9 = 0; } for (int i24 = 0; i24 < i16; i24++) { View view5 = this.C[i24]; HBt hBt3 = (HBt) view5.getLayoutParams(); if (this.h != 1) { int paddingTop = getPaddingTop() + this.A[hBt3.c]; i9 = paddingTop; i8 = this.i.b(view5) + paddingTop; } else { if (ViewCompat.m(this.s) == 1) { paddingLeft = this.A[this.e - hBt3.c] + getPaddingLeft(); b = paddingLeft - this.i.b(view5); } else { b = getPaddingLeft() + this.A[hBt3.c]; paddingLeft = this.i.b(view5) + b; } int i25 = paddingLeft; i7 = b; i6 = i25; } b(view5, i7, i9, i6, i8); if (hBt3.g.isRemoved() || hBt3.g.isUpdated()) { ieS.a = true; } ieS.b = view5.hasFocusable() | ieS.b; } Arrays.fill(this.C, (Object) null); } private void e(View view, int i, boolean z) { int i2; int i3; HBt hBt = (HBt) view.getLayoutParams(); Rect rect = hBt.d; int i4 = rect.top + rect.bottom + ((ViewGroup.MarginLayoutParams) hBt).topMargin + ((ViewGroup.MarginLayoutParams) hBt).bottomMargin; int i5 = rect.left + rect.right + ((ViewGroup.MarginLayoutParams) hBt).leftMargin + ((ViewGroup.MarginLayoutParams) hBt).rightMargin; int c = c(hBt.c, hBt.a); if (this.h == 1) { i3 = d(c, i, i5, ((ViewGroup.LayoutParams) hBt).width, false); i2 = d(this.i.h(), this.m, i4, ((ViewGroup.LayoutParams) hBt).height, true); } else { int d = d(c, i, i4, ((ViewGroup.LayoutParams) hBt).height, false); int d2 = d(this.i.h(), this.x, i5, ((ViewGroup.LayoutParams) hBt).width, true); i2 = d; i3 = d2; } a(view, i3, i2, z); } private void a(View view, int i, int i2, boolean z) { boolean d; RecyclerView.saX sax = (RecyclerView.saX) view.getLayoutParams(); if (z) { d = a(view, i, i2, sax); } else { d = d(view, i, i2, sax); } if (d) { view.measure(i, i2); } } private void k(int i) { if (i == this.e) { return; } this.D = true; if (i <= 0) { throw new IllegalArgumentException("Span count should be at least 1. Provided ".concat(String.valueOf(i))); } this.e = i; this.a.e.clear(); RecyclerView recyclerView = this.s; if (recyclerView != null) { recyclerView.requestLayout(); } } /* loaded from: classes.dex */ public static abstract class Sts { final SparseIntArray e = new SparseIntArray(); final SparseIntArray b = new SparseIntArray(); boolean a = false; boolean d = false; public abstract int e(int i); public int d(int i, int i2) { int e = e(i); if (e == i2) { return 0; } int i3 = 0; for (int i4 = 0; i4 < i; i4++) { int e2 = e(i4); i3 += e2; if (i3 == i2) { i3 = 0; } else if (i3 > i2) { i3 = e2; } } if (e + i3 <= i2) { return i3; } return 0; } public final int b(int i, int i2) { int e = e(i); int i3 = 0; int i4 = 0; for (int i5 = 0; i5 < i; i5++) { int e2 = e(i5); i4 += e2; if (i4 == i2) { i3++; i4 = 0; } else if (i4 > i2) { i3++; i4 = e2; } } return i4 + e > i2 ? i3 + 1 : i3; } } /* JADX WARN: Code restructure failed: missing block: B:64:0x00e2, code lost: if (r13 == (r2 > r15)) goto L60; */ /* JADX WARN: Code restructure failed: missing block: B:79:0x0110, code lost: if (r13 == (r2 > r8)) goto L76; */ /* JADX WARN: Removed duplicated region for block: B:52:0x0118 */ /* JADX WARN: Removed duplicated region for block: B:54:0x0127 */ @Override // androidx.recyclerview.widget.LinearLayoutManager, androidx.recyclerview.widget.RecyclerView.tOB /* Code decompiled incorrectly, please refer to instructions dump. To view partially-correct add '--show-bad-code' argument */ public final android.view.View a(android.view.View r23, int r24, androidx.recyclerview.widget.RecyclerView.huo r25, androidx.recyclerview.widget.RecyclerView.AcL r26) { /* Method dump skipped, instructions count: 335 To view this dump add '--comments-level debug' option */ throw new UnsupportedOperationException("Method not decompiled: androidx.recyclerview.widget.GridLayoutManager.a(android.view.View, int, androidx.recyclerview.widget.RecyclerView$huo, androidx.recyclerview.widget.RecyclerView$AcL):android.view.View"); } @Override // androidx.recyclerview.widget.LinearLayoutManager, androidx.recyclerview.widget.RecyclerView.tOB public final boolean n_() { return this.j == null && !this.D; } @Override // androidx.recyclerview.widget.LinearLayoutManager, androidx.recyclerview.widget.RecyclerView.tOB public final int e(RecyclerView.AcL acL) { return super.e(acL); } @Override // androidx.recyclerview.widget.LinearLayoutManager, androidx.recyclerview.widget.RecyclerView.tOB public final int a(RecyclerView.AcL acL) { return super.a(acL); } @Override // androidx.recyclerview.widget.LinearLayoutManager, androidx.recyclerview.widget.RecyclerView.tOB public final int b(RecyclerView.AcL acL) { return super.b(acL); } @Override // androidx.recyclerview.widget.LinearLayoutManager, androidx.recyclerview.widget.RecyclerView.tOB public final int c(RecyclerView.AcL acL) { return super.c(acL); } /* loaded from: classes.dex */ public static final class LWm extends Sts { @Override // androidx.recyclerview.widget.GridLayoutManager.Sts public final int e(int i) { return 1; } @Override // androidx.recyclerview.widget.GridLayoutManager.Sts public final int d(int i, int i2) { return i % i2; } } /* loaded from: classes.dex */ public static class HBt extends RecyclerView.saX { public int a; int c; public HBt(Context context, AttributeSet attributeSet) { super(context, attributeSet); this.c = -1; this.a = 0; } public HBt(int i, int i2) { super(i, i2); this.c = -1; this.a = 0; } public HBt(ViewGroup.MarginLayoutParams marginLayoutParams) { super(marginLayoutParams); this.c = -1; this.a = 0; } public HBt(ViewGroup.LayoutParams layoutParams) { super(layoutParams); this.c = -1; this.a = 0; } } private void h(int i) { int i2; int[] iArr = this.A; int i3 = this.e; if (iArr == null || iArr.length != i3 + 1 || iArr[iArr.length - 1] != i) { iArr = new int[i3 + 1]; } int i4 = 0; iArr[0] = 0; int i5 = i / i3; int i6 = i % i3; int i7 = 0; for (int i8 = 1; i8 <= i3; i8++) { i4 += i6; if (i4 <= 0 || i3 - i4 >= i6) { i2 = i5; } else { i2 = i5 + 1; i4 -= i3; } i7 += i2; iArr[i8] = i7; } this.A = iArr; } private int b(RecyclerView.huo huoVar, RecyclerView.AcL acL, int i) { if (!acL.c) { Sts sts = this.a; int i2 = this.e; boolean z = sts.d; return sts.b(i, i2); } int e = huoVar.e(i); if (e == -1) { return 0; } Sts sts2 = this.a; int i3 = this.e; boolean z2 = sts2.d; return sts2.b(e, i3); } private int a(RecyclerView.huo huoVar, RecyclerView.AcL acL, int i) { if (!acL.c) { Sts sts = this.a; int i2 = this.e; boolean z = sts.a; return sts.d(i, i2); } int i3 = this.d.get(i, -1); if (i3 != -1) { return i3; } int e = huoVar.e(i); if (e == -1) { return 0; } Sts sts2 = this.a; int i4 = this.e; boolean z2 = sts2.a; return sts2.d(e, i4); } private int e(RecyclerView.huo huoVar, RecyclerView.AcL acL, int i) { if (!acL.c) { return this.a.e(i); } int i2 = this.c.get(i, -1); if (i2 != -1) { return i2; } int e = huoVar.e(i); if (e == -1) { return 1; } return this.a.e(e); } private void s() { int paddingBottom; int paddingTop; if (this.h == 1) { paddingBottom = this.w - getPaddingRight(); paddingTop = getPaddingLeft(); } else { paddingBottom = this.l - getPaddingBottom(); paddingTop = getPaddingTop(); } h(paddingBottom - paddingTop); } @Override // androidx.recyclerview.widget.LinearLayoutManager, androidx.recyclerview.widget.RecyclerView.tOB public final void e(RecyclerView.huo huoVar, RecyclerView.AcL acL) { if (acL.c) { Emo emo = this.k; int c = emo != null ? emo.d.c() - emo.b.size() : 0; for (int i = 0; i < c; i++) { HBt hBt = (HBt) f(i).getLayoutParams(); int layoutPosition = hBt.g.getLayoutPosition(); this.c.put(layoutPosition, hBt.a); this.d.put(layoutPosition, hBt.c); } } super.e(huoVar, acL); this.c.clear(); this.d.clear(); } }