From bfa9df9b48b1eba6a37de32add764388f820c2d6 Mon Sep 17 00:00:00 2001 From: gedoor Date: Tue, 23 Feb 2021 21:20:26 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0=E7=AB=A0=E8=8A=82=E6=98=AF?= =?UTF-8?q?=E6=A3=80=E6=9F=A5=E6=98=AF=E5=90=A6=E6=9C=89=E7=9B=AE=E5=BD=95?= =?UTF-8?q?url?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../io/legado/app/ui/main/MainViewModel.kt | 39 +++++++++---------- 1 file changed, 19 insertions(+), 20 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 b701c4f5d..27a140167 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 @@ -14,7 +14,6 @@ import io.legado.app.model.webBook.WebBook import io.legado.app.service.help.CacheBook import io.legado.app.utils.FileUtils import io.legado.app.utils.postEvent -import kotlinx.coroutines.Dispatchers.IO import kotlinx.coroutines.asCoroutineDispatcher import kotlinx.coroutines.delay import java.util.concurrent.ConcurrentHashMap @@ -76,28 +75,28 @@ class MainViewModel(application: Application) : BaseViewModel(application) { postEvent(EventBus.UP_BOOK, book.bookUrl) } appDb.bookSourceDao.getBookSource(book.origin)?.let { bookSource -> - val webBook = WebBook(bookSource) - webBook.getChapterList(this, book, context = upTocPool) - .timeout(60000) - .onSuccess(IO) { - appDb.bookDao.update(book) - appDb.bookChapterDao.delByBook(book.bookUrl) - appDb.bookChapterDao.insert(*it.toTypedArray()) - if (AppConfig.preDownload) { - cacheBook(webBook, book) - } + execute(context = upTocPool) { + val webBook = WebBook(bookSource) + if (book.tocUrl.isBlank()) { + webBook.getBookInfoAwait(this, book) } - .onError { - it.printStackTrace() + val toc = webBook.getChapterListAwait(this, book) + appDb.bookDao.update(book) + appDb.bookChapterDao.delByBook(book.bookUrl) + appDb.bookChapterDao.insert(*toc.toTypedArray()) + if (AppConfig.preDownload) { + cacheBook(webBook, book) } - .onFinally { - synchronized(this) { - bookMap.remove(bookEntry.key) - updateList.remove(book.bookUrl) - postEvent(EventBus.UP_BOOK, book.bookUrl) - upNext() - } + }.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)