From b8a696b11aac90f5b492e5d042ea9b658d5c80c2 Mon Sep 17 00:00:00 2001 From: Luna712 <142361265+Luna712@users.noreply.github.com> Date: Mon, 10 Jun 2024 13:17:14 -0600 Subject: [PATCH] Use runOnMainThread and cleanup --- .../ui/download/DownloadButtonSetup.kt | 1 - .../cloudstream3/ui/download/DownloadFragment.kt | 16 ++++++++++------ 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/app/src/main/java/com/lagradost/cloudstream3/ui/download/DownloadButtonSetup.kt b/app/src/main/java/com/lagradost/cloudstream3/ui/download/DownloadButtonSetup.kt index d3329272..63a268ed 100644 --- a/app/src/main/java/com/lagradost/cloudstream3/ui/download/DownloadButtonSetup.kt +++ b/app/src/main/java/com/lagradost/cloudstream3/ui/download/DownloadButtonSetup.kt @@ -19,7 +19,6 @@ import com.lagradost.cloudstream3.utils.VideoDownloadHelper import com.lagradost.cloudstream3.utils.VideoDownloadManager object DownloadButtonSetup { - fun handleDownloadClick(click: DownloadClickEvent, deleteCallback: () -> Unit = {}) { val id = click.data.id if (click.data !is VideoDownloadHelper.DownloadEpisodeCached) return diff --git a/app/src/main/java/com/lagradost/cloudstream3/ui/download/DownloadFragment.kt b/app/src/main/java/com/lagradost/cloudstream3/ui/download/DownloadFragment.kt index e8f02472..06152ab4 100644 --- a/app/src/main/java/com/lagradost/cloudstream3/ui/download/DownloadFragment.kt +++ b/app/src/main/java/com/lagradost/cloudstream3/ui/download/DownloadFragment.kt @@ -45,6 +45,7 @@ import com.lagradost.cloudstream3.ui.settings.Globals.TV import com.lagradost.cloudstream3.ui.settings.Globals.isLayout import com.lagradost.cloudstream3.utils.AppUtils.loadResult import com.lagradost.cloudstream3.utils.Coroutines.main +import com.lagradost.cloudstream3.utils.Coroutines.runOnMainThread import com.lagradost.cloudstream3.utils.DOWNLOAD_EPISODE_CACHE import com.lagradost.cloudstream3.utils.DataStore import com.lagradost.cloudstream3.utils.UIHelper.dismissSafe @@ -54,9 +55,6 @@ import com.lagradost.cloudstream3.utils.UIHelper.navigate import com.lagradost.cloudstream3.utils.UIHelper.setAppBarNoScrollFlagsOnTV import com.lagradost.cloudstream3.utils.VideoDownloadHelper import com.lagradost.cloudstream3.utils.VideoDownloadManager -import kotlinx.coroutines.CoroutineScope -import kotlinx.coroutines.Dispatchers -import kotlinx.coroutines.launch import java.net.URI @@ -324,7 +322,10 @@ class SwipeToDeleteCallback(private val adapter: DownloadHeaderAdapter) : ItemTo target: RecyclerView.ViewHolder ): Boolean = false - override fun onSwiped(viewHolder: RecyclerView.ViewHolder, direction: Int) {} + override fun onSwiped( + viewHolder: RecyclerView.ViewHolder, + direction: Int + ) {} private fun handleDelete(viewHolder: RecyclerView.ViewHolder) { if (deleteInitiated) return @@ -333,7 +334,7 @@ class SwipeToDeleteCallback(private val adapter: DownloadHeaderAdapter) : ItemTo val position = viewHolder.bindingAdapterPosition val item = adapter.cardList[position] - CoroutineScope(Dispatchers.Main).launch { + runOnMainThread { item.child?.let { clickEvent -> handleDownloadClick( DownloadClickEvent( @@ -408,7 +409,10 @@ class SwipeToDeleteCallback(private val adapter: DownloadHeaderAdapter) : ItemTo } else super.onChildDraw(c, recyclerView, viewHolder, limitedDX, dY, actionState, isCurrentlyActive) } - override fun clearView(recyclerView: RecyclerView, viewHolder: RecyclerView.ViewHolder) { + override fun clearView( + recyclerView: RecyclerView, + viewHolder: RecyclerView.ViewHolder + ) { super.clearView(recyclerView, viewHolder) deleteInitiated = false }