预下载章节可调整数目

pull/978/head
gedoor 4 years ago
parent a5dbea26b8
commit 11bf63e6a6
  1. 2
      app/src/main/java/io/legado/app/constant/PreferKey.kt
  2. 8
      app/src/main/java/io/legado/app/help/AppConfig.kt
  3. 4
      app/src/main/java/io/legado/app/service/help/ReadBook.kt
  4. 8
      app/src/main/java/io/legado/app/ui/config/OtherConfigFragment.kt
  5. 7
      app/src/main/java/io/legado/app/ui/main/MainViewModel.kt
  6. 2
      app/src/main/res/values-zh-rHK/strings.xml
  7. 2
      app/src/main/res/values-zh-rTW/strings.xml
  8. 2
      app/src/main/res/values-zh/strings.xml
  9. 2
      app/src/main/res/values/strings.xml
  10. 5
      app/src/main/res/xml/pref_config_other.xml

@ -66,7 +66,7 @@ object PreferKey {
const val importKeepName = "importKeepName"
const val screenOrientation = "screenOrientation"
const val syncBookProgress = "syncBookProgress"
const val preDownload = "preDownload"
const val preDownloadNum = "preDownloadNum"
const val autoRefresh = "auto_refresh"
const val defaultToRead = "defaultToRead"
const val exportCharset = "exportCharset"

@ -184,14 +184,18 @@ object AppConfig : SharedPreferences.OnSharedPreferenceChangeListener {
val syncBookProgress get() = appCtx.getPrefBoolean(PreferKey.syncBookProgress, true)
val preDownload get() = appCtx.getPrefBoolean(PreferKey.preDownload, true)
var preDownloadNum
get() = appCtx.getPrefInt(PreferKey.preDownloadNum, 10)
set(value) {
appCtx.putPrefInt(PreferKey.preDownloadNum, value)
}
val mediaButtonOnExit get() = appCtx.getPrefBoolean("mediaButtonOnExit", true)
val replaceEnableDefault get() = appCtx.getPrefBoolean(PreferKey.replaceEnableDefault, true)
val fullScreenGesturesSupport: Boolean
get () = appCtx.getPrefBoolean(PreferKey.fullScreenGesturesSupport, false)
get() = appCtx.getPrefBoolean(PreferKey.fullScreenGesturesSupport, false)
private fun getPrefUserAgent(): String {
val ua = appCtx.getPrefString(PreferKey.userAgent)

@ -137,7 +137,7 @@ object ReadBook {
callBack?.upContent()
}
loadContent(durChapterIndex.plus(1), upContent, false)
if (AppConfig.preDownload) {
if (AppConfig.preDownloadNum) {
GlobalScope.launch(Dispatchers.IO) {
for (i in 2..9) {
delay(1000)
@ -169,7 +169,7 @@ object ReadBook {
callBack?.upContent()
}
loadContent(durChapterIndex.minus(1), upContent, false)
if (AppConfig.preDownload) {
if (AppConfig.preDownloadNum) {
GlobalScope.launch(Dispatchers.IO) {
for (i in 2..9) {
delay(1000)

@ -72,6 +72,14 @@ class OtherConfigFragment : BasePreferenceFragment(),
override fun onPreferenceTreeClick(preference: Preference?): Boolean {
when (preference?.key) {
PreferKey.userAgent -> showUserAgentDialog()
PreferKey.preDownloadNum -> NumberPickerDialog(requireContext())
.setTitle(getString(R.string.pre_download))
.setMaxValue(9999)
.setMinValue(1)
.setValue(AppConfig.preDownloadNum)
.show {
AppConfig.preDownloadNum = it
}
PreferKey.threadCount -> NumberPickerDialog(requireContext())
.setTitle(getString(R.string.threads_num_title))
.setMaxValue(999)

@ -84,9 +84,7 @@ class MainViewModel(application: Application) : BaseViewModel(application) {
appDb.bookDao.update(book)
appDb.bookChapterDao.delByBook(book.bookUrl)
appDb.bookChapterDao.insert(*toc.toTypedArray())
if (AppConfig.preDownload) {
cacheBook(webBook, book)
}
cacheBook(webBook, book)
}.onError {
it.printStackTrace()
}.onFinally {
@ -114,7 +112,8 @@ class MainViewModel(application: Application) : BaseViewModel(application) {
private fun cacheBook(webBook: WebBook, book: Book) {
execute {
if (book.totalChapterNum > book.durChapterIndex) {
val downloadToIndex = min(book.totalChapterNum, book.durChapterIndex.plus(10))
val downloadToIndex =
min(book.totalChapterNum, book.durChapterIndex.plus(AppConfig.preDownloadNum))
for (i in book.durChapterIndex until downloadToIndex) {
appDb.bookChapterDao.getChapter(book.bookUrl, i)?.let { chapter ->
if (!BookHelp.hasContent(book, chapter)) {

@ -800,7 +800,7 @@
<string name="export_bookshelf">导出书单</string>
<string name="import_bookshelf">导入书单</string>
<string name="pre_download">预下载</string>
<string name="pre_download_s">预先下载10章正文</string>
<string name="pre_download_s">预先下载%d章正文</string>
<string name="sort_enable">启用排序</string>
<string name="background_image">背景图片</string>
<string name="export_folder">导出文件夹</string>

@ -804,7 +804,7 @@
<string name="export_bookshelf">匯出書單</string>
<string name="import_bookshelf">匯入書單</string>
<string name="pre_download">預下載</string>
<string name="pre_download_s">預先下載10章正文</string>
<string name="pre_download_s">預先下載%d章正文</string>
<string name="sort_enable">啟用排序</string>
<string name="background_image">背景圖片</string>
<string name="export_folder">匯出資料夾</string>

@ -804,7 +804,7 @@
<string name="export_bookshelf">导出书单</string>
<string name="import_bookshelf">导入书单</string>
<string name="pre_download">预下载</string>
<string name="pre_download_s">预先下载10章正文</string>
<string name="pre_download_s">预先下载%d章正文</string>
<string name="sort_enable">启用排序</string>
<string name="background_image">背景图片</string>
<string name="export_folder">导出文件夹</string>

@ -805,7 +805,7 @@
<string name="export_bookshelf">导出书单</string>
<string name="import_bookshelf">导入书单</string>
<string name="pre_download">预下载</string>
<string name="pre_download_s">预先下载10章正文</string>
<string name="pre_download_s">预先下载%d章正文</string>
<string name="sort_enable">启用排序</string>
<string name="background_image">背景图片</string>
<string name="export_folder">导出文件夹</string>

@ -61,9 +61,8 @@
android:title="@string/high_brush_title"
android:summary="@string/high_brush_summary" />
<io.legado.app.ui.widget.prefs.SwitchPreference
android:defaultValue="true"
android:key="preDownload"
<io.legado.app.ui.widget.prefs.Preference
android:key="preDownloadNum"
android:title="@string/pre_download"
android:summary="@string/pre_download_s" />

Loading…
Cancel
Save