From 579863ca7c761be14f73453b24e540aa5a914349 Mon Sep 17 00:00:00 2001 From: kunfei Date: Sun, 8 Sep 2019 08:54:21 +0800 Subject: [PATCH] up --- .../java/io/legado/app/data/dao/BookChapterDao.kt | 4 ++++ .../app/ui/main/bookshelf/BookshelfViewModel.kt | 14 +++++++++----- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/app/src/main/java/io/legado/app/data/dao/BookChapterDao.kt b/app/src/main/java/io/legado/app/data/dao/BookChapterDao.kt index fdbff2bf1..8ed58cadf 100644 --- a/app/src/main/java/io/legado/app/data/dao/BookChapterDao.kt +++ b/app/src/main/java/io/legado/app/data/dao/BookChapterDao.kt @@ -25,4 +25,8 @@ interface BookChapterDao { @Insert(onConflict = OnConflictStrategy.REPLACE) fun insert(vararg bookChapter: BookChapter) + + @Query("delete from chapters where bookUrl = :bookUrl") + fun delByBook(bookUrl: String) + } \ No newline at end of file diff --git a/app/src/main/java/io/legado/app/ui/main/bookshelf/BookshelfViewModel.kt b/app/src/main/java/io/legado/app/ui/main/bookshelf/BookshelfViewModel.kt index 463c0b015..b1fd24966 100644 --- a/app/src/main/java/io/legado/app/ui/main/bookshelf/BookshelfViewModel.kt +++ b/app/src/main/java/io/legado/app/ui/main/bookshelf/BookshelfViewModel.kt @@ -39,14 +39,18 @@ class BookshelfViewModel(application: Application) : BaseViewModel(application) updateList.add(book.bookUrl) postEvent(Bus.UP_BOOK, book.bookUrl) } - WebBook(bookSource).getChapterList(book).onSuccess(IO) { + WebBook(bookSource).getChapterList(book) + .onSuccess(IO) { it?.let { App.db.bookDao().update(book) - if (it.size > App.db.bookChapterDao().getChapterCount(book.bookUrl)) { - App.db.bookChapterDao().insert(*it.toTypedArray()) - } + App.db.bookChapterDao().delByBook(book.bookUrl) + App.db.bookChapterDao().insert(*it.toTypedArray()) } - }.onFinally { + } + .onError { + it.printStackTrace() + } + .onFinally { synchronized(this) { updateList.remove(book.bookUrl) postEvent(Bus.UP_BOOK, book.bookUrl)