From c4303af5749a48dfa745981947cc946b70545c2b Mon Sep 17 00:00:00 2001 From: gedoor Date: Thu, 27 Aug 2020 17:37:31 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E5=B0=8F=E8=AF=B4=E6=9B=B4?= =?UTF-8?q?=E6=96=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../io/legado/app/ui/main/MainViewModel.kt | 32 +++++++++++-------- 1 file changed, 18 insertions(+), 14 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 3917769b0..fbacdd448 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 @@ -48,29 +48,31 @@ class MainViewModel(application: Application) : BaseViewModel(application) { } fun upToc(books: List) { - books.filter { - it.origin != BookType.local && it.canUpdate - }.forEach { - bookMap[it.bookUrl] = it - } - for (i in 0 until threadCount) { - if (usePoolCount < threadCount) { - usePoolCount++ - updateToc() + execute { + books.filter { + it.origin != BookType.local && it.canUpdate + }.forEach { + bookMap[it.bookUrl] = it + } + for (i in 0 until threadCount) { + if (usePoolCount < threadCount) { + usePoolCount++ + updateToc() + } } } } private fun updateToc() { - execute { + synchronized(this) { bookMap.forEach { bookEntry -> if (!updateList.contains(bookEntry.key)) { val book = bookEntry.value + synchronized(this) { + updateList.add(book.bookUrl) + postEvent(EventBus.UP_BOOK, book.bookUrl) + } App.db.bookSourceDao().getBookSource(book.origin)?.let { bookSource -> - synchronized(this) { - updateList.add(book.bookUrl) - postEvent(EventBus.UP_BOOK, book.bookUrl) - } WebBook(bookSource).getChapterList(book, context = upTocPool) .timeout(300000) .onSuccess(IO) { @@ -91,6 +93,8 @@ class MainViewModel(application: Application) : BaseViewModel(application) { } } ?: synchronized(this) { bookMap.remove(bookEntry.key) + updateList.remove(book.bookUrl) + postEvent(EventBus.UP_BOOK, book.bookUrl) upNext() } return@forEach