3
3
Fork 1
mirror of https://github.com/recloudstream/cloudstream.git synced 2024-08-15 01:53:11 +00:00

Crappy fix

If better ideas to fix this I would love to here them, I hate doing it like this
This commit is contained in:
Luna712 2024-07-07 01:49:23 -06:00 committed by GitHub
parent 0d868da5fc
commit 7b242823dc
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 25 additions and 7 deletions
app/src/main/java/com/lagradost/cloudstream3/ui/download

View file

@ -127,10 +127,18 @@ class DownloadAdapter(
handleChildDownload(card, formattedSize)
} else handleParentDownload(card, formattedSize)
// This is crappy but we disable view recycling for the
// ViewHolder when showDeleteCheckbox is true. This means
// that RecyclerView won't reuse these views when scrolling,
// thereby ensuring that the checkbox states are preserved.
setIsRecyclable(!showDeleteCheckbox)
deleteCheckbox.apply {
isVisible = showDeleteCheckbox
isChecked = selectedIds[card.data.id] == true
setOnCheckedChangeListener(null)
setOnCheckedChangeListener { _, isChecked ->
selectedIds[card.data.id] = isChecked
selectedChangedCallback.invoke(card.data.id, card.data.name, isChecked)
}
}
@ -180,7 +188,9 @@ class DownloadAdapter(
deleteCheckbox.apply {
isVisible = showDeleteCheckbox
isChecked = selectedIds[card.data.id] == true
setOnCheckedChangeListener(null)
setOnCheckedChangeListener { _, isChecked ->
selectedIds[card.data.id] = isChecked
selectedChangedCallback.invoke(card.data.id, card.data.name, isChecked)
}
}
@ -212,7 +222,9 @@ class DownloadAdapter(
deleteCheckbox.apply {
isVisible = showDeleteCheckbox
isChecked = selectedIds[card.data.id] == true
setOnCheckedChangeListener(null)
setOnCheckedChangeListener { _, isChecked ->
selectedIds[card.data.id] = isChecked
selectedChangedCallback.invoke(card.data.id, card.data.name, isChecked)
}
}
@ -265,6 +277,12 @@ class DownloadAdapter(
mediaClickCallback.invoke(DownloadClickEvent(DOWNLOAD_ACTION_PLAY_FILE, data))
}
}
// This is crappy but we disable view recycling for the
// ViewHolder when showDeleteCheckbox is true. This means
// that RecyclerView won't reuse these views when scrolling,
// thereby ensuring that the checkbox states are preserved.
setIsRecyclable(!showDeleteCheckbox)
}
}
@ -294,7 +312,7 @@ class DownloadAdapter(
fun setDeleteCheckboxVisibility(visible: Boolean) {
if (showDeleteCheckbox == visible) return
showDeleteCheckbox = visible
notifyDataSetChanged()
notifyItemRangeChanged(0, itemCount)
}
fun updateSelectedItem(id: Int, isSelected: Boolean) {
@ -316,8 +334,13 @@ class DownloadAdapter(
}
}
@SuppressLint("NotifyDataSetChanged")
fun clearSelectedIds() {
selectedIds.clear()
if (selectedIds.isNotEmpty()) {
selectedIds.clear()
showDeleteCheckbox = false
notifyDataSetChanged()
}
}
class DiffCallback : DiffUtil.ItemCallback<VisualDownloadCached>() {

View file

@ -1,6 +1,5 @@
package com.lagradost.cloudstream3.ui.download
import android.annotation.SuppressLint
import android.app.Activity
import android.app.Dialog
import android.content.ClipboardManager
@ -192,7 +191,6 @@ class DownloadFragment : Fragment() {
}
}
@SuppressLint("NotifyDataSetChanged")
private fun handleSelectedChange(selected: HashMap<Int, String>) {
val adapter = binding?.downloadList?.adapter as? DownloadAdapter
if (selected.isNotEmpty()) {
@ -202,10 +200,7 @@ class DownloadFragment : Fragment() {
context?.let { ctx -> downloadsViewModel.handleMultiDelete(ctx) }
}
binding?.downloadDeleteToolbar?.btnCancel?.setOnClickListener {
adapter?.setDeleteCheckboxVisibility(false)
adapter?.clearSelectedIds()
adapter?.notifyDataSetChanged()
downloadsViewModel.clearSelectedIds()
}