fix: add bounds checks in patch selector

This commit is contained in:
Ax333l 2024-07-02 15:43:06 +02:00
parent 5455cf20ab
commit a12c5c583b
No known key found for this signature in database
GPG key ID: D2B4D85271127D23

View file

@ -285,7 +285,7 @@ fun PatchesSelectorScreen(
ExtendedFloatingActionButton( ExtendedFloatingActionButton(
text = { Text(stringResource(R.string.save)) }, text = { Text(stringResource(R.string.save)) },
icon = { Icon(Icons.Outlined.Save, null) }, icon = { Icon(Icons.Outlined.Save, null) },
expanded = patchLazyListStates[pagerState.currentPage].isScrollingUp, expanded = patchLazyListStates.getOrNull(pagerState.currentPage)?.isScrollingUp ?: true,
onClick = { onClick = {
// TODO: only allow this if all required options have been set. // TODO: only allow this if all required options have been set.
onSave(vm.getCustomSelection(), vm.getOptions()) onSave(vm.getCustomSelection(), vm.getOptions())
@ -325,6 +325,8 @@ fun PatchesSelectorScreen(
state = pagerState, state = pagerState,
userScrollEnabled = true, userScrollEnabled = true,
pageContent = { index -> pageContent = { index ->
// Avoid crashing if the lists have not been fully initialized yet.
if (index > bundles.lastIndex || bundles.size != patchLazyListStates.size) return@HorizontalPager
val bundle = bundles[index] val bundle = bundles[index]
LazyColumnWithScrollbar( LazyColumnWithScrollbar(