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