换源优化

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.Ignore
import androidx.room.Index import androidx.room.Index
import androidx.room.PrimaryKey import androidx.room.PrimaryKey
import io.legado.app.App
import io.legado.app.constant.AppPattern import io.legado.app.constant.AppPattern
import io.legado.app.constant.BookType import io.legado.app.constant.BookType
import io.legado.app.utils.GSON 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.group = group
newBook.order = order newBook.order = order
newBook.customCoverUrl = customCoverUrl newBook.customCoverUrl = customCoverUrl
newBook.canUpdate = canUpdate 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) { fun changeTo(newBook: Book) {
execute { execute {
if (inBookshelf) { if (inBookshelf) {
bookData.value?.let { bookData.value?.changeTo(newBook)
it.changeSource(newBook)
App.db.bookDao().delete(it)
}
App.db.bookDao().insert(newBook)
} }
bookData.postValue(newBook) bookData.postValue(newBook)
if (newBook.tocUrl.isEmpty()) { if (newBook.tocUrl.isEmpty()) {

@ -149,17 +149,13 @@ class ReadBookViewModel(application: Application) : BaseViewModel(application) {
fun changeTo(newBook: Book) { fun changeTo(newBook: Book) {
execute { execute {
ReadBook.upMsg(null) ReadBook.upMsg(null)
ReadBook.book?.let { ReadBook.book?.changeTo(newBook)
it.changeSource(newBook)
App.db.bookDao().delete(it)
}
ReadBook.prevTextChapter = null ReadBook.prevTextChapter = null
ReadBook.curTextChapter = null ReadBook.curTextChapter = null
ReadBook.nextTextChapter = null ReadBook.nextTextChapter = null
withContext(Main) { withContext(Main) {
ReadBook.callBack?.upContent() ReadBook.callBack?.upContent()
} }
App.db.bookDao().insert(newBook)
ReadBook.book = newBook ReadBook.book = newBook
App.db.bookSourceDao().getBookSource(newBook.origin)?.let { App.db.bookSourceDao().getBookSource(newBook.origin)?.let {
ReadBook.webBook = WebBook(it) ReadBook.webBook = WebBook(it)

Loading…
Cancel
Save