From ec643ab263d8c22eb74a2f8a726295c5cdc41c76 Mon Sep 17 00:00:00 2001 From: gedoor Date: Sat, 22 May 2021 17:19:04 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/io/legado/app/data/entities/Book.kt | 35 ++++++++++--------- .../app/ui/book/info/BookInfoViewModel.kt | 2 +- .../app/ui/book/read/ReadBookViewModel.kt | 2 +- .../io/legado/app/ui/book/toc/TocViewModel.kt | 13 ++++--- 4 files changed, 28 insertions(+), 24 deletions(-) diff --git a/app/src/main/java/io/legado/app/data/entities/Book.kt b/app/src/main/java/io/legado/app/data/entities/Book.kt index 2ee782122..240af5e9a 100644 --- a/app/src/main/java/io/legado/app/data/entities/Book.kt +++ b/app/src/main/java/io/legado/app/data/entities/Book.kt @@ -124,6 +124,14 @@ data class Book( return readConfig!! } + fun setReverseToc(reverseToc: Boolean) { + config().reverseToc = reverseToc + } + + fun getReverseToc(): Boolean { + return config().reverseToc + } + fun setUseReplaceRule(useReplaceRule: Boolean) { config().useReplaceRule = useReplaceRule } @@ -156,14 +164,6 @@ data class Book( config().imageStyle = imageStyle } - fun getDelParagraph(): Int { - return config().delParagraph - } - - fun setDelParagraph(num: Int) { - config().delParagraph = num - } - fun setDelTag(tag: Long) { config().delTag = if ((config().delTag and tag) == tag) config().delTag and tag.inv() else config().delTag or tag @@ -208,17 +208,10 @@ data class Book( newBook.customTag = customTag newBook.canUpdate = canUpdate newBook.readConfig = readConfig - delete() + delete(this) appDb.bookDao.insert(newBook) } - fun delete() { - if (ReadBook.book?.bookUrl == bookUrl) { - ReadBook.book = null - } - appDb.bookDao.delete(this) - } - fun upInfoFromOld(oldBook: Book?) { oldBook?.let { group = oldBook.group @@ -241,15 +234,23 @@ data class Book( const val imgStyleDefault = "DEFAULT" const val imgStyleFull = "FULL" const val imgStyleText = "TEXT" + + fun delete(book: Book?) { + book ?: return + if (ReadBook.book?.bookUrl == book.bookUrl) { + ReadBook.book = null + } + appDb.bookDao.delete(book) + } } @Parcelize data class ReadConfig( + var reverseToc: Boolean = false, var pageAnim: Int = -1, var reSegment: Boolean = false, var imageStyle: String? = null, var useReplaceRule: Boolean = AppConfig.replaceEnableDefault,// 正文使用净化替换规则 - var delParagraph: Int = 0,//去除段首 var delTag: Long = 0L,//去除标签 ) : Parcelable diff --git a/app/src/main/java/io/legado/app/ui/book/info/BookInfoViewModel.kt b/app/src/main/java/io/legado/app/ui/book/info/BookInfoViewModel.kt index 39c09fc69..f6fb03b3b 100644 --- a/app/src/main/java/io/legado/app/ui/book/info/BookInfoViewModel.kt +++ b/app/src/main/java/io/legado/app/ui/book/info/BookInfoViewModel.kt @@ -235,7 +235,7 @@ class BookInfoViewModel(application: Application) : BaseViewModel(application) { fun delBook(deleteOriginal: Boolean = false, success: (() -> Unit)? = null) { execute { bookData.value?.let { - it.delete() + Book.delete(it) inBookshelf = false if (it.isLocalBook()) { LocalBook.deleteBook(it, deleteOriginal) diff --git a/app/src/main/java/io/legado/app/ui/book/read/ReadBookViewModel.kt b/app/src/main/java/io/legado/app/ui/book/read/ReadBookViewModel.kt index b91edd0e6..2b6057acd 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/ReadBookViewModel.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/ReadBookViewModel.kt @@ -262,7 +262,7 @@ class ReadBookViewModel(application: Application) : BaseViewModel(application) { fun removeFromBookshelf(success: (() -> Unit)?) { execute { - ReadBook.book?.delete() + Book.delete(ReadBook.book) }.onSuccess { success?.invoke() } diff --git a/app/src/main/java/io/legado/app/ui/book/toc/TocViewModel.kt b/app/src/main/java/io/legado/app/ui/book/toc/TocViewModel.kt index f56c68ff3..cb0f8d708 100644 --- a/app/src/main/java/io/legado/app/ui/book/toc/TocViewModel.kt +++ b/app/src/main/java/io/legado/app/ui/book/toc/TocViewModel.kt @@ -24,12 +24,15 @@ class TocViewModel(application: Application) : BaseViewModel(application) { fun reverseToc() { execute { - val toc = appDb.bookChapterDao.getChapterList(bookUrl) - val newToc = toc.reversed() - newToc.forEachIndexed { index, bookChapter -> - bookChapter.index = index + bookData.value?.let { + it.setReverseToc(it.getReverseToc()) + val toc = appDb.bookChapterDao.getChapterList(bookUrl) + val newToc = toc.reversed() + newToc.forEachIndexed { index, bookChapter -> + bookChapter.index = index + } + appDb.bookChapterDao.insert(*newToc.toTypedArray()) } - appDb.bookChapterDao.insert(*newToc.toTypedArray()) } }