下载加入超时判断

pull/306/head
gedoor 4 years ago
parent a5e2b51507
commit 64e5305999
  1. 60
      app/src/main/java/io/legado/app/service/DownloadService.kt

@ -188,38 +188,40 @@ class DownloadService : BaseService() {
bookChapter, bookChapter,
scope = this, scope = this,
context = searchPool context = searchPool
).onError { ).timeout(3000L)
synchronized(this) { .onError {
downloadingList.remove(bookChapter.url) synchronized(this) {
} downloadingList.remove(bookChapter.url)
Download.addLog(it.localizedMessage)
}.onSuccess(IO) { content ->
BookHelp.saveContent(book, bookChapter, content)
synchronized(this@DownloadService) {
downloadCount[book.bookUrl]?.increaseSuccess()
downloadCount[book.bookUrl]?.increaseFinished()
downloadCount[book.bookUrl]?.let {
updateNotification(
it,
downloadMap[book.bookUrl]?.size,
bookChapter.title
)
} }
val chapterMap = Download.addLog(it.localizedMessage)
finalMap[book.bookUrl] }
?: CopyOnWriteArraySet<BookChapter>().apply { .onSuccess(IO) { content ->
finalMap[book.bookUrl] = this BookHelp.saveContent(book, bookChapter, content)
} synchronized(this@DownloadService) {
chapterMap.add(bookChapter) downloadCount[book.bookUrl]?.increaseSuccess()
if (chapterMap.size == downloadMap[book.bookUrl]?.size) { downloadCount[book.bookUrl]?.increaseFinished()
downloadMap.remove(book.bookUrl) downloadCount[book.bookUrl]?.let {
finalMap.remove(book.bookUrl) updateNotification(
downloadCount.remove(book.bookUrl) it,
downloadMap[book.bookUrl]?.size,
bookChapter.title
)
}
val chapterMap =
finalMap[book.bookUrl]
?: CopyOnWriteArraySet<BookChapter>().apply {
finalMap[book.bookUrl] = this
}
chapterMap.add(bookChapter)
if (chapterMap.size == downloadMap[book.bookUrl]?.size) {
downloadMap.remove(book.bookUrl)
finalMap.remove(book.bookUrl)
downloadCount.remove(book.bookUrl)
}
} }
}.onFinally(IO) {
postDownloading(true)
} }
}.onFinally(IO) {
postDownloading(true)
}
} else { } else {
//无需下载的,设置为增加成功 //无需下载的,设置为增加成功
downloadCount[book.bookUrl]?.increaseSuccess() downloadCount[book.bookUrl]?.increaseSuccess()

Loading…
Cancel
Save