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 996e9648e..be3c56295 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 @@ -5,6 +5,7 @@ import androidx.room.Entity import androidx.room.Ignore import androidx.room.Index 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.utils.GSON @@ -134,10 +135,12 @@ data class Book( } } - fun changeSource(newBook: Book) { + fun changeTo(newBook: Book) { newBook.group = group newBook.order = order newBook.customCoverUrl = customCoverUrl newBook.canUpdate = canUpdate + App.db.bookDao().delete(this) + App.db.bookDao().insert(newBook) } } \ 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 db6e4a5cf..3820f3655 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 @@ -134,11 +134,7 @@ class BookInfoViewModel(application: Application) : BaseViewModel(application) { fun changeTo(newBook: Book) { execute { if (inBookshelf) { - bookData.value?.let { - it.changeSource(newBook) - App.db.bookDao().delete(it) - } - App.db.bookDao().insert(newBook) + bookData.value?.changeTo(newBook) } bookData.postValue(newBook) if (newBook.tocUrl.isEmpty()) { 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 d23fa76fe..0c3da7cc3 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 @@ -149,17 +149,13 @@ class ReadBookViewModel(application: Application) : BaseViewModel(application) { fun changeTo(newBook: Book) { execute { ReadBook.upMsg(null) - ReadBook.book?.let { - it.changeSource(newBook) - App.db.bookDao().delete(it) - } + ReadBook.book?.changeTo(newBook) ReadBook.prevTextChapter = null ReadBook.curTextChapter = null ReadBook.nextTextChapter = null withContext(Main) { ReadBook.callBack?.upContent() } - App.db.bookDao().insert(newBook) ReadBook.book = newBook App.db.bookSourceDao().getBookSource(newBook.origin)?.let { ReadBook.webBook = WebBook(it)