优化导入功能

pull/473/head
gedoor 4 years ago
parent da6d565c75
commit 599592fa6a
  1. 2
      app/src/main/java/io/legado/app/api/controller/BookshelfController.kt
  2. 8
      app/src/main/java/io/legado/app/ui/book/info/BookInfoViewModel.kt

@ -78,7 +78,7 @@ object BookshelfController {
val book = GSON.fromJsonObject<Book>(postData)
val returnData = ReturnData()
if (book != null) {
App.db.bookDao().insert(book)
App.db.bookDao().update(book)
if (ReadBook.book?.bookUrl == book.bookUrl) {
ReadBook.book = book
ReadBook.durChapterIndex = book.durChapterIndex

@ -161,7 +161,7 @@ class BookInfoViewModel(application: Application) : BaseViewModel(application) {
)
book.durChapterTitle = chapters[book.durChapterIndex].title
if (inBookshelf) {
App.db.bookDao().insert(book)
App.db.bookDao().update(book)
App.db.bookChapterDao().insert(*chapters.toTypedArray())
}
bookData.postValue(book)
@ -179,7 +179,11 @@ class BookInfoViewModel(application: Application) : BaseViewModel(application) {
book.durChapterPos = it.durChapterPos
book.durChapterTitle = it.durChapterTitle
}
App.db.bookDao().insert(book)
if (App.db.bookDao().getBook(book.bookUrl) != null) {
App.db.bookDao().update(book)
} else {
App.db.bookDao().insert(book)
}
if (ReadBook.book?.name == book.name && ReadBook.book?.author == book.author) {
ReadBook.book = book
}

Loading…
Cancel
Save