预下载章节可调整数目

pull/978/head
gedoor 4 years ago
parent ff6f4bf6ee
commit 5b40199891
  1. 13
      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,15 +138,15 @@ 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) {
for (i in 2..9) { val maxChapterIndex =
min(chapterSize, durChapterIndex + AppConfig.preDownloadNum)
for (i in 2 until maxChapterIndex) {
delay(1000) delay(1000)
download(durChapterIndex + i) download(durChapterIndex + i)
} }
} }
} }
}
saveRead() saveRead()
callBack?.upView() callBack?.upView()
curPageChanged() curPageChanged()
@ -169,15 +170,15 @@ 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) {
for (i in 2..9) { val maxChapterIndex =
min(chapterSize, durChapterIndex + AppConfig.preDownloadNum)
for (i in 2 until maxChapterIndex) {
delay(1000) delay(1000)
download(durChapterIndex - i) download(durChapterIndex - i)
} }
} }
} }
}
saveRead() saveRead()
callBack?.upView() callBack?.upView()
curPageChanged() curPageChanged()

Loading…
Cancel
Save