Use proper coroutine context for ReaderChapter

This commit is contained in:
Syer10
2021-08-29 13:15:11 -04:00
parent 0f89ab2b58
commit d5a6ca5521
2 changed files with 3 additions and 7 deletions

View File

@@ -115,7 +115,6 @@ class ReaderMenuViewModel @Inject constructor(
suspend fun init(mangaId: Long, chapterIndex: Int) {
resetValues()
val chapter = ReaderChapter(
scope.coroutineContext + Dispatchers.Default,
try {
chapterHandler.getChapter(mangaId, chapterIndex)
} catch (e: Exception) {
@@ -136,14 +135,12 @@ class ReaderMenuViewModel @Inject constructor(
val nextChapter = chapters.find { it.index == chapterIndex + 1 }
if (nextChapter != null) {
viewerChapters.nextChapter.value = ReaderChapter(
scope.coroutineContext + Dispatchers.Default,
nextChapter
)
}
val prevChapter = chapters.find { it.index == chapterIndex - 1 }
if (prevChapter != null) {
viewerChapters.prevChapter.value = ReaderChapter(
scope.coroutineContext + Dispatchers.Default,
prevChapter
)
}

View File

@@ -10,16 +10,15 @@ import ca.gosyer.data.models.Chapter
import ca.gosyer.ui.reader.loader.PageLoader
import ca.gosyer.util.system.CKLogger
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.Job
import kotlinx.coroutines.cancel
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.StateFlow
import kotlinx.coroutines.flow.asStateFlow
import kotlin.coroutines.CoroutineContext
data class ReaderChapter(val context: CoroutineContext, val chapter: Chapter) {
var scope = CoroutineScope(context + Job())
private set
data class ReaderChapter(val chapter: Chapter) {
val scope = CoroutineScope(Dispatchers.Default + Job())
var state: State =
State.Wait