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, "") + } } } }