From 11bf63e6a615400a2a4773dcfdcec9f3f56d1105 Mon Sep 17 00:00:00 2001 From: gedoor Date: Thu, 6 May 2021 17:14:37 +0800 Subject: [PATCH] =?UTF-8?q?=E9=A2=84=E4=B8=8B=E8=BD=BD=E7=AB=A0=E8=8A=82?= =?UTF-8?q?=E5=8F=AF=E8=B0=83=E6=95=B4=E6=95=B0=E7=9B=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/src/main/java/io/legado/app/constant/PreferKey.kt | 2 +- app/src/main/java/io/legado/app/help/AppConfig.kt | 8 ++++++-- app/src/main/java/io/legado/app/service/help/ReadBook.kt | 4 ++-- .../java/io/legado/app/ui/config/OtherConfigFragment.kt | 8 ++++++++ app/src/main/java/io/legado/app/ui/main/MainViewModel.kt | 7 +++---- app/src/main/res/values-zh-rHK/strings.xml | 2 +- app/src/main/res/values-zh-rTW/strings.xml | 2 +- app/src/main/res/values-zh/strings.xml | 2 +- app/src/main/res/values/strings.xml | 2 +- app/src/main/res/xml/pref_config_other.xml | 5 ++--- 10 files changed, 26 insertions(+), 16 deletions(-) diff --git a/app/src/main/java/io/legado/app/constant/PreferKey.kt b/app/src/main/java/io/legado/app/constant/PreferKey.kt index 651830256..bd0e86fc6 100644 --- a/app/src/main/java/io/legado/app/constant/PreferKey.kt +++ b/app/src/main/java/io/legado/app/constant/PreferKey.kt @@ -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" diff --git a/app/src/main/java/io/legado/app/help/AppConfig.kt b/app/src/main/java/io/legado/app/help/AppConfig.kt index cda42eed4..a30f5c614 100644 --- a/app/src/main/java/io/legado/app/help/AppConfig.kt +++ b/app/src/main/java/io/legado/app/help/AppConfig.kt @@ -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) diff --git a/app/src/main/java/io/legado/app/service/help/ReadBook.kt b/app/src/main/java/io/legado/app/service/help/ReadBook.kt index f1f33f4ed..ffb4c8f9b 100644 --- a/app/src/main/java/io/legado/app/service/help/ReadBook.kt +++ b/app/src/main/java/io/legado/app/service/help/ReadBook.kt @@ -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) diff --git a/app/src/main/java/io/legado/app/ui/config/OtherConfigFragment.kt b/app/src/main/java/io/legado/app/ui/config/OtherConfigFragment.kt index 9c09e7620..d5d0b1364 100644 --- a/app/src/main/java/io/legado/app/ui/config/OtherConfigFragment.kt +++ b/app/src/main/java/io/legado/app/ui/config/OtherConfigFragment.kt @@ -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) diff --git a/app/src/main/java/io/legado/app/ui/main/MainViewModel.kt b/app/src/main/java/io/legado/app/ui/main/MainViewModel.kt index 27a140167..48afc90ce 100644 --- a/app/src/main/java/io/legado/app/ui/main/MainViewModel.kt +++ b/app/src/main/java/io/legado/app/ui/main/MainViewModel.kt @@ -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)) { diff --git a/app/src/main/res/values-zh-rHK/strings.xml b/app/src/main/res/values-zh-rHK/strings.xml index cab096ed7..7ae5fa882 100644 --- a/app/src/main/res/values-zh-rHK/strings.xml +++ b/app/src/main/res/values-zh-rHK/strings.xml @@ -800,7 +800,7 @@ 导出书单 导入书单 预下载 - 预先下载10章正文 + 预先下载%d章正文 启用排序 背景图片 导出文件夹 diff --git a/app/src/main/res/values-zh-rTW/strings.xml b/app/src/main/res/values-zh-rTW/strings.xml index 99f5030d0..486ec2e49 100644 --- a/app/src/main/res/values-zh-rTW/strings.xml +++ b/app/src/main/res/values-zh-rTW/strings.xml @@ -804,7 +804,7 @@ 匯出書單 匯入書單 預下載 - 預先下載10章正文 + 預先下載%d章正文 啟用排序 背景圖片 匯出資料夾 diff --git a/app/src/main/res/values-zh/strings.xml b/app/src/main/res/values-zh/strings.xml index 240704cac..f29989897 100644 --- a/app/src/main/res/values-zh/strings.xml +++ b/app/src/main/res/values-zh/strings.xml @@ -804,7 +804,7 @@ 导出书单 导入书单 预下载 - 预先下载10章正文 + 预先下载%d章正文 启用排序 背景图片 导出文件夹 diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index bd230bc1f..ce9bfc9fa 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -805,7 +805,7 @@ 导出书单 导入书单 预下载 - 预先下载10章正文 + 预先下载%d章正文 启用排序 背景图片 导出文件夹 diff --git a/app/src/main/res/xml/pref_config_other.xml b/app/src/main/res/xml/pref_config_other.xml index 66a9cc4fa..8dadf0940 100644 --- a/app/src/main/res/xml/pref_config_other.xml +++ b/app/src/main/res/xml/pref_config_other.xml @@ -61,9 +61,8 @@ android:title="@string/high_brush_title" android:summary="@string/high_brush_summary" /> -