预下载章节可调整数目

pull/978/head
gedoor 4 years ago
parent ff6f4bf6ee
commit 5b40199891
  1. 25
      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.delay
import kotlinx.coroutines.launch import kotlinx.coroutines.launch
import splitties.init.appCtx import splitties.init.appCtx
import kotlin.math.min
@Suppress("MemberVisibilityCanBePrivate") @Suppress("MemberVisibilityCanBePrivate")
@ -137,12 +138,12 @@ object ReadBook {
callBack?.upContent() callBack?.upContent()
} }
loadContent(durChapterIndex.plus(1), upContent, false) loadContent(durChapterIndex.plus(1), upContent, false)
if (AppConfig.preDownloadNum) { GlobalScope.launch(Dispatchers.IO) {
GlobalScope.launch(Dispatchers.IO) { val maxChapterIndex =
for (i in 2..9) { min(chapterSize, durChapterIndex + AppConfig.preDownloadNum)
delay(1000) for (i in 2 until maxChapterIndex) {
download(durChapterIndex + i) delay(1000)
} download(durChapterIndex + i)
} }
} }
} }
@ -169,12 +170,12 @@ object ReadBook {
callBack?.upContent() callBack?.upContent()
} }
loadContent(durChapterIndex.minus(1), upContent, false) loadContent(durChapterIndex.minus(1), upContent, false)
if (AppConfig.preDownloadNum) { GlobalScope.launch(Dispatchers.IO) {
GlobalScope.launch(Dispatchers.IO) { val maxChapterIndex =
for (i in 2..9) { min(chapterSize, durChapterIndex + AppConfig.preDownloadNum)
delay(1000) for (i in 2 until maxChapterIndex) {
download(durChapterIndex - i) delay(1000)
} download(durChapterIndex - i)
} }
} }
} }

Loading…
Cancel
Save