pull/1114/head^2
gedoor 3 years ago
parent c375f3156a
commit ff2c80d045
  1. 6
      app/src/main/java/io/legado/app/help/coroutine/Coroutine.kt
  2. 6
      app/src/main/java/io/legado/app/model/webBook/WebBook.kt
  3. 8
      app/src/main/java/io/legado/app/service/help/ReadBook.kt

@ -14,7 +14,7 @@ class Coroutine<T>(
companion object {
val DEFAULT = MainScope()
private val DEFAULT = MainScope()
fun <T> async(
scope: CoroutineScope = DEFAULT,
@ -24,10 +24,6 @@ class Coroutine<T>(
return Coroutine(scope, context, block)
}
fun cancel() {
DEFAULT.cancel()
}
}
private val job: Job

@ -75,7 +75,7 @@ class WebBook(val bookSource: BookSource) {
}
suspend fun exploreBookAwait(
scope: CoroutineScope = Coroutine.DEFAULT,
scope: CoroutineScope,
url: String,
page: Int? = 1,
): ArrayList<SearchBook> {
@ -114,7 +114,7 @@ class WebBook(val bookSource: BookSource) {
}
suspend fun getBookInfoAwait(
scope: CoroutineScope = Coroutine.DEFAULT,
scope: CoroutineScope,
book: Book,
canReName: Boolean = true,
): Book {
@ -164,7 +164,7 @@ class WebBook(val bookSource: BookSource) {
}
suspend fun getChapterListAwait(
scope: CoroutineScope = Coroutine.DEFAULT,
scope: CoroutineScope,
book: Book,
): List<BookChapter> {
book.type = bookSource.bookSourceType

@ -16,6 +16,7 @@ import io.legado.app.ui.book.read.page.provider.ChapterProvider
import io.legado.app.ui.book.read.page.provider.ImageProvider
import io.legado.app.utils.msg
import io.legado.app.utils.toastOnUi
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.delay
import splitties.init.appCtx
import kotlin.math.max
@ -270,7 +271,7 @@ object ReadBook {
success?.invoke()
}
removeLoading(chapter.index)
} ?: download(chapter, resetPageOffset = resetPageOffset)
} ?: download(this, chapter, resetPageOffset = resetPageOffset)
} ?: removeLoading(index)
}.onError {
removeLoading(index)
@ -288,7 +289,7 @@ object ReadBook {
if (BookHelp.hasContent(book, chapter)) {
removeLoading(chapter.index)
} else {
download(chapter, false)
download(this, chapter, false)
}
} ?: removeLoading(index)
}.onError {
@ -299,6 +300,7 @@ object ReadBook {
}
private fun download(
scope: CoroutineScope,
chapter: BookChapter,
resetPageOffset: Boolean,
success: (() -> Unit)? = null
@ -306,7 +308,7 @@ object ReadBook {
val book = book
val webBook = webBook
if (book != null && webBook != null) {
CacheBook.download(Coroutine.DEFAULT, webBook, book, chapter)
CacheBook.download(scope, webBook, book, chapter)
} else if (book != null) {
contentLoadFinish(
book, chapter, "没有书源", resetPageOffset = resetPageOffset

Loading…
Cancel
Save