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

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 val isChecked = !checkbox.isChecked
checkbox.isChecked = isChecked checkbox.isChecked = isChecked
onItemSelectionChanged.invoke(id, isChecked) onItemSelectionChanged.invoke(itemId, isChecked)
} }
class DiffCallback : DiffUtil.ItemCallback<VisualDownloadCached>() { class DiffCallback : DiffUtil.ItemCallback<VisualDownloadCached>() {

View file

@ -38,8 +38,7 @@ class DownloadChildFragment : Fragment() {
} }
override fun onDestroyView() { override fun onDestroyView() {
downloadDeleteEventListener?.let { VideoDownloadManager.downloadDeleteEvent -= it } unsetDownloadDeleteListener()
downloadDeleteEventListener = null
detachBackPressedCallback() detachBackPressedCallback()
binding = null binding = null
super.onDestroyView() super.onDestroyView()
@ -171,6 +170,10 @@ class DownloadChildFragment : Fragment() {
} }
binding?.btnDelete?.setOnClickListener { 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 -> context?.let { ctx ->
downloadsViewModel.handleMultiDelete(ctx) { downloadsViewModel.handleMultiDelete(ctx) {
arguments?.getString("folder") arguments?.getString("folder")
@ -214,4 +217,11 @@ class DownloadChildFragment : Fragment() {
} }
downloadDeleteEventListener?.let { VideoDownloadManager.downloadDeleteEvent += it } 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() { override fun onDestroyView() {
downloadDeleteEventListener?.let { VideoDownloadManager.downloadDeleteEvent -= it } unsetDownloadDeleteListener()
downloadDeleteEventListener = null
detachBackPressedCallback() detachBackPressedCallback()
binding = null binding = null
super.onDestroyView() super.onDestroyView()
@ -254,6 +253,10 @@ class DownloadFragment : Fragment() {
} }
binding?.btnDelete?.setOnClickListener { 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 -> context?.let { ctx ->
downloadsViewModel.handleMultiDelete(ctx) { downloadsViewModel.handleMultiDelete(ctx) {
downloadsViewModel.updateList(ctx) downloadsViewModel.updateList(ctx)
@ -297,6 +300,13 @@ class DownloadFragment : Fragment() {
downloadDeleteEventListener?.let { VideoDownloadManager.downloadDeleteEvent += it } downloadDeleteEventListener?.let { VideoDownloadManager.downloadDeleteEvent += it }
} }
private fun unsetDownloadDeleteListener() {
downloadDeleteEventListener?.let {
VideoDownloadManager.downloadDeleteEvent -= it
}
downloadDeleteEventListener = null
}
private fun updateStorageInfo( private fun updateStorageInfo(
context: Context, context: Context,
bytes: Long, bytes: Long,