优化导入功能

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. 6
      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 book = GSON.fromJsonObject<Book>(postData)
val returnData = ReturnData() val returnData = ReturnData()
if (book != null) { if (book != null) {
App.db.bookDao().insert(book) App.db.bookDao().update(book)
if (ReadBook.book?.bookUrl == book.bookUrl) { if (ReadBook.book?.bookUrl == book.bookUrl) {
ReadBook.book = book ReadBook.book = book
ReadBook.durChapterIndex = book.durChapterIndex ReadBook.durChapterIndex = book.durChapterIndex

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

Loading…
Cancel
Save