From 2e937f8dd6b885f1891079f2731c4143ff7d26c9 Mon Sep 17 00:00:00 2001 From: Horis <821938089@qq.com> Date: Tue, 24 Jan 2023 23:50:46 +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 --- .../java/io/legado/app/help/book/BookHelp.kt | 2 +- .../java/io/legado/app/model/CacheBook.kt | 22 ++++++++++++++++++- .../app/ui/book/cache/CacheViewModel.kt | 2 +- 3 files changed, 23 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/io/legado/app/help/book/BookHelp.kt b/app/src/main/java/io/legado/app/help/book/BookHelp.kt index 88f82937b..388f16829 100644 --- a/app/src/main/java/io/legado/app/help/book/BookHelp.kt +++ b/app/src/main/java/io/legado/app/help/book/BookHelp.kt @@ -111,7 +111,7 @@ object BookHelp { ).writeText(content) } - private suspend fun saveImages( + suspend fun saveImages( bookSource: BookSource, book: Book, bookChapter: BookChapter, diff --git a/app/src/main/java/io/legado/app/model/CacheBook.kt b/app/src/main/java/io/legado/app/model/CacheBook.kt index f889b552f..e4a864d56 100644 --- a/app/src/main/java/io/legado/app/model/CacheBook.kt +++ b/app/src/main/java/io/legado/app/model/CacheBook.kt @@ -11,6 +11,7 @@ import io.legado.app.data.entities.BookSource import io.legado.app.exception.ConcurrentException import io.legado.app.help.book.BookHelp import io.legado.app.help.book.isLocal +import io.legado.app.help.coroutine.Coroutine import io.legado.app.model.webBook.WebBook import io.legado.app.service.CacheBookService import io.legado.app.utils.postEvent @@ -247,12 +248,31 @@ object CacheBook { waitDownloadSet.remove(chapterIndex) return } - if (BookHelp.hasContent(book, chapter)) { + if (BookHelp.hasImageContent(book, chapter)) { waitDownloadSet.remove(chapterIndex) return } waitDownloadSet.remove(chapterIndex) onDownloadSet.add(chapterIndex) + if (BookHelp.hasContent(book, chapter)) { + Coroutine.async { + BookHelp.getContent(book, chapter)?.let { + BookHelp.saveImages(bookSource, book, chapter, it) + } + }.onSuccess { + onSuccess(chapterIndex) + }.onError { + onPreError(chapterIndex, it) + //出现错误等待一秒后重新加入待下载列表 + delay(1000) + onPostError(chapterIndex, it, chapter.title) + }.onCancel { + onCancel(chapterIndex) + }.onFinally { + onFinally() + } + return + } WebBook.getContent( scope, bookSource, diff --git a/app/src/main/java/io/legado/app/ui/book/cache/CacheViewModel.kt b/app/src/main/java/io/legado/app/ui/book/cache/CacheViewModel.kt index ff77b7045..b74d44465 100644 --- a/app/src/main/java/io/legado/app/ui/book/cache/CacheViewModel.kt +++ b/app/src/main/java/io/legado/app/ui/book/cache/CacheViewModel.kt @@ -65,7 +65,7 @@ class CacheViewModel(application: Application) : BaseViewModel(application) { val cacheNames = BookHelp.getChapterFiles(book) if (cacheNames.isNotEmpty()) { appDb.bookChapterDao.getChapterList(book.bookUrl).forEach { chapter -> - if (cacheNames.contains(chapter.getFileName())) { + if (cacheNames.contains(chapter.getFileName()) || chapter.isVolume) { chapterCaches.add(chapter.url) } }