From 9798f24cc1c0e7166436fa317d131623f0fd36e2 Mon Sep 17 00:00:00 2001 From: gedoor Date: Mon, 6 Jul 2020 22:37:39 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/src/main/assets/updateLog.md | 3 +++ .../java/io/legado/app/service/DownloadService.kt | 12 +++++++++--- .../main/java/io/legado/app/service/help/Download.kt | 2 +- 3 files changed, 13 insertions(+), 4 deletions(-) diff --git a/app/src/main/assets/updateLog.md b/app/src/main/assets/updateLog.md index 0f8a4d438..d4fda7b96 100644 --- a/app/src/main/assets/updateLog.md +++ b/app/src/main/assets/updateLog.md @@ -3,6 +3,9 @@ * 请关注公众号[开源阅读]()支持我,同时关注合作公众号[小说拾遗](),阅读公众号小编。 * 新公众号[开源阅读]()已启用,[开源阅读软件]()备用 +**2020/07/06** +* 优化下载 + **2020/07/05** * 修复夜间模式底栏颜色调整无效的bug * 【web看书】加了翻页、排序等 by [Celeter](https://github.com/Celeter) diff --git a/app/src/main/java/io/legado/app/service/DownloadService.kt b/app/src/main/java/io/legado/app/service/DownloadService.kt index 8148ef7d1..86785fefd 100644 --- a/app/src/main/java/io/legado/app/service/DownloadService.kt +++ b/app/src/main/java/io/legado/app/service/DownloadService.kt @@ -151,6 +151,7 @@ class DownloadService : BaseService() { private fun download() { downloadingCount += 1 + Download.addLog("downloadingCount++") tasks.add(Coroutine.async(this, context = searchPool) { if (!isActive) return@async val bookChapter: BookChapter? = synchronized(this@DownloadService) { @@ -184,12 +185,14 @@ class DownloadService : BaseService() { scope = this, context = searchPool ).onError { + synchronized(this) { + downloadingList.remove(bookChapter.url) + } Download.addLog(it.localizedMessage) }.onSuccess(IO) { content -> - downloadCount[book.bookUrl]?.increaseSuccess() BookHelp.saveContent(book, bookChapter, content) - }.onFinally(IO) { synchronized(this@DownloadService) { + downloadCount[book.bookUrl]?.increaseSuccess() downloadCount[book.bookUrl]?.increaseFinished() downloadCount[book.bookUrl]?.let { updateNotification( @@ -210,8 +213,9 @@ class DownloadService : BaseService() { downloadCount.remove(book.bookUrl) } } + }.onFinally(IO) { + postDownloading(true) } - postDownloading(true) } else { //无需下载的,设置为增加成功 downloadCount[book.bookUrl]?.increaseSuccess() @@ -224,6 +228,8 @@ class DownloadService : BaseService() { private fun postDownloading(hasChapter: Boolean) { downloadingCount -= 1 + Download.addLog("downloadingCount--") + Download.addLog("downloadingCount $downloadingCount") if (hasChapter) { download() } else { diff --git a/app/src/main/java/io/legado/app/service/help/Download.kt b/app/src/main/java/io/legado/app/service/help/Download.kt index d7e99b641..5ba31004a 100644 --- a/app/src/main/java/io/legado/app/service/help/Download.kt +++ b/app/src/main/java/io/legado/app/service/help/Download.kt @@ -12,7 +12,7 @@ object Download { fun addLog(log: String?) { log ?: return synchronized(this) { - if (logs.size > 30) { + if (logs.size > 1000) { logs.removeAt(0) } logs.add(log)