|
|
@ -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 { |
|
|
|