From 36923356100f8169064da3d4583a00f1c4db6b06 Mon Sep 17 00:00:00 2001 From: gedoor Date: Sat, 14 Nov 2020 23:10:57 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../io/legado/app/ui/main/MainViewModel.kt | 69 +++++++++---------- 1 file changed, 34 insertions(+), 35 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 a87ea2e32..0f447bf30 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 @@ -68,44 +68,43 @@ class MainViewModel(application: Application) : BaseViewModel(application) { } } + @Synchronized private fun updateToc() { - 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 -> - val webBook = WebBook(bookSource) - webBook.getChapterList(book, context = upTocPool) - .timeout(300000) - .onSuccess(IO) { - App.db.bookDao().update(book) - App.db.bookChapterDao().delByBook(book.bookUrl) - App.db.bookChapterDao().insert(*it.toTypedArray()) - cacheBook(webBook, book) - } - .onError { - it.printStackTrace() - } - .onFinally { - synchronized(this) { - bookMap.remove(bookEntry.key) - updateList.remove(book.bookUrl) - postEvent(EventBus.UP_BOOK, book.bookUrl) - upNext() - } + 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 -> + val webBook = WebBook(bookSource) + webBook.getChapterList(book, context = upTocPool) + .timeout(300000) + .onSuccess(IO) { + App.db.bookDao().update(book) + App.db.bookChapterDao().delByBook(book.bookUrl) + App.db.bookChapterDao().insert(*it.toTypedArray()) + cacheBook(webBook, book) + } + .onError { + it.printStackTrace() + } + .onFinally { + synchronized(this) { + bookMap.remove(bookEntry.key) + updateList.remove(book.bookUrl) + postEvent(EventBus.UP_BOOK, book.bookUrl) + upNext() } - } ?: synchronized(this) { - bookMap.remove(bookEntry.key) - updateList.remove(book.bookUrl) - postEvent(EventBus.UP_BOOK, book.bookUrl) - upNext() - } - return + } + } ?: synchronized(this) { + bookMap.remove(bookEntry.key) + updateList.remove(book.bookUrl) + postEvent(EventBus.UP_BOOK, book.bookUrl) + upNext() } + return } } }