pull/1301/head
gedoor 4 years ago
parent 33a68f59e4
commit a34f37b062
  1. 22
      app/src/main/java/io/legado/app/model/CacheBook.kt

@ -155,6 +155,15 @@ class CacheBook(var bookSource: BookSource, var book: Book) {
} }
} }
private fun onFinally() {
synchronized(this) {
if (waitDownloadSet.isEmpty() && onDownloadSet.isEmpty()) {
postEvent(EventBus.UP_DOWNLOAD, "")
cacheBookMap.remove(book.bookUrl)
}
}
}
/** /**
* 从待下载列表内取第一条下载 * 从待下载列表内取第一条下载
*/ */
@ -201,10 +210,7 @@ class CacheBook(var bookSource: BookSource, var book: Book) {
}.onCancel { }.onCancel {
onErrorOrCancel(chapterIndex) onErrorOrCancel(chapterIndex)
}.onFinally { }.onFinally {
if (waitDownloadSet.isEmpty() && onDownloadSet.isEmpty()) { onFinally()
postEvent(EventBus.UP_DOWNLOAD, "")
cacheBookMap.remove(book.bookUrl)
}
} }
return true return true
} }
@ -223,18 +229,18 @@ class CacheBook(var bookSource: BookSource, var book: Book) {
onDownloadSet.add(chapter.index) onDownloadSet.add(chapter.index)
WebBook.getContent(scope, bookSource, book, chapter) WebBook.getContent(scope, bookSource, book, chapter)
.onSuccess { content -> .onSuccess { content ->
onSuccess(chapter.index)
downloadFinish(chapter, content.ifBlank { "No content" }, resetPageOffset) downloadFinish(chapter, content.ifBlank { "No content" }, resetPageOffset)
}.onError { }.onError {
onErrorOrCancel(chapter.index)
downloadFinish( downloadFinish(
chapter, chapter,
it.localizedMessage ?: "download error", it.localizedMessage ?: "download error",
resetPageOffset resetPageOffset
) )
}.onCancel {
onErrorOrCancel(chapter.index)
}.onFinally { }.onFinally {
synchronized(this) {
onDownloadSet.remove(chapter.index)
}
ReadBook.removeLoading(chapter.index)
if (waitDownloadSet.isEmpty() && onDownloadSet.isEmpty()) { if (waitDownloadSet.isEmpty() && onDownloadSet.isEmpty()) {
postEvent(EventBus.UP_DOWNLOAD, "") postEvent(EventBus.UP_DOWNLOAD, "")
} }

Loading…
Cancel
Save