From 277406e0e65b234da0f592203c7e2578f3adceed Mon Sep 17 00:00:00 2001 From: kunfei Date: Tue, 10 Sep 2019 16:33:16 +0800 Subject: [PATCH] up --- .../ui/main/bookshelf/BookshelfViewModel.kt | 23 +++++++++---------- 1 file changed, 11 insertions(+), 12 deletions(-) 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 b1fd24966..c9baf1494 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 @@ -31,31 +31,30 @@ class BookshelfViewModel(application: Application) : BaseViewModel(application) fun upChapterList() { execute { - App.db.bookDao().getRecentRead().map { book -> + App.db.bookDao().getRecentRead().forEach { book -> if (book.origin != BookType.local) { - val bookSource = App.db.bookSourceDao().getBookSource(book.origin) - bookSource?.let { + App.db.bookSourceDao().getBookSource(book.origin)?.let { bookSource -> synchronized(this) { updateList.add(book.bookUrl) postEvent(Bus.UP_BOOK, book.bookUrl) } WebBook(bookSource).getChapterList(book) .onSuccess(IO) { - it?.let { - App.db.bookDao().update(book) - App.db.bookChapterDao().delByBook(book.bookUrl) - App.db.bookChapterDao().insert(*it.toTypedArray()) - } + it?.let { + App.db.bookDao().update(book) + App.db.bookChapterDao().delByBook(book.bookUrl) + App.db.bookChapterDao().insert(*it.toTypedArray()) + } } .onError { it.printStackTrace() } .onFinally { - synchronized(this) { - updateList.remove(book.bookUrl) - postEvent(Bus.UP_BOOK, book.bookUrl) + synchronized(this) { + updateList.remove(book.bookUrl) + postEvent(Bus.UP_BOOK, book.bookUrl) + } } - } } } delay(50)