Use MainScope for coroutines in ui package classes (#8845)
(cherry picked from commit 920ca405a2116065840c7dd074209d902bfd3419) # Conflicts: # app/src/main/java/eu/kanade/tachiyomi/ui/reader/viewer/pager/PagerPageHolder.kt
This commit is contained in:
parent
c516848843
commit
65c95fbb78
@ -13,15 +13,14 @@ import eu.kanade.tachiyomi.ui.reader.model.ReaderPage
|
|||||||
import eu.kanade.tachiyomi.ui.reader.viewer.ReaderPageImageView
|
import eu.kanade.tachiyomi.ui.reader.viewer.ReaderPageImageView
|
||||||
import eu.kanade.tachiyomi.ui.reader.viewer.ReaderProgressIndicator
|
import eu.kanade.tachiyomi.ui.reader.viewer.ReaderProgressIndicator
|
||||||
import eu.kanade.tachiyomi.ui.webview.WebViewActivity
|
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.ImageUtil
|
||||||
import eu.kanade.tachiyomi.util.system.logcat
|
import eu.kanade.tachiyomi.util.system.logcat
|
||||||
import eu.kanade.tachiyomi.widget.ViewPagerAdapter
|
import eu.kanade.tachiyomi.widget.ViewPagerAdapter
|
||||||
import kotlinx.coroutines.CoroutineScope
|
|
||||||
import kotlinx.coroutines.Dispatchers
|
|
||||||
import kotlinx.coroutines.Job
|
import kotlinx.coroutines.Job
|
||||||
|
import kotlinx.coroutines.MainScope
|
||||||
import kotlinx.coroutines.delay
|
import kotlinx.coroutines.delay
|
||||||
import kotlinx.coroutines.flow.collectLatest
|
import kotlinx.coroutines.flow.collectLatest
|
||||||
|
import kotlinx.coroutines.launch
|
||||||
import logcat.LogPriority
|
import logcat.LogPriority
|
||||||
import rx.Observable
|
import rx.Observable
|
||||||
import rx.Subscription
|
import rx.Subscription
|
||||||
@ -65,7 +64,7 @@ class PagerPageHolder(
|
|||||||
*/
|
*/
|
||||||
private var errorLayout: ReaderErrorBinding? = null
|
private var errorLayout: ReaderErrorBinding? = null
|
||||||
|
|
||||||
private val scope = CoroutineScope(Dispatchers.IO)
|
private val scope = MainScope()
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Subscription for status changes of the page.
|
* Subscription for status changes of the page.
|
||||||
@ -144,7 +143,7 @@ class PagerPageHolder(
|
|||||||
|
|
||||||
private fun launchProgressJob() {
|
private fun launchProgressJob() {
|
||||||
progressJob?.cancel()
|
progressJob?.cancel()
|
||||||
progressJob = scope.launchUI {
|
progressJob = scope.launch {
|
||||||
page.progressFlow.collectLatest { value -> progressIndicator.setProgress(value) }
|
page.progressFlow.collectLatest { value -> progressIndicator.setProgress(value) }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -152,7 +151,7 @@ class PagerPageHolder(
|
|||||||
private fun launchProgressJob2() {
|
private fun launchProgressJob2() {
|
||||||
extraProgressJob?.cancel()
|
extraProgressJob?.cancel()
|
||||||
val extraPage = extraPage ?: return
|
val extraPage = extraPage ?: return
|
||||||
extraProgressJob = scope.launchUI {
|
extraProgressJob = scope.launch {
|
||||||
extraPage.progressFlow.collectLatest { value -> progressIndicator.setProgress(((page.progressFlow.value + value) / 2 * 0.95f).roundToInt()) }
|
extraPage.progressFlow.collectLatest { value -> progressIndicator.setProgress(((page.progressFlow.value + value) / 2 * 0.95f).roundToInt()) }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -379,7 +378,7 @@ class PagerPageHolder(
|
|||||||
logcat(LogPriority.ERROR) { "Cannot combine pages" }
|
logcat(LogPriority.ERROR) { "Cannot combine pages" }
|
||||||
return imageBytes.inputStream()
|
return imageBytes.inputStream()
|
||||||
}
|
}
|
||||||
viewer.scope.launchUI { progressIndicator.setProgress(96) }
|
scope.launch { progressIndicator.setProgress(96) }
|
||||||
val height = imageBitmap.height
|
val height = imageBitmap.height
|
||||||
val width = imageBitmap.width
|
val width = imageBitmap.width
|
||||||
|
|
||||||
@ -407,7 +406,7 @@ class PagerPageHolder(
|
|||||||
logcat(LogPriority.ERROR) { "Cannot combine pages" }
|
logcat(LogPriority.ERROR) { "Cannot combine pages" }
|
||||||
return imageBytes.inputStream()
|
return imageBytes.inputStream()
|
||||||
}
|
}
|
||||||
viewer.scope.launchUI { progressIndicator.setProgress(97) }
|
scope.launch { progressIndicator.setProgress(97) }
|
||||||
val height2 = imageBitmap2.height
|
val height2 = imageBitmap2.height
|
||||||
val width2 = imageBitmap2.width
|
val width2 = imageBitmap2.width
|
||||||
|
|
||||||
@ -431,7 +430,7 @@ class PagerPageHolder(
|
|||||||
}
|
}
|
||||||
|
|
||||||
return ImageUtil.mergeBitmaps(imageBitmap, imageBitmap2, isLTR, centerMargin, viewer.config.pageCanvasColor) {
|
return ImageUtil.mergeBitmaps(imageBitmap, imageBitmap2, isLTR, centerMargin, viewer.config.pageCanvasColor) {
|
||||||
viewer.scope.launchUI {
|
scope.launch {
|
||||||
if (it == 100) {
|
if (it == 100) {
|
||||||
progressIndicator.hide()
|
progressIndicator.hide()
|
||||||
} else {
|
} else {
|
||||||
@ -442,7 +441,7 @@ class PagerPageHolder(
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun splitDoublePages() {
|
private fun splitDoublePages() {
|
||||||
viewer.scope.launchUI {
|
scope.launch {
|
||||||
delay(100)
|
delay(100)
|
||||||
viewer.splitDoublePages(page)
|
viewer.splitDoublePages(page)
|
||||||
if (extraPage?.fullPage == true || page.fullPage) {
|
if (extraPage?.fullPage == true || page.fullPage) {
|
||||||
|
@ -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.model.ReaderChapter
|
||||||
import eu.kanade.tachiyomi.ui.reader.viewer.ReaderButton
|
import eu.kanade.tachiyomi.ui.reader.viewer.ReaderButton
|
||||||
import eu.kanade.tachiyomi.ui.reader.viewer.ReaderTransitionView
|
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.util.system.dpToPx
|
||||||
import eu.kanade.tachiyomi.widget.ViewPagerAdapter
|
import eu.kanade.tachiyomi.widget.ViewPagerAdapter
|
||||||
import kotlinx.coroutines.CoroutineScope
|
|
||||||
import kotlinx.coroutines.Dispatchers
|
|
||||||
import kotlinx.coroutines.Job
|
import kotlinx.coroutines.Job
|
||||||
|
import kotlinx.coroutines.MainScope
|
||||||
import kotlinx.coroutines.flow.collectLatest
|
import kotlinx.coroutines.flow.collectLatest
|
||||||
|
import kotlinx.coroutines.launch
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* View of the ViewPager that contains a chapter transition.
|
* View of the ViewPager that contains a chapter transition.
|
||||||
@ -33,7 +32,7 @@ class PagerTransitionHolder(
|
|||||||
val transition: ChapterTransition,
|
val transition: ChapterTransition,
|
||||||
) : LinearLayout(readerThemedContext), ViewPagerAdapter.PositionableView {
|
) : LinearLayout(readerThemedContext), ViewPagerAdapter.PositionableView {
|
||||||
|
|
||||||
private val scope = CoroutineScope(Dispatchers.IO)
|
private val scope = MainScope()
|
||||||
private var stateJob: Job? = null
|
private var stateJob: Job? = null
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -81,7 +80,7 @@ class PagerTransitionHolder(
|
|||||||
*/
|
*/
|
||||||
private fun observeStatus(chapter: ReaderChapter) {
|
private fun observeStatus(chapter: ReaderChapter) {
|
||||||
stateJob?.cancel()
|
stateJob?.cancel()
|
||||||
stateJob = scope.launchUI {
|
stateJob = scope.launch {
|
||||||
chapter.stateFlow
|
chapter.stateFlow
|
||||||
.collectLatest { state ->
|
.collectLatest { state ->
|
||||||
pagesContainer.removeAllViews()
|
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.ReaderPageImageView
|
||||||
import eu.kanade.tachiyomi.ui.reader.viewer.ReaderProgressIndicator
|
import eu.kanade.tachiyomi.ui.reader.viewer.ReaderProgressIndicator
|
||||||
import eu.kanade.tachiyomi.ui.webview.WebViewActivity
|
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.ImageUtil
|
||||||
import eu.kanade.tachiyomi.util.system.dpToPx
|
import eu.kanade.tachiyomi.util.system.dpToPx
|
||||||
import kotlinx.coroutines.CoroutineScope
|
|
||||||
import kotlinx.coroutines.Dispatchers
|
|
||||||
import kotlinx.coroutines.Job
|
import kotlinx.coroutines.Job
|
||||||
|
import kotlinx.coroutines.MainScope
|
||||||
import kotlinx.coroutines.flow.collectLatest
|
import kotlinx.coroutines.flow.collectLatest
|
||||||
|
import kotlinx.coroutines.launch
|
||||||
import rx.Observable
|
import rx.Observable
|
||||||
import rx.Subscription
|
import rx.Subscription
|
||||||
import rx.android.schedulers.AndroidSchedulers
|
import rx.android.schedulers.AndroidSchedulers
|
||||||
@ -71,7 +70,7 @@ class WebtoonPageHolder(
|
|||||||
*/
|
*/
|
||||||
private var page: ReaderPage? = null
|
private var page: ReaderPage? = null
|
||||||
|
|
||||||
private val scope = CoroutineScope(Dispatchers.IO)
|
private val scope = MainScope()
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Subscription for status changes of the page.
|
* Subscription for status changes of the page.
|
||||||
@ -156,7 +155,7 @@ class WebtoonPageHolder(
|
|||||||
|
|
||||||
val page = page ?: return
|
val page = page ?: return
|
||||||
|
|
||||||
progressJob = scope.launchUI {
|
progressJob = scope.launch {
|
||||||
page.progressFlow.collectLatest { value -> progressIndicator.setProgress(value) }
|
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.ChapterTransition
|
||||||
import eu.kanade.tachiyomi.ui.reader.model.ReaderChapter
|
import eu.kanade.tachiyomi.ui.reader.model.ReaderChapter
|
||||||
import eu.kanade.tachiyomi.ui.reader.viewer.ReaderTransitionView
|
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.util.system.dpToPx
|
||||||
import kotlinx.coroutines.CoroutineScope
|
|
||||||
import kotlinx.coroutines.Dispatchers
|
|
||||||
import kotlinx.coroutines.Job
|
import kotlinx.coroutines.Job
|
||||||
|
import kotlinx.coroutines.MainScope
|
||||||
import kotlinx.coroutines.flow.collectLatest
|
import kotlinx.coroutines.flow.collectLatest
|
||||||
|
import kotlinx.coroutines.launch
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Holder of the webtoon viewer that contains a chapter transition.
|
* Holder of the webtoon viewer that contains a chapter transition.
|
||||||
@ -28,7 +27,7 @@ class WebtoonTransitionHolder(
|
|||||||
viewer: WebtoonViewer,
|
viewer: WebtoonViewer,
|
||||||
) : WebtoonBaseHolder(layout, viewer) {
|
) : WebtoonBaseHolder(layout, viewer) {
|
||||||
|
|
||||||
private val scope = CoroutineScope(Dispatchers.IO)
|
private val scope = MainScope()
|
||||||
private var stateJob: Job? = null
|
private var stateJob: Job? = null
|
||||||
|
|
||||||
private val transitionView = ReaderTransitionView(context)
|
private val transitionView = ReaderTransitionView(context)
|
||||||
@ -82,7 +81,7 @@ class WebtoonTransitionHolder(
|
|||||||
*/
|
*/
|
||||||
private fun observeStatus(chapter: ReaderChapter, transition: ChapterTransition) {
|
private fun observeStatus(chapter: ReaderChapter, transition: ChapterTransition) {
|
||||||
stateJob?.cancel()
|
stateJob?.cancel()
|
||||||
stateJob = scope.launchUI {
|
stateJob = scope.launch {
|
||||||
chapter.stateFlow
|
chapter.stateFlow
|
||||||
.collectLatest { state ->
|
.collectLatest { state ->
|
||||||
pagesContainer.removeAllViews()
|
pagesContainer.removeAllViews()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user