pull/274/head
gedoor 4 years ago
parent 99b9a59129
commit 12be963d76
  1. 10
      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. 4
      app/src/main/java/io/legado/app/ui/book/read/ReadBookViewModel.kt

@ -8,6 +8,7 @@ import androidx.room.PrimaryKey
import io.legado.app.App import io.legado.app.App
import io.legado.app.constant.AppPattern import io.legado.app.constant.AppPattern
import io.legado.app.constant.BookType import io.legado.app.constant.BookType
import io.legado.app.service.help.ReadBook
import io.legado.app.utils.GSON import io.legado.app.utils.GSON
import io.legado.app.utils.fromJsonObject import io.legado.app.utils.fromJsonObject
import kotlinx.android.parcel.IgnoredOnParcel import kotlinx.android.parcel.IgnoredOnParcel
@ -142,7 +143,14 @@ data class Book(
newBook.customIntro = customIntro newBook.customIntro = customIntro
newBook.customTag = customTag newBook.customTag = customTag
newBook.canUpdate = canUpdate newBook.canUpdate = canUpdate
App.db.bookDao().delete(this) delete()
App.db.bookDao().insert(newBook) App.db.bookDao().insert(newBook)
} }
fun delete() {
if (ReadBook.book?.bookUrl == bookUrl) {
ReadBook.book = null
}
App.db.bookDao().delete(this)
}
} }

@ -216,7 +216,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 {
App.db.bookDao().delete(it) it.delete()
inBookshelf = false inBookshelf = false
if (it.isLocalBook()) { if (it.isLocalBook()) {
LocalBook.deleteBook(it, deleteOriginal) LocalBook.deleteBook(it, deleteOriginal)

@ -222,9 +222,7 @@ class ReadBookViewModel(application: Application) : BaseViewModel(application) {
fun removeFromBookshelf(success: (() -> Unit)?) { fun removeFromBookshelf(success: (() -> Unit)?) {
execute { execute {
ReadBook.book?.let { ReadBook.book?.delete()
App.db.bookDao().delete(it)
}
}.onSuccess { }.onSuccess {
success?.invoke() success?.invoke()
} }

Loading…
Cancel
Save