下载加入超时判断

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,
scope = this,
context = searchPool
).onError {
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
)
).timeout(3000L)
.onError {
synchronized(this) {
downloadingList.remove(bookChapter.url)
}
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)
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 =
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 {
//无需下载的,设置为增加成功
downloadCount[book.bookUrl]?.increaseSuccess()

Loading…
Cancel
Save