mirror of
https://github.com/null2264/yokai.git
synced 2025-06-21 10:44:42 +00:00
chore(recents): Use flow to set refresh state
This commit is contained in:
parent
a2a0a7e79e
commit
2416037615
2 changed files with 15 additions and 10 deletions
|
@ -66,8 +66,10 @@ import kotlinx.coroutines.awaitAll
|
|||
import kotlinx.coroutines.channels.BufferOverflow
|
||||
import kotlinx.coroutines.coroutineScope
|
||||
import kotlinx.coroutines.ensureActive
|
||||
import kotlinx.coroutines.flow.Flow
|
||||
import kotlinx.coroutines.flow.MutableSharedFlow
|
||||
import kotlinx.coroutines.flow.asSharedFlow
|
||||
import kotlinx.coroutines.flow.map
|
||||
import kotlinx.coroutines.launch
|
||||
import kotlinx.coroutines.runBlocking
|
||||
import kotlinx.coroutines.sync.Semaphore
|
||||
|
@ -677,6 +679,12 @@ class LibraryUpdateJob(private val context: Context, workerParams: WorkerParamet
|
|||
WorkManager.getInstance(context).cancelAllWorkByTag(TAG)
|
||||
}
|
||||
|
||||
fun isRunningFlow(context: Context): Flow<Boolean> {
|
||||
return WorkManager.getInstance(context).getWorkInfosByTagFlow(TAG).map { list ->
|
||||
list.any { it.state == WorkInfo.State.RUNNING }
|
||||
}
|
||||
}
|
||||
|
||||
fun isRunning(context: Context): Boolean {
|
||||
val list = WorkManager.getInstance(context).getWorkInfosByTag(TAG).get()
|
||||
return list.any { it.state == WorkInfo.State.RUNNING }
|
||||
|
|
|
@ -87,6 +87,8 @@ import eu.kanade.tachiyomi.util.view.snack
|
|||
import eu.kanade.tachiyomi.util.view.updateGradiantBGRadius
|
||||
import eu.kanade.tachiyomi.util.view.withFadeTransaction
|
||||
import eu.kanade.tachiyomi.widget.LinearLayoutManagerAccurateOffset
|
||||
import kotlinx.coroutines.flow.collectLatest
|
||||
import kotlinx.coroutines.launch
|
||||
import java.util.*
|
||||
import kotlin.math.max
|
||||
|
||||
|
@ -381,7 +383,11 @@ class RecentsController(bundle: Bundle? = null) :
|
|||
}
|
||||
},
|
||||
)
|
||||
binding.swipeRefresh.isRefreshing = LibraryUpdateJob.isRunning(view.context)
|
||||
viewScope.launch {
|
||||
LibraryUpdateJob.isRunningFlow(view.context).collectLatest {
|
||||
binding.swipeRefresh.isRefreshing = it
|
||||
}
|
||||
}
|
||||
binding.swipeRefresh.setOnRefreshListener {
|
||||
if (!LibraryUpdateJob.isRunning(view.context)) {
|
||||
snack?.dismiss()
|
||||
|
@ -401,14 +407,6 @@ class RecentsController(bundle: Bundle? = null) :
|
|||
)
|
||||
}
|
||||
}
|
||||
addCallback(
|
||||
object : BaseTransientBottomBar.BaseCallback<Snackbar>() {
|
||||
override fun onDismissed(transientBottomBar: Snackbar?, event: Int) {
|
||||
super.onDismissed(transientBottomBar, event)
|
||||
binding.swipeRefresh.isRefreshing = LibraryUpdateJob.isRunning(view.context)
|
||||
}
|
||||
},
|
||||
)
|
||||
}
|
||||
LibraryUpdateJob.startNow(view.context)
|
||||
}
|
||||
|
@ -576,7 +574,6 @@ class RecentsController(bundle: Bundle? = null) :
|
|||
}
|
||||
binding.progress.isVisible = false
|
||||
binding.recentsFrameLayout.alpha = 1f
|
||||
binding.swipeRefresh.isRefreshing = LibraryUpdateJob.isRunning(view!!.context)
|
||||
adapter.removeAllScrollableHeaders()
|
||||
adapter.updateDataSet(recents)
|
||||
adapter.onLoadMoreComplete(null)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue