mirror of
https://github.com/gedoor/legado.git
synced 2024-07-06 23:47:49 +08:00
优化
This commit is contained in:
parent
d4ac63e1b0
commit
16b3efcdb7
@ -16,10 +16,12 @@ import io.legado.app.help.book.BookHelp
|
||||
import io.legado.app.help.book.ContentProcessor
|
||||
import io.legado.app.help.book.isEpub
|
||||
import io.legado.app.help.book.isImage
|
||||
import io.legado.app.help.book.isLocal
|
||||
import io.legado.app.help.book.isPdf
|
||||
import io.legado.app.help.config.AppConfig
|
||||
import io.legado.app.help.config.ReadBookConfig
|
||||
import io.legado.app.model.ReadBook
|
||||
import io.legado.app.model.localBook.LocalBook
|
||||
import io.legado.app.utils.GSON
|
||||
import io.legado.app.utils.MD5Utils
|
||||
import io.legado.app.utils.fromJsonObject
|
||||
@ -286,6 +288,10 @@ data class Book(
|
||||
return appDb.bookSourceDao.getBookSource(origin)
|
||||
}
|
||||
|
||||
fun isLocalModified(): Boolean {
|
||||
return isLocal && LocalBook.getLastModified(this).getOrDefault(0L) > latestChapterTime
|
||||
}
|
||||
|
||||
fun toSearchBook() = SearchBook(
|
||||
name = name,
|
||||
author = author,
|
||||
|
@ -88,7 +88,7 @@ object ReadBook : CoroutineScope by MainScope() {
|
||||
readRecord.readTime = appDb.readRecordDao.getReadTime(book.name) ?: 0
|
||||
chapterSize = appDb.bookChapterDao.getChapterCount(book.bookUrl)
|
||||
contentProcessor = ContentProcessor.get(book)
|
||||
durChapterIndex = book.durChapterIndex
|
||||
durChapterIndex = min(book.durChapterIndex, chapterSize - 1)
|
||||
durChapterPos = book.durChapterPos
|
||||
isLocalBook = book.isLocal
|
||||
clearTextChapter()
|
||||
@ -111,6 +111,15 @@ object ReadBook : CoroutineScope by MainScope() {
|
||||
durChapterPos = book.durChapterPos
|
||||
clearTextChapter()
|
||||
}
|
||||
if (curTextChapter?.isCompleted == false) {
|
||||
curTextChapter = null
|
||||
}
|
||||
if (nextTextChapter?.isCompleted == false) {
|
||||
nextTextChapter = null
|
||||
}
|
||||
if (prevTextChapter?.isCompleted == false) {
|
||||
prevTextChapter = null
|
||||
}
|
||||
callBack?.upMenuView()
|
||||
upWebBook(book)
|
||||
synchronized(this) {
|
||||
@ -369,6 +378,20 @@ object ReadBook : CoroutineScope by MainScope() {
|
||||
loadContent(durChapterIndex - 1, resetPageOffset = resetPageOffset)
|
||||
}
|
||||
|
||||
fun loadOrUpContent() {
|
||||
if (curTextChapter == null) {
|
||||
loadContent(durChapterIndex)
|
||||
} else {
|
||||
callBack?.upContent()
|
||||
}
|
||||
if (nextTextChapter == null) {
|
||||
loadContent(durChapterIndex + 1)
|
||||
}
|
||||
if (prevTextChapter == null) {
|
||||
loadContent(durChapterIndex - 1)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 加载章节内容
|
||||
* @param index 章节序号
|
||||
@ -392,10 +415,9 @@ object ReadBook : CoroutineScope by MainScope() {
|
||||
chapter,
|
||||
it,
|
||||
upContent,
|
||||
resetPageOffset
|
||||
) {
|
||||
success?.invoke()
|
||||
}
|
||||
resetPageOffset,
|
||||
success
|
||||
)
|
||||
} ?: download(
|
||||
downloadScope,
|
||||
chapter,
|
||||
@ -456,9 +478,8 @@ object ReadBook : CoroutineScope by MainScope() {
|
||||
chapter,
|
||||
"加载正文失败\n$msg",
|
||||
resetPageOffset = resetPageOffset,
|
||||
) {
|
||||
success?.invoke()
|
||||
}
|
||||
success = success
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@ -655,6 +676,7 @@ object ReadBook : CoroutineScope by MainScope() {
|
||||
downloadedChapters.clear()
|
||||
downloadFailChapters.clear()
|
||||
ImageProvider.clear()
|
||||
curTextChapter?.cancelLayout()
|
||||
}
|
||||
|
||||
interface CallBack {
|
||||
|
@ -109,21 +109,12 @@ class ReadBookViewModel(application: Application) : BaseViewModel(application) {
|
||||
} else {
|
||||
loadChapterList(book)
|
||||
}
|
||||
} else if (book.isLocal
|
||||
&& LocalBook.getLastModified(book).getOrDefault(0L) > book.latestChapterTime
|
||||
) {
|
||||
} else if (book.isLocalModified()) {
|
||||
loadChapterList(book)
|
||||
} else if (isSameBook) {
|
||||
if (ReadBook.curTextChapter != null) {
|
||||
ReadBook.callBack?.upContent(resetPageOffset = false)
|
||||
} else {
|
||||
ReadBook.loadContent(resetPageOffset = true)
|
||||
}
|
||||
ReadBook.loadOrUpContent()
|
||||
checkLocalBookFileExist(book)
|
||||
} else {
|
||||
if (ReadBook.durChapterIndex > ReadBook.chapterSize - 1) {
|
||||
ReadBook.durChapterIndex = ReadBook.chapterSize - 1
|
||||
}
|
||||
ReadBook.loadContent(resetPageOffset = false)
|
||||
checkLocalBookFileExist(book)
|
||||
}
|
||||
|
@ -288,14 +288,12 @@ data class TextChapter(
|
||||
}
|
||||
|
||||
override fun onLayoutException(e: Throwable) {
|
||||
isCompleted = true
|
||||
listener?.onLayoutException(e)
|
||||
listener = null
|
||||
}
|
||||
|
||||
fun cancelLayout() {
|
||||
layout?.cancel()
|
||||
isCompleted = true
|
||||
listener = null
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user