From c2dc7119e1b90dc0e8320b6500e0add0cc0e76a9 Mon Sep 17 00:00:00 2001 From: gedoor Date: Sun, 9 Aug 2020 21:52:20 +0800 Subject: [PATCH] =?UTF-8?q?=E4=B9=A6=E6=9E=B6=E5=88=B7=E6=96=B0=E6=B7=BB?= =?UTF-8?q?=E5=8A=A0=E7=BA=BF=E7=A8=8B=E6=8E=A7=E5=88=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../main/java/io/legado/app/ui/main/MainViewModel.kt | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) 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 a3268db42..3263640ff 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.EventBus import io.legado.app.data.entities.Book import io.legado.app.data.entities.RssSource +import io.legado.app.help.AppConfig import io.legado.app.help.http.HttpHelper import io.legado.app.help.storage.Restore import io.legado.app.model.WebBook @@ -15,11 +16,19 @@ import io.legado.app.utils.GSON import io.legado.app.utils.fromJsonObject import io.legado.app.utils.postEvent import kotlinx.coroutines.Dispatchers.IO +import kotlinx.coroutines.asCoroutineDispatcher import kotlinx.coroutines.delay +import java.util.concurrent.Executors class MainViewModel(application: Application) : BaseViewModel(application) { + var upTocPool = Executors.newFixedThreadPool(AppConfig.threadCount).asCoroutineDispatcher() val updateList = hashSetOf() + override fun onCleared() { + super.onCleared() + upTocPool.close() + } + fun upChapterList() { execute { upChapterList(App.db.bookDao().hasUpdateBooks) @@ -37,7 +46,7 @@ class MainViewModel(application: Application) : BaseViewModel(application) { updateList.add(book.bookUrl) postEvent(EventBus.UP_BOOK, book.bookUrl) } - WebBook(bookSource).getChapterList(book) + WebBook(bookSource).getChapterList(book, context = upTocPool) .timeout(300000) .onSuccess(IO) { synchronized(this) {