From 5b40199891dedd2fcd5177c1cce64d8b854d3f26 Mon Sep 17 00:00:00 2001 From: gedoor Date: Thu, 6 May 2021 17:28:20 +0800 Subject: [PATCH] =?UTF-8?q?=E9=A2=84=E4=B8=8B=E8=BD=BD=E7=AB=A0=E8=8A=82?= =?UTF-8?q?=E5=8F=AF=E8=B0=83=E6=95=B4=E6=95=B0=E7=9B=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../io/legado/app/service/help/ReadBook.kt | 25 ++++++++++--------- 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/app/src/main/java/io/legado/app/service/help/ReadBook.kt b/app/src/main/java/io/legado/app/service/help/ReadBook.kt index ffb4c8f9b..0eef72768 100644 --- a/app/src/main/java/io/legado/app/service/help/ReadBook.kt +++ b/app/src/main/java/io/legado/app/service/help/ReadBook.kt @@ -21,6 +21,7 @@ import kotlinx.coroutines.GlobalScope import kotlinx.coroutines.delay import kotlinx.coroutines.launch import splitties.init.appCtx +import kotlin.math.min @Suppress("MemberVisibilityCanBePrivate") @@ -137,12 +138,12 @@ object ReadBook { callBack?.upContent() } loadContent(durChapterIndex.plus(1), upContent, false) - if (AppConfig.preDownloadNum) { - GlobalScope.launch(Dispatchers.IO) { - for (i in 2..9) { - delay(1000) - download(durChapterIndex + i) - } + GlobalScope.launch(Dispatchers.IO) { + val maxChapterIndex = + min(chapterSize, durChapterIndex + AppConfig.preDownloadNum) + for (i in 2 until maxChapterIndex) { + delay(1000) + download(durChapterIndex + i) } } } @@ -169,12 +170,12 @@ object ReadBook { callBack?.upContent() } loadContent(durChapterIndex.minus(1), upContent, false) - if (AppConfig.preDownloadNum) { - GlobalScope.launch(Dispatchers.IO) { - for (i in 2..9) { - delay(1000) - download(durChapterIndex - i) - } + GlobalScope.launch(Dispatchers.IO) { + val maxChapterIndex = + min(chapterSize, durChapterIndex + AppConfig.preDownloadNum) + for (i in 2 until maxChapterIndex) { + delay(1000) + download(durChapterIndex - i) } } }