From c1c5b3b90ad01dcff2519d1c7b3c5ea3771b5462 Mon Sep 17 00:00:00 2001 From: kunfei Date: Sun, 13 Oct 2019 19:43:07 +0800 Subject: [PATCH] up --- .../io/legado/app/ui/main/MainViewModel.kt | 39 +++++++++++-------- 1 file changed, 22 insertions(+), 17 deletions(-) diff --git a/app/src/main/java/io/legado/app/ui/main/MainViewModel.kt b/app/src/main/java/io/legado/app/ui/main/MainViewModel.kt index 992ed6a16..ca5c2f2f9 100644 --- a/app/src/main/java/io/legado/app/ui/main/MainViewModel.kt +++ b/app/src/main/java/io/legado/app/ui/main/MainViewModel.kt @@ -7,6 +7,7 @@ import io.legado.app.constant.BookType import io.legado.app.constant.Bus import io.legado.app.help.storage.Restore import io.legado.app.model.WebBook +import io.legado.app.utils.LogUtils import io.legado.app.utils.postEvent import kotlinx.coroutines.Dispatchers.IO import kotlinx.coroutines.delay @@ -25,25 +26,29 @@ class MainViewModel(application: Application) : BaseViewModel(application) { execute { App.db.bookDao().allBooks.forEach { book -> if (book.origin != BookType.local) { - 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()) - } + if (!updateList.contains(book.bookUrl)) { + App.db.bookSourceDao().getBookSource(book.origin)?.let { bookSource -> + synchronized(this) { + updateList.add(book.bookUrl) + LogUtils.d("updateAdd", book.name) + postEvent(Bus.UP_BOOK, book.bookUrl) } - .onFinally { - synchronized(this) { - updateList.remove(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()) + } } - } + .onFinally { + synchronized(this) { + updateList.remove(book.bookUrl) + LogUtils.d("updateRemove", book.name) + postEvent(Bus.UP_BOOK, book.bookUrl) + } + } + } } } delay(50)