pull/1006/head
gedoor 4 years ago
parent 229e37acc3
commit ec643ab263
  1. 35
      app/src/main/java/io/legado/app/data/entities/Book.kt
  2. 2
      app/src/main/java/io/legado/app/ui/book/info/BookInfoViewModel.kt
  3. 2
      app/src/main/java/io/legado/app/ui/book/read/ReadBookViewModel.kt
  4. 13
      app/src/main/java/io/legado/app/ui/book/toc/TocViewModel.kt

@ -124,6 +124,14 @@ data class Book(
return readConfig!! return readConfig!!
} }
fun setReverseToc(reverseToc: Boolean) {
config().reverseToc = reverseToc
}
fun getReverseToc(): Boolean {
return config().reverseToc
}
fun setUseReplaceRule(useReplaceRule: Boolean) { fun setUseReplaceRule(useReplaceRule: Boolean) {
config().useReplaceRule = useReplaceRule config().useReplaceRule = useReplaceRule
} }
@ -156,14 +164,6 @@ data class Book(
config().imageStyle = imageStyle config().imageStyle = imageStyle
} }
fun getDelParagraph(): Int {
return config().delParagraph
}
fun setDelParagraph(num: Int) {
config().delParagraph = num
}
fun setDelTag(tag: Long) { fun setDelTag(tag: Long) {
config().delTag = config().delTag =
if ((config().delTag and tag) == tag) config().delTag and tag.inv() else config().delTag or tag 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.customTag = customTag
newBook.canUpdate = canUpdate newBook.canUpdate = canUpdate
newBook.readConfig = readConfig newBook.readConfig = readConfig
delete() delete(this)
appDb.bookDao.insert(newBook) appDb.bookDao.insert(newBook)
} }
fun delete() {
if (ReadBook.book?.bookUrl == bookUrl) {
ReadBook.book = null
}
appDb.bookDao.delete(this)
}
fun upInfoFromOld(oldBook: Book?) { fun upInfoFromOld(oldBook: Book?) {
oldBook?.let { oldBook?.let {
group = oldBook.group group = oldBook.group
@ -241,15 +234,23 @@ data class Book(
const val imgStyleDefault = "DEFAULT" const val imgStyleDefault = "DEFAULT"
const val imgStyleFull = "FULL" const val imgStyleFull = "FULL"
const val imgStyleText = "TEXT" const val imgStyleText = "TEXT"
fun delete(book: Book?) {
book ?: return
if (ReadBook.book?.bookUrl == book.bookUrl) {
ReadBook.book = null
}
appDb.bookDao.delete(book)
}
} }
@Parcelize @Parcelize
data class ReadConfig( data class ReadConfig(
var reverseToc: Boolean = false,
var pageAnim: Int = -1, var pageAnim: Int = -1,
var reSegment: Boolean = false, var reSegment: Boolean = false,
var imageStyle: String? = null, var imageStyle: String? = null,
var useReplaceRule: Boolean = AppConfig.replaceEnableDefault,// 正文使用净化替换规则 var useReplaceRule: Boolean = AppConfig.replaceEnableDefault,// 正文使用净化替换规则
var delParagraph: Int = 0,//去除段首
var delTag: Long = 0L,//去除标签 var delTag: Long = 0L,//去除标签
) : Parcelable ) : Parcelable

@ -235,7 +235,7 @@ class BookInfoViewModel(application: Application) : BaseViewModel(application) {
fun delBook(deleteOriginal: Boolean = false, success: (() -> Unit)? = null) { fun delBook(deleteOriginal: Boolean = false, success: (() -> Unit)? = null) {
execute { execute {
bookData.value?.let { bookData.value?.let {
it.delete() Book.delete(it)
inBookshelf = false inBookshelf = false
if (it.isLocalBook()) { if (it.isLocalBook()) {
LocalBook.deleteBook(it, deleteOriginal) LocalBook.deleteBook(it, deleteOriginal)

@ -262,7 +262,7 @@ class ReadBookViewModel(application: Application) : BaseViewModel(application) {
fun removeFromBookshelf(success: (() -> Unit)?) { fun removeFromBookshelf(success: (() -> Unit)?) {
execute { execute {
ReadBook.book?.delete() Book.delete(ReadBook.book)
}.onSuccess { }.onSuccess {
success?.invoke() success?.invoke()
} }

@ -24,12 +24,15 @@ class TocViewModel(application: Application) : BaseViewModel(application) {
fun reverseToc() { fun reverseToc() {
execute { execute {
val toc = appDb.bookChapterDao.getChapterList(bookUrl) bookData.value?.let {
val newToc = toc.reversed() it.setReverseToc(it.getReverseToc())
newToc.forEachIndexed { index, bookChapter -> val toc = appDb.bookChapterDao.getChapterList(bookUrl)
bookChapter.index = index val newToc = toc.reversed()
newToc.forEachIndexed { index, bookChapter ->
bookChapter.index = index
}
appDb.bookChapterDao.insert(*newToc.toTypedArray())
} }
appDb.bookChapterDao.insert(*newToc.toTypedArray())
} }
} }

Loading…
Cancel
Save