Cleanup DownloadInfoListener callbackFlow

This commit is contained in:
tarsin committed 2023-07-03 20:03:48 +08:00
1 parent dfd9af8ee3
commit 0eb3cc9073
2 files changed
+6 -4

No files matched your search

@@ -39,6 +39,7 @@ import eu.kanade.tachiyomi.util.lang.withUIContext
import kotlinx.coroutines.channels.awaitClose
import kotlinx.coroutines.coroutineScope
import kotlinx.coroutines.flow.callbackFlow
import kotlinx.coroutines.flow.filter
import kotlinx.coroutines.launch
import splitties.init.appCtx
import splitties.preferences.edit
@@ -256,7 +257,7 @@ object DownloadManager : OnSpiderListener {
}
}
val stateFlow = callbackFlow {
private val _stateFlow = callbackFlow {
val listener = object : DownloadInfoListener {
override fun onAdd(info: DownloadInfo, list: List<DownloadInfo>, position: Int) {
trySend(info)
@@ -297,6 +298,8 @@ object DownloadManager : OnSpiderListener {
}
}
fun stateFlow(gid: Long) = _stateFlow.filter { it.gid == gid }
fun startAllDownload() {
var update = false
// Start all STATE_NONE and STATE_FAILED item
@@ -41,7 +41,6 @@ import com.hippo.ehviewer.download.DownloadManager
import com.hippo.ehviewer.ui.tools.CrystalCard
import com.hippo.ehviewer.ui.tools.ElevatedCard
import com.hippo.ehviewer.ui.tools.GalleryListCardRating
import kotlinx.coroutines.flow.collect
@Composable
fun GalleryInfoListItem(
@@ -117,8 +116,8 @@ fun GalleryInfoListItem(
) {
var download by remember(info.gid) { mutableStateOf(DownloadManager.containDownloadInfo(info.gid)) }
LaunchedEffect(info.gid) {
DownloadManager.stateFlow.collect {
if (it.gid == info.gid) download = DownloadManager.containDownloadInfo(info.gid)
DownloadManager.stateFlow(info.gid).collect {
download = DownloadManager.containDownloadInfo(info.gid)
}
}
if (download) {