优化
Some checks failed
Test Build / prepare (push) Has been cancelled
Test Build / build (app, release) (push) Has been cancelled
Test Build / build (app, releaseA) (push) Has been cancelled
Test Build / prerelease (push) Has been cancelled
Test Build / lanzou (push) Has been cancelled
Test Build / test_Branch (push) Has been cancelled
Test Build / telegram (push) Has been cancelled
update fork / build (push) Has been cancelled

This commit is contained in:
Horis
2025-05-24 11:53:29 +08:00
parent d46249be0d
commit 3baaf6ecfd
5 changed files with 18 additions and 9 deletions

View File

@@ -245,6 +245,8 @@ object LocalBook {
} else {
deleteBook(book, false)
upBookInfo(book)
// 触发 isLocalModified
book.latestChapterTime = 0
//已有书籍说明是更新,删除原有目录
appDb.bookChapterDao.delByBook(bookUrl)
}

View File

@@ -76,16 +76,17 @@ class TextFile(private var book: Book) {
*/
@Throws(FileNotFoundException::class, SecurityException::class, EmptyFileException::class)
fun getChapterList(): ArrayList<BookChapter> {
if (book.charset == null || book.tocUrl.isBlank()) {
val modified = book.isLocalModified()
if (book.charset == null || book.tocUrl.isBlank() || modified) {
LocalBook.getBookInputStream(book).use { bis ->
val buffer = ByteArray(bufferSize)
val length = bis.read(buffer)
if (length == -1) throw EmptyFileException("Unexpected Empty Txt File")
if (book.charset.isNullOrBlank()) {
if (book.charset.isNullOrBlank() || modified) {
book.charset = EncodingDetect.getEncode(buffer.copyOf(length))
}
charset = book.fileCharset()
if (book.tocUrl.isBlank()) {
if (book.tocUrl.isBlank() || modified) {
val blockContent = String(buffer, 0, length, charset)
book.tocUrl = getTocRule(blockContent)?.pattern() ?: ""
}
@@ -223,7 +224,7 @@ class TextFile(private var book: Book) {
*/
if (toc.isEmpty()) { //如果当前没有章节,那么就是序章
//加入简介
if (StringUtils.trim(chapterContent).isNotEmpty()) {
if (chapterContent.isNotBlank()) {
val qyChapter = BookChapter()
qyChapter.title = "前言"
qyChapter.start = curOffset

View File

@@ -195,9 +195,11 @@ class TocActivity : VMBaseActivity<ActivityChapterListBinding, TocViewModel>(),
waitDialog.show()
viewModel.upBookTocRule(book) {
waitDialog.dismiss()
ReadBook.book?.let { readBook ->
if (readBook == book) {
if (ReadBook.book == book) {
if (it == null) {
ReadBook.upMsg(null)
} else {
ReadBook.upMsg("LoadTocError:${it.localizedMessage}")
}
}
}

View File

@@ -35,7 +35,7 @@ class TocViewModel(application: Application) : BaseViewModel(application) {
}
}
fun upBookTocRule(book: Book, finally: () -> Unit) {
fun upBookTocRule(book: Book, complete: (Throwable?) -> Unit) {
execute {
appDb.bookDao.update(book)
LocalBook.getChapterList(book).let {
@@ -45,8 +45,10 @@ class TocViewModel(application: Application) : BaseViewModel(application) {
ReadBook.onChapterListUpdated(book)
bookData.postValue(book)
}
}.onFinally {
finally.invoke()
}.onSuccess {
complete.invoke(null)
}.onError {
complete.invoke(it)
}
}

View File

@@ -55,6 +55,7 @@ object RhinoClassShutter : ClassShutter {
"java.lang.ProcessImpl",
"java.lang.UNIXProcess",
"java.io.File",
"java.io.FileDescriptor",
"java.io.FileInputStream",
"java.io.FileOutputStream",
"java.io.PrintStream",
@@ -113,6 +114,7 @@ object RhinoClassShutter : ClassShutter {
"com.script",
"org.mozilla",
"sun",
"libcore",
).let { ClassNameMatcher(it) }
}