Skip to content

Commit

Permalink
Gallery: Fix ArrayIndexOutOfBoundsException in MediaView
Browse files Browse the repository at this point in the history
Make sure we never reach for a previously deleted index from list

Signed-off-by: IacobIonut01 <paulionut2003@gmail.com>
  • Loading branch information
IacobIonut01 committed Aug 8, 2023
1 parent afb1755 commit ee61c60
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ fun MediaViewScreen(
if (state.media.isNotEmpty()) {
val index = if (page == -1) 0 else page
if (lastIndex.value != -1)
runtimeMediaId = state.media[lastIndex.value].id
runtimeMediaId = state.media[lastIndex.value.coerceAtMost(state.media.size - 1)].id
currentDate.value = state.media[index].timestamp.getDate(HEADER_DATE_FORMAT)
currentMedia.value = state.media[index]
} else if (!isStandalone) navigateUp()
Expand Down Expand Up @@ -131,7 +131,7 @@ fun MediaViewScreen(
durationMillis = DEFAULT_LOW_VELOCITY_SWIPE_DURATION
)
),
key = { index -> state.media[index].toString() },
key = { index -> state.media[index.coerceAtMost(state.media.size - 1)].toString() },
pageSpacing = 16.dp,
) { index ->
MediaPreviewComponent(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,9 @@ fun BoxScope.TrashedViewBottomBar(
title = stringResource(id = R.string.trash_restore)
) {
scope.launch {
onDeleteMedia.invoke(currentIndex)
handler.trashMedia(result = result, arrayListOf(it), trash = false)
}
onDeleteMedia.invoke(currentIndex)
}
Spacer(modifier = Modifier.size(8.dp))
// Delete Component
Expand All @@ -89,9 +89,9 @@ fun BoxScope.TrashedViewBottomBar(
title = stringResource(id = R.string.trash_delete)
) {
scope.launch {
onDeleteMedia.invoke(currentIndex)
handler.deleteMedia(result = result, arrayListOf(it))
}
onDeleteMedia.invoke(currentIndex)
}
}
}
Expand Down

0 comments on commit ee61c60

Please sign in to comment.