This commit is contained in:
Horis 2024-02-22 13:05:38 +08:00
parent ea47a24737
commit fc6a35ff6d

View File

@ -13,6 +13,7 @@ import io.legado.app.help.book.BookHelp
import io.legado.app.help.config.AppConfig
import io.legado.app.help.config.ReadBookConfig
import io.legado.app.help.coroutine.Coroutine
import io.legado.app.help.globalExecutor
import io.legado.app.model.ImageProvider
import io.legado.app.model.ReadBook
import io.legado.app.ui.book.read.page.entities.TextChapter
@ -68,7 +69,7 @@ class TextChapterLayout(
private val stringBuilder = StringBuilder()
private var isCompleted = false
private val job: Coroutine<*>
private var job: Coroutine<*>? = null
private val bookChapter inline get() = textChapter.chapter
private val displayTitle inline get() = textChapter.title
private val chaptersSize inline get() = textChapter.chaptersSize
@ -76,17 +77,19 @@ class TextChapterLayout(
var exception: Throwable? = null
init {
job = Coroutine.async(scope) {
launch {
val bookSource = book.getBookSource() ?: return@launch
BookHelp.saveImages(bookSource, book, bookChapter, bookContent.toString())
globalExecutor.submit {
job = Coroutine.async(scope) {
launch {
val bookSource = book.getBookSource() ?: return@launch
BookHelp.saveImages(bookSource, book, bookChapter, bookContent.toString())
}
getTextChapter(book, bookChapter, displayTitle, bookContent)
}.onError {
exception = it
onException(it)
}.onFinally {
isCompleted = true
}
getTextChapter(book, bookChapter, displayTitle, bookContent)
}.onError {
exception = it
onException(it)
}.onFinally {
isCompleted = true
}
}
@ -106,7 +109,7 @@ class TextChapterLayout(
}
fun cancel() {
job.cancel()
job?.cancel()
}
private fun onPageCompleted() {