添加预加载设置

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 importKeepName = "importKeepName"
const val screenOrientation = "screenOrientation" const val screenOrientation = "screenOrientation"
const val syncBookProgress = "syncBookProgress" const val syncBookProgress = "syncBookProgress"
const val preDownload = "preDownload"
const val cPrimary = "colorPrimary" const val cPrimary = "colorPrimary"
const val cAccent = "colorAccent" const val cAccent = "colorAccent"

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

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

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

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

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

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

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

@ -55,6 +55,12 @@
android:key="userAgent" android:key="userAgent"
android:title="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 <io.legado.app.ui.widget.prefs.SwitchPreference
android:defaultValue="true" android:defaultValue="true"
android:key="replaceEnableDefault" android:key="replaceEnableDefault"

Loading…
Cancel
Save