package androidx.compose.foundation.lazy.grid; import androidx.compose.foundation.lazy.grid.LazyGridSpanLayoutProvider; import androidx.compose.foundation.lazy.layout.IntervalList; import io.sentry.protocol.SentryTransaction; import java.util.ArrayList; import java.util.List; import kotlin.Metadata; import kotlin.collections.CollectionsKt; import kotlin.jvm.functions.Function1; import kotlin.jvm.internal.DefaultConstructorMarker; import kotlin.jvm.internal.Intrinsics; /* compiled from: LazyGridSpanLayoutProvider.kt */ @Metadata(d1 = {"\u0000L\n\u0002\u0018\u0002\n\u0002\u0010\u0000\n\u0000\n\u0002\u0018\u0002\n\u0002\b\u0002\n\u0002\u0010\b\n\u0002\b\u0003\n\u0002\u0018\u0002\n\u0002\u0018\u0002\n\u0002\u0018\u0002\n\u0000\n\u0002\u0010!\n\u0002\b\u0005\n\u0002\u0010 \n\u0002\u0018\u0002\n\u0002\b\n\n\u0002\u0018\u0002\n\u0002\b\u0004\n\u0002\u0010\u0002\n\u0002\b\u0006\b\u0000\u0018\u00002\u00020\u0001:\u0003()*B\r\u0012\u0006\u0010\u0002\u001a\u00020\u0003¢\u0006\u0002\u0010\u0004J\u0019\u0010\u001d\u001a\b\u0012\u0004\u0012\u00020\u00150\u00142\u0006\u0010\u001e\u001a\u00020\u0006H\u0002ø\u0001\u0000J\u000e\u0010\u001f\u001a\u00020 2\u0006\u0010!\u001a\u00020\u0006J\u000e\u0010\"\u001a\u00020\u00062\u0006\u0010#\u001a\u00020\u0006J\b\u0010$\u001a\u00020%H\u0002J\u0016\u0010&\u001a\u00020\u00062\u0006\u0010#\u001a\u00020\u00062\u0006\u0010'\u001a\u00020\u0006R\u0014\u0010\u0005\u001a\u00020\u00068BX\u0082\u0004¢\u0006\u0006\u001a\u0004\b\u0007\u0010\bR\u001e\u0010\t\u001a\u0012\u0012\u0004\u0012\u00020\u000b0\nj\b\u0012\u0004\u0012\u00020\u000b`\fX\u0082\u0004¢\u0006\u0002\n\u0000R\u0014\u0010\r\u001a\b\u0012\u0004\u0012\u00020\u00060\u000eX\u0082\u0004¢\u0006\u0002\n\u0000R\u000e\u0010\u000f\u001a\u00020\u0006X\u0082\u000e¢\u0006\u0002\n\u0000R\u000e\u0010\u0002\u001a\u00020\u0003X\u0082\u0004¢\u0006\u0002\n\u0000R\u000e\u0010\u0010\u001a\u00020\u0006X\u0082\u000e¢\u0006\u0002\n\u0000R\u000e\u0010\u0011\u001a\u00020\u0006X\u0082\u000e¢\u0006\u0002\n\u0000R\u000e\u0010\u0012\u001a\u00020\u0006X\u0082\u000e¢\u0006\u0002\n\u0000R\u0017\u0010\u0013\u001a\b\u0012\u0004\u0012\u00020\u00150\u0014X\u0082\u000eø\u0001\u0000¢\u0006\u0002\n\u0000R$\u0010\u0017\u001a\u00020\u00062\u0006\u0010\u0016\u001a\u00020\u0006@FX\u0086\u000e¢\u0006\u000e\n\u0000\u001a\u0004\b\u0018\u0010\b\"\u0004\b\u0019\u0010\u001aR\u0011\u0010\u001b\u001a\u00020\u00068F¢\u0006\u0006\u001a\u0004\b\u001c\u0010\b\u0082\u0002\u0004\n\u0002\b\u0019¨\u0006+"}, d2 = {"Landroidx/compose/foundation/lazy/grid/LazyGridSpanLayoutProvider;", "", "gridContent", "Landroidx/compose/foundation/lazy/grid/LazyGridIntervalContent;", "(Landroidx/compose/foundation/lazy/grid/LazyGridIntervalContent;)V", "bucketSize", "", "getBucketSize", "()I", "buckets", "Ljava/util/ArrayList;", "Landroidx/compose/foundation/lazy/grid/LazyGridSpanLayoutProvider$Bucket;", "Lkotlin/collections/ArrayList;", "cachedBucket", "", "cachedBucketIndex", "lastLineIndex", "lastLineStartItemIndex", "lastLineStartKnownSpan", "previousDefaultSpans", "", "Landroidx/compose/foundation/lazy/grid/GridItemSpan;", "value", "slotsPerLine", "getSlotsPerLine", "setSlotsPerLine", "(I)V", "totalSize", "getTotalSize", "getDefaultSpans", "currentSlotsPerLine", "getLineConfiguration", "Landroidx/compose/foundation/lazy/grid/LazyGridSpanLayoutProvider$LineConfiguration;", "lineIndex", "getLineIndexOfItem", "itemIndex", "invalidateCache", "", "spanOf", "maxSpan", "Bucket", "LazyGridItemSpanScopeImpl", "LineConfiguration", "foundation_release"}, k = 1, mv = {1, 8, 0}, xi = 48) /* loaded from: classes.dex */ public final class LazyGridSpanLayoutProvider { private final ArrayList buckets; private final List cachedBucket; private int cachedBucketIndex; private final LazyGridIntervalContent gridContent; private int lastLineIndex; private int lastLineStartItemIndex; private int lastLineStartKnownSpan; private List previousDefaultSpans; private int slotsPerLine; public final int getSlotsPerLine() { return this.slotsPerLine; } public LazyGridSpanLayoutProvider(LazyGridIntervalContent gridContent) { Intrinsics.checkNotNullParameter(gridContent, "gridContent"); this.gridContent = gridContent; ArrayList arrayList = new ArrayList<>(); int i = 0; arrayList.add(new Bucket(i, i, 2, null)); this.buckets = arrayList; this.cachedBucketIndex = -1; this.cachedBucket = new ArrayList(); this.previousDefaultSpans = CollectionsKt.emptyList(); } /* compiled from: LazyGridSpanLayoutProvider.kt */ @Metadata(d1 = {"\u0000\u001c\n\u0002\u0018\u0002\n\u0002\u0010\u0000\n\u0000\n\u0002\u0010\b\n\u0000\n\u0002\u0010 \n\u0002\u0018\u0002\n\u0002\b\u0006\b\u0007\u0018\u00002\u00020\u0001B\u001e\u0012\u0006\u0010\u0002\u001a\u00020\u0003\u0012\f\u0010\u0004\u001a\b\u0012\u0004\u0012\u00020\u00060\u0005ø\u0001\u0000¢\u0006\u0002\u0010\u0007R\u0011\u0010\u0002\u001a\u00020\u0003¢\u0006\b\n\u0000\u001a\u0004\b\b\u0010\tR\u001a\u0010\u0004\u001a\b\u0012\u0004\u0012\u00020\u00060\u0005ø\u0001\u0000¢\u0006\b\n\u0000\u001a\u0004\b\n\u0010\u000b\u0082\u0002\u0004\n\u0002\b\u0019¨\u0006\f"}, d2 = {"Landroidx/compose/foundation/lazy/grid/LazyGridSpanLayoutProvider$LineConfiguration;", "", "firstItemIndex", "", SentryTransaction.JsonKeys.SPANS, "", "Landroidx/compose/foundation/lazy/grid/GridItemSpan;", "(ILjava/util/List;)V", "getFirstItemIndex", "()I", "getSpans", "()Ljava/util/List;", "foundation_release"}, k = 1, mv = {1, 8, 0}, xi = 48) /* loaded from: classes.dex */ public static final class LineConfiguration { public static final int $stable = 8; private final int firstItemIndex; private final List spans; public final int getFirstItemIndex() { return this.firstItemIndex; } public final List getSpans() { return this.spans; } public LineConfiguration(int i, List spans) { Intrinsics.checkNotNullParameter(spans, "spans"); this.firstItemIndex = i; this.spans = spans; } } private final int getBucketSize() { return ((int) Math.sqrt((getTotalSize() * 1.0d) / this.slotsPerLine)) + 1; } private final List getDefaultSpans(int currentSlotsPerLine) { if (currentSlotsPerLine == this.previousDefaultSpans.size()) { return this.previousDefaultSpans; } ArrayList arrayList = new ArrayList(currentSlotsPerLine); for (int i = 0; i < currentSlotsPerLine; i++) { arrayList.add(GridItemSpan.m605boximpl(LazyGridSpanKt.GridItemSpan(1))); } ArrayList arrayList2 = arrayList; this.previousDefaultSpans = arrayList2; return arrayList2; } public final int getTotalSize() { return this.gridContent.getIntervals().getSize(); } public final void setSlotsPerLine(int i) { if (i != this.slotsPerLine) { this.slotsPerLine = i; invalidateCache(); } } /* JADX WARN: Code restructure failed: missing block: B:14:0x008d, code lost: if (r7 < r6) goto L22; */ /* Code decompiled incorrectly, please refer to instructions dump. To view partially-correct add '--show-bad-code' argument */ public final androidx.compose.foundation.lazy.grid.LazyGridSpanLayoutProvider.LineConfiguration getLineConfiguration(int r11) { /* Method dump skipped, instructions count: 338 To view this dump add '--comments-level debug' option */ throw new UnsupportedOperationException("Method not decompiled: androidx.compose.foundation.lazy.grid.LazyGridSpanLayoutProvider.getLineConfiguration(int):androidx.compose.foundation.lazy.grid.LazyGridSpanLayoutProvider$LineConfiguration"); } public final int getLineIndexOfItem(final int itemIndex) { int i = 0; if (getTotalSize() <= 0) { return 0; } if (itemIndex >= getTotalSize()) { throw new IllegalArgumentException("Failed requirement.".toString()); } if (!this.gridContent.getHasCustomSpans()) { return itemIndex / this.slotsPerLine; } int binarySearch$default = CollectionsKt.binarySearch$default(this.buckets, 0, 0, new Function1() { // from class: androidx.compose.foundation.lazy.grid.LazyGridSpanLayoutProvider$getLineIndexOfItem$lowerBoundBucket$1 /* JADX INFO: Access modifiers changed from: package-private */ /* JADX WARN: 'super' call moved to the top of the method (can break code semantics) */ { super(1); } @Override // kotlin.jvm.functions.Function1 public final Integer invoke(LazyGridSpanLayoutProvider.Bucket it) { Intrinsics.checkNotNullParameter(it, "it"); return Integer.valueOf(it.getFirstItemIndex() - itemIndex); } }, 3, (Object) null); int i2 = 2; if (binarySearch$default < 0) { binarySearch$default = (-binarySearch$default) - 2; } int bucketSize = getBucketSize() * binarySearch$default; int firstItemIndex = this.buckets.get(binarySearch$default).getFirstItemIndex(); if (firstItemIndex > itemIndex) { throw new IllegalArgumentException("Failed requirement.".toString()); } int i3 = 0; while (firstItemIndex < itemIndex) { int i4 = firstItemIndex + 1; int spanOf = spanOf(firstItemIndex, this.slotsPerLine - i3); i3 += spanOf; int i5 = this.slotsPerLine; if (i3 >= i5) { if (i3 == i5) { bucketSize++; i3 = 0; } else { bucketSize++; i3 = spanOf; } } if (bucketSize % getBucketSize() == 0 && bucketSize / getBucketSize() >= this.buckets.size()) { this.buckets.add(new Bucket(i4 - (i3 > 0 ? 1 : 0), i, i2, null)); } firstItemIndex = i4; } return i3 + spanOf(itemIndex, this.slotsPerLine - i3) > this.slotsPerLine ? bucketSize + 1 : bucketSize; } public final int spanOf(int itemIndex, int maxSpan) { LazyGridItemSpanScopeImpl lazyGridItemSpanScopeImpl = LazyGridItemSpanScopeImpl.INSTANCE; lazyGridItemSpanScopeImpl.setMaxCurrentLineSpan(maxSpan); lazyGridItemSpanScopeImpl.setMaxLineSpan(this.slotsPerLine); IntervalList.Interval interval = this.gridContent.getIntervals().get(itemIndex); return GridItemSpan.m609getCurrentLineSpanimpl(interval.getValue().getSpan().invoke(lazyGridItemSpanScopeImpl, Integer.valueOf(itemIndex - interval.getStartIndex())).getPackedValue()); } private final void invalidateCache() { this.buckets.clear(); int i = 0; this.buckets.add(new Bucket(i, i, 2, null)); this.lastLineIndex = 0; this.lastLineStartItemIndex = 0; this.lastLineStartKnownSpan = 0; this.cachedBucketIndex = -1; this.cachedBucket.clear(); } /* JADX INFO: Access modifiers changed from: private */ /* compiled from: LazyGridSpanLayoutProvider.kt */ @Metadata(d1 = {"\u0000\u0012\n\u0002\u0018\u0002\n\u0002\u0010\u0000\n\u0000\n\u0002\u0010\b\n\u0002\b\u0006\b\u0002\u0018\u00002\u00020\u0001B\u0017\u0012\u0006\u0010\u0002\u001a\u00020\u0003\u0012\b\b\u0002\u0010\u0004\u001a\u00020\u0003¢\u0006\u0002\u0010\u0005R\u0011\u0010\u0002\u001a\u00020\u0003¢\u0006\b\n\u0000\u001a\u0004\b\u0006\u0010\u0007R\u0011\u0010\u0004\u001a\u00020\u0003¢\u0006\b\n\u0000\u001a\u0004\b\b\u0010\u0007¨\u0006\t"}, d2 = {"Landroidx/compose/foundation/lazy/grid/LazyGridSpanLayoutProvider$Bucket;", "", "firstItemIndex", "", "firstItemKnownSpan", "(II)V", "getFirstItemIndex", "()I", "getFirstItemKnownSpan", "foundation_release"}, k = 1, mv = {1, 8, 0}, xi = 48) /* loaded from: classes.dex */ public static final class Bucket { private final int firstItemIndex; private final int firstItemKnownSpan; public final int getFirstItemIndex() { return this.firstItemIndex; } public final int getFirstItemKnownSpan() { return this.firstItemKnownSpan; } public Bucket(int i, int i2) { this.firstItemIndex = i; this.firstItemKnownSpan = i2; } public /* synthetic */ Bucket(int i, int i2, int i3, DefaultConstructorMarker defaultConstructorMarker) { this(i, (i3 & 2) != 0 ? 0 : i2); } } /* JADX INFO: Access modifiers changed from: private */ /* compiled from: LazyGridSpanLayoutProvider.kt */ @Metadata(d1 = {"\u0000\u0014\n\u0002\u0018\u0002\n\u0002\u0018\u0002\n\u0002\b\u0002\n\u0002\u0010\b\n\u0002\b\b\bÂ\u0002\u0018\u00002\u00020\u0001B\u0007\b\u0002¢\u0006\u0002\u0010\u0002R\u001a\u0010\u0003\u001a\u00020\u0004X\u0096\u000e¢\u0006\u000e\n\u0000\u001a\u0004\b\u0005\u0010\u0006\"\u0004\b\u0007\u0010\bR\u001a\u0010\t\u001a\u00020\u0004X\u0096\u000e¢\u0006\u000e\n\u0000\u001a\u0004\b\n\u0010\u0006\"\u0004\b\u000b\u0010\b¨\u0006\f"}, d2 = {"Landroidx/compose/foundation/lazy/grid/LazyGridSpanLayoutProvider$LazyGridItemSpanScopeImpl;", "Landroidx/compose/foundation/lazy/grid/LazyGridItemSpanScope;", "()V", "maxCurrentLineSpan", "", "getMaxCurrentLineSpan", "()I", "setMaxCurrentLineSpan", "(I)V", "maxLineSpan", "getMaxLineSpan", "setMaxLineSpan", "foundation_release"}, k = 1, mv = {1, 8, 0}, xi = 48) /* loaded from: classes.dex */ public static final class LazyGridItemSpanScopeImpl implements LazyGridItemSpanScope { public static final LazyGridItemSpanScopeImpl INSTANCE = new LazyGridItemSpanScopeImpl(); private static int maxCurrentLineSpan; private static int maxLineSpan; @Override // androidx.compose.foundation.lazy.grid.LazyGridItemSpanScope public int getMaxCurrentLineSpan() { return maxCurrentLineSpan; } @Override // androidx.compose.foundation.lazy.grid.LazyGridItemSpanScope public int getMaxLineSpan() { return maxLineSpan; } public void setMaxCurrentLineSpan(int i) { maxCurrentLineSpan = i; } public void setMaxLineSpan(int i) { maxLineSpan = i; } private LazyGridItemSpanScopeImpl() { } } }