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. 3
      app/src/main/java/io/legado/app/ui/book/toc/TocViewModel.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

@ -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)

@ -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()
}

@ -24,6 +24,8 @@ class TocViewModel(application: Application) : BaseViewModel(application) {
fun reverseToc() {
execute {
bookData.value?.let {
it.setReverseToc(it.getReverseToc())
val toc = appDb.bookChapterDao.getChapterList(bookUrl)
val newToc = toc.reversed()
newToc.forEachIndexed { index, bookChapter ->
@ -32,6 +34,7 @@ class TocViewModel(application: Application) : BaseViewModel(application) {
appDb.bookChapterDao.insert(*newToc.toTypedArray())
}
}
}
fun startChapterListSearch(newText: String?) {
chapterCallBack?.startChapterListSearch(newText)

Loading…
Cancel
Save