pull/32/head
kunfei 5 years ago
parent 8b310b96dd
commit 579863ca7c
  1. 4
      app/src/main/java/io/legado/app/data/dao/BookChapterDao.kt
  2. 14
      app/src/main/java/io/legado/app/ui/main/bookshelf/BookshelfViewModel.kt

@ -25,4 +25,8 @@ interface BookChapterDao {
@Insert(onConflict = OnConflictStrategy.REPLACE) @Insert(onConflict = OnConflictStrategy.REPLACE)
fun insert(vararg bookChapter: BookChapter) fun insert(vararg bookChapter: BookChapter)
@Query("delete from chapters where bookUrl = :bookUrl")
fun delByBook(bookUrl: String)
} }

@ -39,14 +39,18 @@ class BookshelfViewModel(application: Application) : BaseViewModel(application)
updateList.add(book.bookUrl) updateList.add(book.bookUrl)
postEvent(Bus.UP_BOOK, book.bookUrl) postEvent(Bus.UP_BOOK, book.bookUrl)
} }
WebBook(bookSource).getChapterList(book).onSuccess(IO) { WebBook(bookSource).getChapterList(book)
.onSuccess(IO) {
it?.let { it?.let {
App.db.bookDao().update(book) App.db.bookDao().update(book)
if (it.size > App.db.bookChapterDao().getChapterCount(book.bookUrl)) { App.db.bookChapterDao().delByBook(book.bookUrl)
App.db.bookChapterDao().insert(*it.toTypedArray()) App.db.bookChapterDao().insert(*it.toTypedArray())
}
} }
}.onFinally { }
.onError {
it.printStackTrace()
}
.onFinally {
synchronized(this) { synchronized(this) {
updateList.remove(book.bookUrl) updateList.remove(book.bookUrl)
postEvent(Bus.UP_BOOK, book.bookUrl) postEvent(Bus.UP_BOOK, book.bookUrl)

Loading…
Cancel
Save