添加预加载设置

pull/783/head
gedoor 4 years ago
parent 16d29aeb55
commit 1767f96de2
  1. 1
      app/src/main/java/io/legado/app/constant/PreferKey.kt
  2. 2
      app/src/main/java/io/legado/app/help/AppConfig.kt
  3. 14
      app/src/main/java/io/legado/app/service/help/ReadBook.kt
  4. 2
      app/src/main/java/io/legado/app/ui/main/MainViewModel.kt
  5. 2
      app/src/main/res/values-zh-rHK/strings.xml
  6. 2
      app/src/main/res/values-zh-rTW/strings.xml
  7. 2
      app/src/main/res/values-zh/strings.xml
  8. 2
      app/src/main/res/values/strings.xml
  9. 6
      app/src/main/res/xml/pref_config_other.xml

@ -64,6 +64,7 @@ object PreferKey {
const val importKeepName = "importKeepName"
const val screenOrientation = "screenOrientation"
const val syncBookProgress = "syncBookProgress"
const val preDownload = "preDownload"
const val cPrimary = "colorPrimary"
const val cAccent = "colorAccent"

@ -149,6 +149,8 @@ object AppConfig : SharedPreferences.OnSharedPreferenceChangeListener {
val syncBookProgress get() = context.getPrefBoolean(PreferKey.syncBookProgress, true)
val preDownload get() = context.getPrefBoolean(PreferKey.preDownload, true)
private fun getPrefUserAgent(): String {
val ua = context.getPrefString(PreferKey.userAgent)
if (ua.isNullOrBlank()) {

@ -133,13 +133,15 @@ object ReadBook {
callBack?.upContent()
}
loadContent(durChapterIndex.plus(1), upContent, false)
if (AppConfig.preDownload) {
GlobalScope.launch(Dispatchers.IO) {
for (i in 2..10) {
delay(100)
for (i in 2..9) {
delay(1000)
download(durChapterIndex + i)
}
}
}
}
saveRead()
callBack?.upView()
curPageChanged()
@ -163,10 +165,12 @@ object ReadBook {
callBack?.upContent()
}
loadContent(durChapterIndex.minus(1), upContent, false)
if (AppConfig.preDownload) {
GlobalScope.launch(Dispatchers.IO) {
for (i in -5..-2) {
delay(100)
download(durChapterIndex + i)
for (i in 2..9) {
delay(1000)
download(durChapterIndex - i)
}
}
}
}

@ -81,8 +81,10 @@ class MainViewModel(application: Application) : BaseViewModel(application) {
App.db.bookDao.update(book)
App.db.bookChapterDao.delByBook(book.bookUrl)
App.db.bookChapterDao.insert(*it.toTypedArray())
if (AppConfig.preDownload) {
cacheBook(webBook, book)
}
}
.onError {
it.printStackTrace()
}

@ -797,5 +797,7 @@
<string name="single_url">单URL</string>
<string name="export_bookshelf">导出书单</string>
<string name="import_bookshelf">导入书单</string>
<string name="pre_download">预下载</string>
<string name="pre_download_s">预先下载10章正文</string>
</resources>

@ -798,5 +798,7 @@
<string name="single_url">单URL</string>
<string name="export_bookshelf">导出书单</string>
<string name="import_bookshelf">导入书单</string>
<string name="pre_download">预下载</string>
<string name="pre_download_s">预先下载10章正文</string>
</resources>

@ -801,5 +801,7 @@
<string name="single_url">单URL</string>
<string name="export_bookshelf">导出书单</string>
<string name="import_bookshelf">导入书单</string>
<string name="pre_download">预下载</string>
<string name="pre_download_s">预先下载10章正文</string>
</resources>

@ -804,5 +804,7 @@
<string name="single_url">单URL</string>
<string name="export_bookshelf">导出书单</string>
<string name="import_bookshelf">导入书单</string>
<string name="pre_download">预下载</string>
<string name="pre_download_s">预先下载10章正文</string>
</resources>

@ -55,6 +55,12 @@
android:key="userAgent"
android:title="UserAgent" />
<io.legado.app.ui.widget.prefs.SwitchPreference
android:defaultValue="true"
android:key="preDownload"
android:title="@string/pre_download"
android:summary="@string/pre_download_s" />
<io.legado.app.ui.widget.prefs.SwitchPreference
android:defaultValue="true"
android:key="replaceEnableDefault"

Loading…
Cancel
Save