From 12be963d76537650385f8846fec3f32cdaddfdc5 Mon Sep 17 00:00:00 2001 From: gedoor Date: Mon, 13 Jul 2020 09:24:16 +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 --- app/src/main/java/io/legado/app/data/entities/Book.kt | 10 +++++++++- .../io/legado/app/ui/book/info/BookInfoViewModel.kt | 2 +- .../io/legado/app/ui/book/read/ReadBookViewModel.kt | 4 +--- 3 files changed, 11 insertions(+), 5 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 7a48d5519..db9f06777 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 @@ -8,6 +8,7 @@ import androidx.room.PrimaryKey import io.legado.app.App import io.legado.app.constant.AppPattern import io.legado.app.constant.BookType +import io.legado.app.service.help.ReadBook import io.legado.app.utils.GSON import io.legado.app.utils.fromJsonObject import kotlinx.android.parcel.IgnoredOnParcel @@ -142,7 +143,14 @@ data class Book( newBook.customIntro = customIntro newBook.customTag = customTag newBook.canUpdate = canUpdate - App.db.bookDao().delete(this) + delete() App.db.bookDao().insert(newBook) } + + fun delete() { + if (ReadBook.book?.bookUrl == bookUrl) { + ReadBook.book = null + } + App.db.bookDao().delete(this) + } } \ No newline at end of file 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 800024cf5..3a36170e4 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 @@ -216,7 +216,7 @@ class BookInfoViewModel(application: Application) : BaseViewModel(application) { fun delBook(deleteOriginal: Boolean = false, success: (() -> Unit)? = null) { execute { bookData.value?.let { - App.db.bookDao().delete(it) + it.delete() 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 0c3da7cc3..d7fb413f0 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 @@ -222,9 +222,7 @@ class ReadBookViewModel(application: Application) : BaseViewModel(application) { fun removeFromBookshelf(success: (() -> Unit)?) { execute { - ReadBook.book?.let { - App.db.bookDao().delete(it) - } + ReadBook.book?.delete() }.onSuccess { success?.invoke() }