换源优化

pull/274/head
gedoor 4 years ago
parent 1f6d9b36cb
commit 2ab5e8b6d4
  1. 5
      app/src/main/java/io/legado/app/data/entities/Book.kt
  2. 6
      app/src/main/java/io/legado/app/ui/book/info/BookInfoViewModel.kt
  3. 6
      app/src/main/java/io/legado/app/ui/book/read/ReadBookViewModel.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)
}
}

@ -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()) {

@ -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)

Loading…
Cancel
Save