From a34f37b06291766cb463a2f99397976274baa904 Mon Sep 17 00:00:00 2001 From: gedoor Date: Tue, 7 Sep 2021 16:00:21 +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/model/CacheBook.kt | 22 ++++++++++++------- 1 file changed, 14 insertions(+), 8 deletions(-) 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 11f5478c4..a4b2745ee 100644 --- a/app/src/main/java/io/legado/app/model/CacheBook.kt +++ b/app/src/main/java/io/legado/app/model/CacheBook.kt @@ -155,6 +155,15 @@ class CacheBook(var bookSource: BookSource, var book: Book) { } } + private fun onFinally() { + synchronized(this) { + if (waitDownloadSet.isEmpty() && onDownloadSet.isEmpty()) { + postEvent(EventBus.UP_DOWNLOAD, "") + cacheBookMap.remove(book.bookUrl) + } + } + } + /** * 从待下载列表内取第一条下载 */ @@ -201,10 +210,7 @@ class CacheBook(var bookSource: BookSource, var book: Book) { }.onCancel { onErrorOrCancel(chapterIndex) }.onFinally { - if (waitDownloadSet.isEmpty() && onDownloadSet.isEmpty()) { - postEvent(EventBus.UP_DOWNLOAD, "") - cacheBookMap.remove(book.bookUrl) - } + onFinally() } return true } @@ -223,18 +229,18 @@ class CacheBook(var bookSource: BookSource, var book: Book) { onDownloadSet.add(chapter.index) WebBook.getContent(scope, bookSource, book, chapter) .onSuccess { content -> + onSuccess(chapter.index) downloadFinish(chapter, content.ifBlank { "No content" }, resetPageOffset) }.onError { + onErrorOrCancel(chapter.index) downloadFinish( chapter, it.localizedMessage ?: "download error", resetPageOffset ) + }.onCancel { + onErrorOrCancel(chapter.index) }.onFinally { - synchronized(this) { - onDownloadSet.remove(chapter.index) - } - ReadBook.removeLoading(chapter.index) if (waitDownloadSet.isEmpty() && onDownloadSet.isEmpty()) { postEvent(EventBus.UP_DOWNLOAD, "") }