mirror of
https://github.com/tachiyomiorg/tachiyomi.git
synced 2024-12-21 15:31:49 +01:00
Use MainScope for coroutines in ui package classes (#8845)
This commit is contained in:
parent
6d3a3b3f39
commit
920ca405a2
@ -13,13 +13,12 @@ import eu.kanade.tachiyomi.ui.reader.model.ReaderPage
|
||||
import eu.kanade.tachiyomi.ui.reader.viewer.ReaderPageImageView
|
||||
import eu.kanade.tachiyomi.ui.reader.viewer.ReaderProgressIndicator
|
||||
import eu.kanade.tachiyomi.ui.webview.WebViewActivity
|
||||
import eu.kanade.tachiyomi.util.lang.launchUI
|
||||
import eu.kanade.tachiyomi.util.system.ImageUtil
|
||||
import eu.kanade.tachiyomi.widget.ViewPagerAdapter
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.Job
|
||||
import kotlinx.coroutines.MainScope
|
||||
import kotlinx.coroutines.flow.collectLatest
|
||||
import kotlinx.coroutines.launch
|
||||
import rx.Observable
|
||||
import rx.Subscription
|
||||
import rx.android.schedulers.AndroidSchedulers
|
||||
@ -58,7 +57,7 @@ class PagerPageHolder(
|
||||
*/
|
||||
private var errorLayout: ReaderErrorBinding? = null
|
||||
|
||||
private val scope = CoroutineScope(Dispatchers.IO)
|
||||
private val scope = MainScope()
|
||||
|
||||
/**
|
||||
* Subscription for status changes of the page.
|
||||
@ -108,7 +107,7 @@ class PagerPageHolder(
|
||||
|
||||
private fun launchProgressJob() {
|
||||
progressJob?.cancel()
|
||||
progressJob = scope.launchUI {
|
||||
progressJob = scope.launch {
|
||||
page.progressFlow.collectLatest { value -> progressIndicator.setProgress(value) }
|
||||
}
|
||||
}
|
||||
|
@ -15,13 +15,12 @@ import eu.kanade.tachiyomi.ui.reader.model.ChapterTransition
|
||||
import eu.kanade.tachiyomi.ui.reader.model.ReaderChapter
|
||||
import eu.kanade.tachiyomi.ui.reader.viewer.ReaderButton
|
||||
import eu.kanade.tachiyomi.ui.reader.viewer.ReaderTransitionView
|
||||
import eu.kanade.tachiyomi.util.lang.launchUI
|
||||
import eu.kanade.tachiyomi.util.system.dpToPx
|
||||
import eu.kanade.tachiyomi.widget.ViewPagerAdapter
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.Job
|
||||
import kotlinx.coroutines.MainScope
|
||||
import kotlinx.coroutines.flow.collectLatest
|
||||
import kotlinx.coroutines.launch
|
||||
|
||||
/**
|
||||
* View of the ViewPager that contains a chapter transition.
|
||||
@ -33,7 +32,7 @@ class PagerTransitionHolder(
|
||||
val transition: ChapterTransition,
|
||||
) : LinearLayout(readerThemedContext), ViewPagerAdapter.PositionableView {
|
||||
|
||||
private val scope = CoroutineScope(Dispatchers.IO)
|
||||
private val scope = MainScope()
|
||||
private var stateJob: Job? = null
|
||||
|
||||
/**
|
||||
@ -81,7 +80,7 @@ class PagerTransitionHolder(
|
||||
*/
|
||||
private fun observeStatus(chapter: ReaderChapter) {
|
||||
stateJob?.cancel()
|
||||
stateJob = scope.launchUI {
|
||||
stateJob = scope.launch {
|
||||
chapter.stateFlow
|
||||
.collectLatest { state ->
|
||||
pagesContainer.removeAllViews()
|
||||
|
@ -18,13 +18,12 @@ import eu.kanade.tachiyomi.ui.reader.model.StencilPage
|
||||
import eu.kanade.tachiyomi.ui.reader.viewer.ReaderPageImageView
|
||||
import eu.kanade.tachiyomi.ui.reader.viewer.ReaderProgressIndicator
|
||||
import eu.kanade.tachiyomi.ui.webview.WebViewActivity
|
||||
import eu.kanade.tachiyomi.util.lang.launchUI
|
||||
import eu.kanade.tachiyomi.util.system.ImageUtil
|
||||
import eu.kanade.tachiyomi.util.system.dpToPx
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.Job
|
||||
import kotlinx.coroutines.MainScope
|
||||
import kotlinx.coroutines.flow.collectLatest
|
||||
import kotlinx.coroutines.launch
|
||||
import rx.Observable
|
||||
import rx.Subscription
|
||||
import rx.android.schedulers.AndroidSchedulers
|
||||
@ -71,7 +70,7 @@ class WebtoonPageHolder(
|
||||
*/
|
||||
private var page: ReaderPage? = null
|
||||
|
||||
private val scope = CoroutineScope(Dispatchers.IO)
|
||||
private val scope = MainScope()
|
||||
|
||||
/**
|
||||
* Subscription for status changes of the page.
|
||||
@ -156,7 +155,7 @@ class WebtoonPageHolder(
|
||||
|
||||
val page = page ?: return
|
||||
|
||||
progressJob = scope.launchUI {
|
||||
progressJob = scope.launch {
|
||||
page.progressFlow.collectLatest { value -> progressIndicator.setProgress(value) }
|
||||
}
|
||||
}
|
||||
|
@ -13,12 +13,11 @@ import eu.kanade.tachiyomi.R
|
||||
import eu.kanade.tachiyomi.ui.reader.model.ChapterTransition
|
||||
import eu.kanade.tachiyomi.ui.reader.model.ReaderChapter
|
||||
import eu.kanade.tachiyomi.ui.reader.viewer.ReaderTransitionView
|
||||
import eu.kanade.tachiyomi.util.lang.launchUI
|
||||
import eu.kanade.tachiyomi.util.system.dpToPx
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.Job
|
||||
import kotlinx.coroutines.MainScope
|
||||
import kotlinx.coroutines.flow.collectLatest
|
||||
import kotlinx.coroutines.launch
|
||||
|
||||
/**
|
||||
* Holder of the webtoon viewer that contains a chapter transition.
|
||||
@ -28,7 +27,7 @@ class WebtoonTransitionHolder(
|
||||
viewer: WebtoonViewer,
|
||||
) : WebtoonBaseHolder(layout, viewer) {
|
||||
|
||||
private val scope = CoroutineScope(Dispatchers.IO)
|
||||
private val scope = MainScope()
|
||||
private var stateJob: Job? = null
|
||||
|
||||
private val transitionView = ReaderTransitionView(context)
|
||||
@ -82,7 +81,7 @@ class WebtoonTransitionHolder(
|
||||
*/
|
||||
private fun observeStatus(chapter: ReaderChapter, transition: ChapterTransition) {
|
||||
stateJob?.cancel()
|
||||
stateJob = scope.launchUI {
|
||||
stateJob = scope.launch {
|
||||
chapter.stateFlow
|
||||
.collectLatest { state ->
|
||||
pagesContainer.removeAllViews()
|
||||
|
Loading…
Reference in New Issue
Block a user