Skip to content

Commit 3718bc5

Browse files
committed
fix: crash when deleting subsequent downloads
1 parent ee9be1f commit 3718bc5

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

app/src/main/java/com/github/libretube/ui/adapters/DownloadsAdapter.kt

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,8 @@ class DownloadsAdapter(
5252

5353
@SuppressLint("SetTextI18n")
5454
override fun onBindViewHolder(holder: DownloadsViewHolder, position: Int) {
55-
val download = getItem(holder.bindingAdapterPosition).download
56-
val items = getItem(holder.bindingAdapterPosition).downloadItems
55+
val downloadWithItems = getItem(holder.bindingAdapterPosition)
56+
val (download, items, _) = downloadWithItems
5757

5858
holder.binding.apply {
5959
fileSize.isVisible = true
@@ -130,7 +130,11 @@ class DownloadsAdapter(
130130
DELETE_DOWNLOAD_REQUEST_KEY,
131131
activity
132132
) { _, _ ->
133-
showDeleteDialog(root.context, position)
133+
// the position might have changed in the meanwhile if an other item was deleted
134+
// apparently [onBindViewHolder] is only retriggered if the item changes, but
135+
// not if the position changes (which would lead to IndexOutOfBounds here)
136+
val realPosition = currentList.indexOf(downloadWithItems)
137+
showDeleteDialog(root.context, realPosition)
134138
}
135139
DownloadOptionsBottomSheet()
136140
.apply {

0 commit comments

Comments
 (0)