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 } }