feat: 优化

pull/274/head 3.20.070622
gedoor 4 years ago
parent 304785f902
commit 9798f24cc1
  1. 3
      app/src/main/assets/updateLog.md
  2. 12
      app/src/main/java/io/legado/app/service/DownloadService.kt
  3. 2
      app/src/main/java/io/legado/app/service/help/Download.kt

@ -3,6 +3,9 @@
* 请关注公众号[开源阅读]()支持我,同时关注合作公众号[小说拾遗](),阅读公众号小编。 * 请关注公众号[开源阅读]()支持我,同时关注合作公众号[小说拾遗](),阅读公众号小编。
* 新公众号[开源阅读]()已启用,[开源阅读软件]()备用 * 新公众号[开源阅读]()已启用,[开源阅读软件]()备用
**2020/07/06**
* 优化下载
**2020/07/05** **2020/07/05**
* 修复夜间模式底栏颜色调整无效的bug * 修复夜间模式底栏颜色调整无效的bug
* 【web看书】加了翻页、排序等 by [Celeter](https://github.com/Celeter) * 【web看书】加了翻页、排序等 by [Celeter](https://github.com/Celeter)

@ -151,6 +151,7 @@ class DownloadService : BaseService() {
private fun download() { private fun download() {
downloadingCount += 1 downloadingCount += 1
Download.addLog("downloadingCount++")
tasks.add(Coroutine.async(this, context = searchPool) { tasks.add(Coroutine.async(this, context = searchPool) {
if (!isActive) return@async if (!isActive) return@async
val bookChapter: BookChapter? = synchronized(this@DownloadService) { val bookChapter: BookChapter? = synchronized(this@DownloadService) {
@ -184,12 +185,14 @@ class DownloadService : BaseService() {
scope = this, scope = this,
context = searchPool context = searchPool
).onError { ).onError {
synchronized(this) {
downloadingList.remove(bookChapter.url)
}
Download.addLog(it.localizedMessage) Download.addLog(it.localizedMessage)
}.onSuccess(IO) { content -> }.onSuccess(IO) { content ->
downloadCount[book.bookUrl]?.increaseSuccess()
BookHelp.saveContent(book, bookChapter, content) BookHelp.saveContent(book, bookChapter, content)
}.onFinally(IO) {
synchronized(this@DownloadService) { synchronized(this@DownloadService) {
downloadCount[book.bookUrl]?.increaseSuccess()
downloadCount[book.bookUrl]?.increaseFinished() downloadCount[book.bookUrl]?.increaseFinished()
downloadCount[book.bookUrl]?.let { downloadCount[book.bookUrl]?.let {
updateNotification( updateNotification(
@ -210,8 +213,9 @@ class DownloadService : BaseService() {
downloadCount.remove(book.bookUrl) downloadCount.remove(book.bookUrl)
} }
} }
}.onFinally(IO) {
postDownloading(true)
} }
postDownloading(true)
} else { } else {
//无需下载的,设置为增加成功 //无需下载的,设置为增加成功
downloadCount[book.bookUrl]?.increaseSuccess() downloadCount[book.bookUrl]?.increaseSuccess()
@ -224,6 +228,8 @@ class DownloadService : BaseService() {
private fun postDownloading(hasChapter: Boolean) { private fun postDownloading(hasChapter: Boolean) {
downloadingCount -= 1 downloadingCount -= 1
Download.addLog("downloadingCount--")
Download.addLog("downloadingCount $downloadingCount")
if (hasChapter) { if (hasChapter) {
download() download()
} else { } else {

@ -12,7 +12,7 @@ object Download {
fun addLog(log: String?) { fun addLog(log: String?) {
log ?: return log ?: return
synchronized(this) { synchronized(this) {
if (logs.size > 30) { if (logs.size > 1000) {
logs.removeAt(0) logs.removeAt(0)
} }
logs.add(log) logs.add(log)

Loading…
Cancel
Save