From ab2512e7e8af47d74c203e997aab4aa132f882cc Mon Sep 17 00:00:00 2001 From: gedoor Date: Wed, 9 Sep 2020 20:04:46 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E8=87=AA=E5=8A=A8=E6=8D=A2?= =?UTF-8?q?=E6=BA=90=E7=9A=84bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/io/legado/app/data/entities/Book.kt | 17 ++++++++++++++++- .../ui/book/changesource/ChangeSourceDialog.kt | 15 ++------------- .../app/ui/book/read/ReadBookViewModel.kt | 4 +++- 3 files changed, 21 insertions(+), 15 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 c6c62aa4b..7996e3ea9 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 @@ -151,11 +151,26 @@ data class Book( delete() App.db.bookDao().insert(newBook) } - + fun delete() { if (ReadBook.book?.bookUrl == bookUrl) { ReadBook.book = null } App.db.bookDao().delete(this) } + + fun upInfoFromOld(oldBook: Book?) { + oldBook?.let { + group = oldBook.group + durChapterIndex = oldBook.durChapterIndex + durChapterPos = oldBook.durChapterPos + durChapterTitle = oldBook.durChapterTitle + customCoverUrl = oldBook.customCoverUrl + customIntro = oldBook.customIntro + order = oldBook.order + if (coverUrl.isNullOrEmpty()) { + coverUrl = oldBook.getDisplayCover() + } + } + } } \ No newline at end of file diff --git a/app/src/main/java/io/legado/app/ui/book/changesource/ChangeSourceDialog.kt b/app/src/main/java/io/legado/app/ui/book/changesource/ChangeSourceDialog.kt index 7ebb4c0db..bbd627466 100644 --- a/app/src/main/java/io/legado/app/ui/book/changesource/ChangeSourceDialog.kt +++ b/app/src/main/java/io/legado/app/ui/book/changesource/ChangeSourceDialog.kt @@ -166,19 +166,8 @@ class ChangeSourceDialog : BaseDialogFragment(), override fun changeTo(searchBook: SearchBook) { val book = searchBook.toBook() - callBack?.oldBook?.let { oldBook -> - book.group = oldBook.group - book.durChapterIndex = oldBook.durChapterIndex - book.durChapterPos = oldBook.durChapterPos - book.durChapterTitle = oldBook.durChapterTitle - book.customCoverUrl = oldBook.customCoverUrl - book.customIntro = oldBook.customIntro - book.order = oldBook.order - if (book.coverUrl.isNullOrEmpty()) { - book.coverUrl = oldBook.getDisplayCover() - } - callBack?.changeTo(book) - } + book.upInfoFromOld(callBack?.oldBook) + callBack?.changeTo(book) dismiss() } 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 db721915a..0e2b4a050 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 @@ -188,7 +188,9 @@ class ReadBookViewModel(application: Application) : BaseViewModel(application) { .searchBookSuspend(this, name, variableBook = variableBook) .getOrNull(0)?.let { if (it.name == name && (it.author == author || author == "")) { - changeTo(it.toBook()) + val book = it.toBook() + book.upInfoFromOld(ReadBook.book) + changeTo(book) return@execute } }