From 920ca405a2116065840c7dd074209d902bfd3419 Mon Sep 17 00:00:00 2001 From: Two-Ai <81279822+Two-Ai@users.noreply.github.com> Date: Sat, 7 Jan 2023 10:07:09 -0500 Subject: [PATCH] Use MainScope for coroutines in ui package classes (#8845) --- .../tachiyomi/ui/reader/viewer/pager/PagerPageHolder.kt | 9 ++++----- .../ui/reader/viewer/pager/PagerTransitionHolder.kt | 9 ++++----- .../ui/reader/viewer/webtoon/WebtoonPageHolder.kt | 9 ++++----- .../ui/reader/viewer/webtoon/WebtoonTransitionHolder.kt | 9 ++++----- 4 files changed, 16 insertions(+), 20 deletions(-) diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/viewer/pager/PagerPageHolder.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/viewer/pager/PagerPageHolder.kt index 5d3da4d5e5..e3d44bf83f 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/viewer/pager/PagerPageHolder.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/viewer/pager/PagerPageHolder.kt @@ -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) } } } diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/viewer/pager/PagerTransitionHolder.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/viewer/pager/PagerTransitionHolder.kt index d69ac451d5..d11ef8e4d6 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/viewer/pager/PagerTransitionHolder.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/viewer/pager/PagerTransitionHolder.kt @@ -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() diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/viewer/webtoon/WebtoonPageHolder.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/viewer/webtoon/WebtoonPageHolder.kt index e61810a3d1..908fac4bc4 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/viewer/webtoon/WebtoonPageHolder.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/viewer/webtoon/WebtoonPageHolder.kt @@ -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) } } } diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/viewer/webtoon/WebtoonTransitionHolder.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/viewer/webtoon/WebtoonTransitionHolder.kt index 5dd0b2880f..6ac3c9813d 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/viewer/webtoon/WebtoonTransitionHolder.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/viewer/webtoon/WebtoonTransitionHolder.kt @@ -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()