From bf0e4c6ef1ea9e761d509330173d9f1b8336204a Mon Sep 17 00:00:00 2001 From: gedoor Date: Mon, 6 Sep 2021 15:16:08 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E4=B8=8B=E8=BD=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/src/main/assets/updateLog.md | 1 + app/src/main/java/io/legado/app/model/CacheBook.kt | 9 +++++++++ 2 files changed, 10 insertions(+) diff --git a/app/src/main/assets/updateLog.md b/app/src/main/assets/updateLog.md index ce6b562fc..56ca06009 100644 --- a/app/src/main/assets/updateLog.md +++ b/app/src/main/assets/updateLog.md @@ -22,6 +22,7 @@ * 次数/时间 格式: 如 5/60000, 每分钟最多访问5次 5. url参数添加js, 和webJs参数,js参数传入url返回新的url, webJs参数在webView内执行直到返回不为空,和正文规则webJs一样 +6. 重写离线缓存 **2021/09/01** 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 220f0727e..a5892fbbd 100644 --- a/app/src/main/java/io/legado/app/model/CacheBook.kt +++ b/app/src/main/java/io/legado/app/model/CacheBook.kt @@ -14,6 +14,7 @@ import io.legado.app.service.CacheBookService import io.legado.app.utils.postEvent import io.legado.app.utils.startService import kotlinx.coroutines.CoroutineScope +import kotlinx.coroutines.delay import java.text.SimpleDateFormat import java.util.* import java.util.concurrent.ConcurrentHashMap @@ -148,6 +149,9 @@ class CacheBook(val bookSource: BookSource, val book: Book) { } } + /** + * 从待下载列表内取第一条下载 + */ fun download(scope: CoroutineScope, context: CoroutineContext): Boolean { synchronized(this) { val chapterIndex = waitDownloadSet.firstOrNull() ?: return false @@ -176,6 +180,8 @@ class CacheBook(val bookSource: BookSource, val book: Book) { addLog("${book.name}-${chapter.title} getContentSuccess") downloadFinish(chapter, content.ifBlank { "No content" }) }.onError { + //出现错误等待1秒后重新加入待下载列表 + delay(1000) onErrorOrCancel(chapterIndex) print(it.localizedMessage) addLog("${book.name}-${chapter.title} getContentError${it.localizedMessage}") @@ -216,6 +222,9 @@ class CacheBook(val bookSource: BookSource, val book: Book) { onDownloadSet.remove(chapter.index) } ReadBook.removeLoading(chapter.index) + if (waitDownloadSet.isEmpty() && onDownloadSet.isEmpty()) { + postEvent(EventBus.UP_DOWNLOAD, "") + } } } }