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

Unset downloadDeleteEvent if we are multi-deleting so we don't end up running update on the lists for every single download

This commit is contained in:
Luna712 2024-07-17 11:43:00 -06:00 committed by GitHub
parent 821f6e3186
commit ca59982d60
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 26 additions and 6 deletions
app/src/main/java/com/lagradost/cloudstream3/ui/download

View file

@ -371,10 +371,10 @@ class DownloadAdapter(
}
}
private fun toggleIsChecked(checkbox: CheckBox, id: Int) {
private fun toggleIsChecked(checkbox: CheckBox, itemId: Int) {
val isChecked = !checkbox.isChecked
checkbox.isChecked = isChecked
onItemSelectionChanged.invoke(id, isChecked)
onItemSelectionChanged.invoke(itemId, isChecked)
}
class DiffCallback : DiffUtil.ItemCallback<VisualDownloadCached>() {

View file

@ -38,8 +38,7 @@ class DownloadChildFragment : Fragment() {
}
override fun onDestroyView() {
downloadDeleteEventListener?.let { VideoDownloadManager.downloadDeleteEvent -= it }
downloadDeleteEventListener = null
unsetDownloadDeleteListener()
detachBackPressedCallback()
binding = null
super.onDestroyView()
@ -171,6 +170,10 @@ class DownloadChildFragment : Fragment() {
}
binding?.btnDelete?.setOnClickListener {
// We want to unset it here if we have it so
// that we don't have to run it for every download,
// we just do it once here.
unsetDownloadDeleteListener()
context?.let { ctx ->
downloadsViewModel.handleMultiDelete(ctx) {
arguments?.getString("folder")
@ -214,4 +217,11 @@ class DownloadChildFragment : Fragment() {
}
downloadDeleteEventListener?.let { VideoDownloadManager.downloadDeleteEvent += it }
}
private fun unsetDownloadDeleteListener() {
downloadDeleteEventListener?.let {
VideoDownloadManager.downloadDeleteEvent -= it
}
downloadDeleteEventListener = null
}
}

View file

@ -68,8 +68,7 @@ class DownloadFragment : Fragment() {
}
override fun onDestroyView() {
downloadDeleteEventListener?.let { VideoDownloadManager.downloadDeleteEvent -= it }
downloadDeleteEventListener = null
unsetDownloadDeleteListener()
detachBackPressedCallback()
binding = null
super.onDestroyView()
@ -254,6 +253,10 @@ class DownloadFragment : Fragment() {
}
binding?.btnDelete?.setOnClickListener {
// We want to unset it here if we have it so
// that we don't have to run it for every download,
// we just do it once here.
unsetDownloadDeleteListener()
context?.let { ctx ->
downloadsViewModel.handleMultiDelete(ctx) {
downloadsViewModel.updateList(ctx)
@ -297,6 +300,13 @@ class DownloadFragment : Fragment() {
downloadDeleteEventListener?.let { VideoDownloadManager.downloadDeleteEvent += it }
}
private fun unsetDownloadDeleteListener() {
downloadDeleteEventListener?.let {
VideoDownloadManager.downloadDeleteEvent -= it
}
downloadDeleteEventListener = null
}
private fun updateStorageInfo(
context: Context,
bytes: Long,