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:
parent
0d868da5fc
commit
7b242823dc
2 changed files with 25 additions and 7 deletions
app/src/main/java/com/lagradost/cloudstream3/ui/download
|
@ -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>() {
|
||||
|
|
|
@ -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()
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue