mirror of
https://github.com/gedoor/legado.git
synced 2024-07-06 23:47:49 +08:00
优化
This commit is contained in:
parent
fc6a35ff6d
commit
3449fd7c86
@ -488,22 +488,14 @@ object ReadBook : CoroutineScope by MainScope() {
|
||||
)
|
||||
val contents = contentProcessor
|
||||
.getContent(book, chapter, content, includeTitle = false)
|
||||
val textChapter = ChapterProvider.getTextChapterAsync(
|
||||
book,
|
||||
chapter,
|
||||
displayTitle,
|
||||
contents,
|
||||
chapterSize,
|
||||
this@ReadBook
|
||||
)
|
||||
val textChapter =
|
||||
ChapterProvider.getTextChapterAsync(chapter, displayTitle, contents, chapterSize)
|
||||
when (val offset = chapter.index - durChapterIndex) {
|
||||
0 -> {
|
||||
curTextChapter?.cancelLayout()
|
||||
curTextChapter?.setProgressListener(null)
|
||||
curTextChapter = textChapter
|
||||
if (textChapter.isCompleted) {
|
||||
if (upContent) callBack?.upContent(offset, resetPageOffset)
|
||||
} else if (resetPageOffset) {
|
||||
if (resetPageOffset) {
|
||||
callBack?.resetPageOffset()
|
||||
}
|
||||
callBack?.upMenuView()
|
||||
@ -516,15 +508,11 @@ object ReadBook : CoroutineScope by MainScope() {
|
||||
prevTextChapter?.cancelLayout()
|
||||
prevTextChapter = textChapter
|
||||
if (upContent) {
|
||||
if (textChapter.isCompleted) {
|
||||
callBack?.upContent(offset, resetPageOffset)
|
||||
} else {
|
||||
textChapter.setProgressListener(object : LayoutProgressListener {
|
||||
override fun onLayoutCompleted() {
|
||||
callBack?.upContent(offset, resetPageOffset)
|
||||
}
|
||||
})
|
||||
}
|
||||
textChapter.setProgressListener(object : LayoutProgressListener {
|
||||
override fun onLayoutCompleted() {
|
||||
callBack?.upContent(offset, resetPageOffset)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
@ -532,22 +520,18 @@ object ReadBook : CoroutineScope by MainScope() {
|
||||
nextTextChapter?.cancelLayout()
|
||||
nextTextChapter = textChapter
|
||||
if (upContent) {
|
||||
if (textChapter.isCompleted) {
|
||||
callBack?.upContent(offset, resetPageOffset)
|
||||
} else {
|
||||
textChapter.setProgressListener(object : LayoutProgressListener {
|
||||
override fun onLayoutPageCompleted(index: Int, page: TextPage) {
|
||||
if (index > 1) {
|
||||
return
|
||||
}
|
||||
callBack?.upContent(offset, resetPageOffset)
|
||||
textChapter.setProgressListener(object : LayoutProgressListener {
|
||||
override fun onLayoutPageCompleted(index: Int, page: TextPage) {
|
||||
if (index > 1) {
|
||||
return
|
||||
}
|
||||
})
|
||||
}
|
||||
callBack?.upContent(offset, resetPageOffset)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
Unit
|
||||
textChapter.createLayout(this@ReadBook, book, contents)
|
||||
}.onError {
|
||||
AppLog.put("ChapterProvider ERROR", it)
|
||||
appCtx.toastOnUi("ChapterProvider ERROR:\n${it.stackTraceStr}")
|
||||
|
@ -288,6 +288,10 @@ class PageView(context: Context) : FrameLayout(context) {
|
||||
binding.contentTextView.setContent(textPage)
|
||||
}
|
||||
|
||||
fun invalidateContentView() {
|
||||
binding.contentTextView.invalidate()
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置无障碍文本
|
||||
*/
|
||||
|
@ -527,7 +527,11 @@ class ReadView(context: Context, attrs: AttributeSet) :
|
||||
curPage.setContentDescription(pageFactory.curPage.text)
|
||||
}
|
||||
if (isScroll && !isAutoPage) {
|
||||
curPage.setContent(pageFactory.curPage, resetPageOffset)
|
||||
if (relativePosition == 0) {
|
||||
curPage.setContent(pageFactory.curPage, resetPageOffset)
|
||||
} else {
|
||||
curPage.invalidateContentView()
|
||||
}
|
||||
} else {
|
||||
when (relativePosition) {
|
||||
-1 -> prevPage.setContent(pageFactory.prevPage)
|
||||
|
@ -32,7 +32,6 @@ 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
|
||||
@ -307,12 +306,10 @@ object ChapterProvider {
|
||||
}
|
||||
|
||||
fun getTextChapterAsync(
|
||||
book: Book,
|
||||
bookChapter: BookChapter,
|
||||
displayTitle: String,
|
||||
bookContent: BookContent,
|
||||
chapterSize: Int,
|
||||
scope: CoroutineScope
|
||||
): TextChapter {
|
||||
|
||||
val textChapter = TextChapter(
|
||||
@ -323,9 +320,7 @@ object ChapterProvider {
|
||||
bookChapter.isVip,
|
||||
bookChapter.isPay,
|
||||
bookContent.effectiveReplaceRules
|
||||
).apply {
|
||||
createLayout(scope, book, bookContent)
|
||||
}
|
||||
)
|
||||
|
||||
return textChapter
|
||||
}
|
||||
|
@ -13,7 +13,6 @@ 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
|
||||
@ -69,7 +68,7 @@ class TextChapterLayout(
|
||||
private val stringBuilder = StringBuilder()
|
||||
|
||||
private var isCompleted = false
|
||||
private var job: Coroutine<*>? = null
|
||||
private val job: Coroutine<*>
|
||||
private val bookChapter inline get() = textChapter.chapter
|
||||
private val displayTitle inline get() = textChapter.title
|
||||
private val chaptersSize inline get() = textChapter.chaptersSize
|
||||
@ -77,19 +76,17 @@ class TextChapterLayout(
|
||||
var exception: Throwable? = null
|
||||
|
||||
init {
|
||||
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
|
||||
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
|
||||
}
|
||||
}
|
||||
|
||||
@ -109,7 +106,7 @@ class TextChapterLayout(
|
||||
}
|
||||
|
||||
fun cancel() {
|
||||
job?.cancel()
|
||||
job.cancel()
|
||||
}
|
||||
|
||||
private fun onPageCompleted() {
|
||||
|
Loading…
Reference in New Issue
Block a user