|
|
@@ -18,6 +18,7 @@ import io.legado.app.utils.postEvent
|
|
|
|
|
|
import io.legado.app.utils.startService
|
|
|
import kotlinx.coroutines.CoroutineScope
|
|
|
+import kotlinx.coroutines.CoroutineStart
|
|
|
import kotlinx.coroutines.Dispatchers.IO
|
|
|
import kotlinx.coroutines.delay
|
|
|
|
|
|
@@ -268,6 +269,7 @@ object CacheBook {
|
|
|
book,
|
|
|
chapter,
|
|
|
context = context,
|
|
|
+ start = CoroutineStart.LAZY,
|
|
|
executeContext = context
|
|
|
).onSuccess { content ->
|
|
|
onSuccess(chapter)
|
|
|
@@ -282,7 +284,7 @@ object CacheBook {
|
|
|
onCancel(chapterIndex)
|
|
|
}.onFinally {
|
|
|
onFinally()
|
|
|
- }
|
|
|
+ }.start()
|
|
|
}
|
|
|
|
|
|
@Synchronized
|
|
|
@@ -297,22 +299,28 @@ object CacheBook {
|
|
|
postEvent(EventBus.UP_DOWNLOAD, book.bookUrl)
|
|
|
onDownloadSet.add(chapter.index)
|
|
|
waitDownloadSet.remove(chapter.index)
|
|
|
- WebBook.getContent(scope, bookSource, book, chapter, executeContext = IO)
|
|
|
- .onSuccess { content ->
|
|
|
- onSuccess(chapter)
|
|
|
- ReadBook.downloadedChapters.add(chapter.index)
|
|
|
- ReadBook.downloadFailChapters.remove(chapter.index)
|
|
|
- downloadFinish(chapter, content, resetPageOffset)
|
|
|
- }.onError {
|
|
|
- onError(chapter, it)
|
|
|
- ReadBook.downloadFailChapters[chapter.index] =
|
|
|
- (ReadBook.downloadFailChapters[chapter.index] ?: 0) + 1
|
|
|
- downloadFinish(chapter, "获取正文失败\n${it.localizedMessage}", resetPageOffset)
|
|
|
- }.onCancel {
|
|
|
- onCancel(chapter.index)
|
|
|
- }.onFinally {
|
|
|
- postEvent(EventBus.UP_DOWNLOAD, book.bookUrl)
|
|
|
- }
|
|
|
+ WebBook.getContent(
|
|
|
+ scope,
|
|
|
+ bookSource,
|
|
|
+ book,
|
|
|
+ chapter,
|
|
|
+ start = CoroutineStart.LAZY,
|
|
|
+ executeContext = IO
|
|
|
+ ).onSuccess { content ->
|
|
|
+ onSuccess(chapter)
|
|
|
+ ReadBook.downloadedChapters.add(chapter.index)
|
|
|
+ ReadBook.downloadFailChapters.remove(chapter.index)
|
|
|
+ downloadFinish(chapter, content, resetPageOffset)
|
|
|
+ }.onError {
|
|
|
+ onError(chapter, it)
|
|
|
+ ReadBook.downloadFailChapters[chapter.index] =
|
|
|
+ (ReadBook.downloadFailChapters[chapter.index] ?: 0) + 1
|
|
|
+ downloadFinish(chapter, "获取正文失败\n${it.localizedMessage}", resetPageOffset)
|
|
|
+ }.onCancel {
|
|
|
+ onCancel(chapter.index)
|
|
|
+ }.onFinally {
|
|
|
+ postEvent(EventBus.UP_DOWNLOAD, book.bookUrl)
|
|
|
+ }.start()
|
|
|
}
|
|
|
|
|
|
private fun downloadFinish(
|