mirror of
https://github.com/gedoor/legado.git
synced 2024-07-04 23:36:56 +08:00
优化
This commit is contained in:
parent
03f8437270
commit
7d978ebd6e
|
@ -35,6 +35,8 @@ data class TextChapter(
|
|||
|
||||
private var layout: TextChapterLayout? = null
|
||||
|
||||
val layoutChannel get() = layout!!.channel
|
||||
|
||||
fun getPage(index: Int): TextPage? {
|
||||
return pages.getOrNull(index)
|
||||
}
|
||||
|
|
|
@ -32,6 +32,7 @@ import io.legado.app.utils.postEvent
|
|||
import io.legado.app.utils.spToPx
|
||||
import io.legado.app.utils.splitNotBlank
|
||||
import io.legado.app.utils.textHeight
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
import splitties.init.appCtx
|
||||
import java.util.LinkedList
|
||||
import java.util.Locale
|
||||
|
@ -306,6 +307,8 @@ object ChapterProvider {
|
|||
}
|
||||
|
||||
fun getTextChapterAsync(
|
||||
scope: CoroutineScope,
|
||||
book: Book,
|
||||
bookChapter: BookChapter,
|
||||
displayTitle: String,
|
||||
bookContent: BookContent,
|
||||
|
@ -320,7 +323,9 @@ object ChapterProvider {
|
|||
bookChapter.isVip,
|
||||
bookChapter.isPay,
|
||||
bookContent.effectiveReplaceRules
|
||||
)
|
||||
).apply {
|
||||
createLayout(scope, book, bookContent)
|
||||
}
|
||||
|
||||
return textChapter
|
||||
}
|
||||
|
|
|
@ -26,6 +26,7 @@ import io.legado.app.utils.fastSum
|
|||
import io.legado.app.utils.splitNotBlank
|
||||
import kotlinx.coroutines.CancellationException
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
import kotlinx.coroutines.channels.Channel
|
||||
import kotlinx.coroutines.ensureActive
|
||||
import kotlinx.coroutines.launch
|
||||
import java.util.LinkedList
|
||||
|
@ -78,6 +79,8 @@ class TextChapterLayout(
|
|||
|
||||
var exception: Throwable? = null
|
||||
|
||||
var channel = Channel<TextPage>(Int.MAX_VALUE)
|
||||
|
||||
init {
|
||||
job = Coroutine.async(scope) {
|
||||
launch {
|
||||
|
@ -124,6 +127,7 @@ class TextChapterLayout(
|
|||
textPage.isCompleted = true
|
||||
textPage.textChapter = textChapter
|
||||
textPage.upLinesPosition()
|
||||
channel.trySend(textPage)
|
||||
try {
|
||||
listener?.onLayoutPageCompleted(textPages.lastIndex, textPage)
|
||||
} catch (e: Exception) {
|
||||
|
@ -133,6 +137,7 @@ class TextChapterLayout(
|
|||
}
|
||||
|
||||
private fun onCompleted() {
|
||||
channel.close()
|
||||
try {
|
||||
listener?.onLayoutCompleted()
|
||||
} catch (e: Exception) {
|
||||
|
@ -144,6 +149,7 @@ class TextChapterLayout(
|
|||
}
|
||||
|
||||
private fun onException(e: Throwable) {
|
||||
channel.close(e)
|
||||
if (e is CancellationException) {
|
||||
listener = null
|
||||
return
|
||||
|
|
Loading…
Reference in New Issue
Block a user