This commit is contained in:
Horis
2024-02-22 13:05:38 +08:00
parent 557c32c834
commit aabeef4e27
@@ -13,6 +13,7 @@ import io.legado.app.help.book.BookHelp
import io.legado.app.help.config.AppConfig import io.legado.app.help.config.AppConfig
import io.legado.app.help.config.ReadBookConfig import io.legado.app.help.config.ReadBookConfig
import io.legado.app.help.coroutine.Coroutine import io.legado.app.help.coroutine.Coroutine
import io.legado.app.help.globalExecutor
import io.legado.app.model.ImageProvider import io.legado.app.model.ImageProvider
import io.legado.app.model.ReadBook import io.legado.app.model.ReadBook
import io.legado.app.ui.book.read.page.entities.TextChapter import io.legado.app.ui.book.read.page.entities.TextChapter
@@ -68,7 +69,7 @@ class TextChapterLayout(
private val stringBuilder = StringBuilder() private val stringBuilder = StringBuilder()
private var isCompleted = false private var isCompleted = false
private val job: Coroutine<*> private var job: Coroutine<*>? = null
private val bookChapter inline get() = textChapter.chapter private val bookChapter inline get() = textChapter.chapter
private val displayTitle inline get() = textChapter.title private val displayTitle inline get() = textChapter.title
private val chaptersSize inline get() = textChapter.chaptersSize private val chaptersSize inline get() = textChapter.chaptersSize
@@ -76,17 +77,19 @@ class TextChapterLayout(
var exception: Throwable? = null var exception: Throwable? = null
init { init {
job = Coroutine.async(scope) { globalExecutor.submit {
launch { job = Coroutine.async(scope) {
val bookSource = book.getBookSource() ?: return@launch launch {
BookHelp.saveImages(bookSource, book, bookChapter, bookContent.toString()) 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() { fun cancel() {
job.cancel() job?.cancel()
} }
private fun onPageCompleted() { private fun onPageCompleted() {