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

@ -75,7 +75,7 @@ class WebBook(val bookSource: BookSource) {
} }
suspend fun exploreBookAwait( suspend fun exploreBookAwait(
scope: CoroutineScope = Coroutine.DEFAULT, scope: CoroutineScope,
url: String, url: String,
page: Int? = 1, page: Int? = 1,
): ArrayList<SearchBook> { ): ArrayList<SearchBook> {
@ -114,7 +114,7 @@ class WebBook(val bookSource: BookSource) {
} }
suspend fun getBookInfoAwait( suspend fun getBookInfoAwait(
scope: CoroutineScope = Coroutine.DEFAULT, scope: CoroutineScope,
book: Book, book: Book,
canReName: Boolean = true, canReName: Boolean = true,
): Book { ): Book {
@ -164,7 +164,7 @@ class WebBook(val bookSource: BookSource) {
} }
suspend fun getChapterListAwait( suspend fun getChapterListAwait(
scope: CoroutineScope = Coroutine.DEFAULT, scope: CoroutineScope,
book: Book, book: Book,
): List<BookChapter> { ): List<BookChapter> {
book.type = bookSource.bookSourceType 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.ui.book.read.page.provider.ImageProvider
import io.legado.app.utils.msg import io.legado.app.utils.msg
import io.legado.app.utils.toastOnUi import io.legado.app.utils.toastOnUi
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.delay import kotlinx.coroutines.delay
import splitties.init.appCtx import splitties.init.appCtx
import kotlin.math.max import kotlin.math.max
@ -270,7 +271,7 @@ object ReadBook {
success?.invoke() success?.invoke()
} }
removeLoading(chapter.index) removeLoading(chapter.index)
} ?: download(chapter, resetPageOffset = resetPageOffset) } ?: download(this, chapter, resetPageOffset = resetPageOffset)
} ?: removeLoading(index) } ?: removeLoading(index)
}.onError { }.onError {
removeLoading(index) removeLoading(index)
@ -288,7 +289,7 @@ object ReadBook {
if (BookHelp.hasContent(book, chapter)) { if (BookHelp.hasContent(book, chapter)) {
removeLoading(chapter.index) removeLoading(chapter.index)
} else { } else {
download(chapter, false) download(this, chapter, false)
} }
} ?: removeLoading(index) } ?: removeLoading(index)
}.onError { }.onError {
@ -299,6 +300,7 @@ object ReadBook {
} }
private fun download( private fun download(
scope: CoroutineScope,
chapter: BookChapter, chapter: BookChapter,
resetPageOffset: Boolean, resetPageOffset: Boolean,
success: (() -> Unit)? = null success: (() -> Unit)? = null
@ -306,7 +308,7 @@ object ReadBook {
val book = book val book = book
val webBook = webBook val webBook = webBook
if (book != null && webBook != null) { if (book != null && webBook != null) {
CacheBook.download(Coroutine.DEFAULT, webBook, book, chapter) CacheBook.download(scope, webBook, book, chapter)
} else if (book != null) { } else if (book != null) {
contentLoadFinish( contentLoadFinish(
book, chapter, "没有书源", resetPageOffset = resetPageOffset book, chapter, "没有书源", resetPageOffset = resetPageOffset

Loading…
Cancel
Save