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 588ca8581..ccb32a3af 100644 --- a/app/src/main/java/io/legado/app/constant/PreferKey.kt +++ b/app/src/main/java/io/legado/app/constant/PreferKey.kt @@ -82,6 +82,7 @@ object PreferKey { const val syncBookProgress = "syncBookProgress" const val cronet = "Cronet" const val antiAlias = "antiAlias" + const val bitmapCacheSize = "bitmapCacheSize" const val preDownloadNum = "preDownloadNum" const val autoRefresh = "auto_refresh" const val defaultToRead = "defaultToRead" @@ -107,7 +108,6 @@ object PreferKey { const val welcomeShowIcon = "welcomeShowIcon" const val welcomeShowIconDark = "welcomeShowIconDark" - const val cPrimary = "colorPrimary" const val cAccent = "colorAccent" const val cBackground = "colorBackground" @@ -121,4 +121,5 @@ object PreferKey { const val cNBBackground = "colorBottomBackgroundNight" const val bgImageN = "backgroundImageNight" const val bgImageNBlurring = "backgroundImageNightBlurring" + } diff --git a/app/src/main/java/io/legado/app/help/config/AppConfig.kt b/app/src/main/java/io/legado/app/help/config/AppConfig.kt index f36decf1d..05e2c80b6 100644 --- a/app/src/main/java/io/legado/app/help/config/AppConfig.kt +++ b/app/src/main/java/io/legado/app/help/config/AppConfig.kt @@ -323,5 +323,11 @@ object AppConfig : SharedPreferences.OnSharedPreferenceChangeListener { } return ua } + + var bitmapCacheSize: Int + get() = appCtx.getPrefInt(PreferKey.bitmapCacheSize, 50) + set(value) { + appCtx.putPrefInt(PreferKey.bitmapCacheSize, value) + } } diff --git a/app/src/main/java/io/legado/app/ui/book/read/page/provider/ImageProvider.kt b/app/src/main/java/io/legado/app/ui/book/read/page/provider/ImageProvider.kt index 7ecfe83f5..df88392a1 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/page/provider/ImageProvider.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/page/provider/ImageProvider.kt @@ -11,6 +11,7 @@ import io.legado.app.data.entities.BookSource import io.legado.app.exception.NoStackTraceException import io.legado.app.help.BookHelp import io.legado.app.help.coroutine.Coroutine +import io.legado.app.help.config.AppConfig import io.legado.app.model.localBook.EpubFile import io.legado.app.utils.BitmapUtils import io.legado.app.utils.FileUtils @@ -32,8 +33,7 @@ object ImageProvider { *缓存bitmap LruCache实现 */ private const val M = 1024 * 1024 - private val cacheSize = - max(50 * M, min(100 * M, (Runtime.getRuntime().maxMemory() / 8).toInt())) + private val cacheSize = AppConfig.bitmapCacheSize * M val bitmapLruCache = object : LruCache(cacheSize) { override fun sizeOf(key: String, bitmap: Bitmap): Int { 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 5ffdede56..f65123720 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 @@ -56,6 +56,7 @@ class OtherConfigFragment : PreferenceFragment(), upPreferenceSummary(PreferKey.defaultBookTreeUri, it) } upPreferenceSummary(PreferKey.checkSource, CheckSource.summary) + upPreferenceSummary(PreferKey.bitmapCacheSize, AppConfig.bitmapCacheSize.toString()) } override fun onViewCreated(view: View, savedInstanceState: Bundle?) { @@ -104,6 +105,14 @@ class OtherConfigFragment : PreferenceFragment(), PreferKey.cleanCache -> clearCache() PreferKey.uploadRule -> showDialogFragment() PreferKey.checkSource -> showDialogFragment() + PreferKey.bitmapCacheSize -> NumberPickerDialog(requireContext()) + .setTitle(getString(R.string.bitmap_cache_size)) + .setMaxValue(9999) + .setMinValue(1) + .setValue(AppConfig.bitmapCacheSize) + .show { + AppConfig.bitmapCacheSize = it + } } return super.onPreferenceTreeClick(preference) } @@ -141,6 +150,11 @@ class OtherConfigFragment : PreferenceFragment(), PreferKey.checkSource -> listView.post { upPreferenceSummary(PreferKey.checkSource, CheckSource.summary) } + PreferKey.bitmapCacheSize -> { + upPreferenceSummary(key, AppConfig.bitmapCacheSize.toString()) + // restart to apply changes + appCtx.restart() + } } } @@ -151,6 +165,7 @@ class OtherConfigFragment : PreferenceFragment(), getString(R.string.pre_download_s, value) PreferKey.threadCount -> preference.summary = getString(R.string.threads_num, value) PreferKey.webPort -> preference.summary = getString(R.string.web_port_summary, value) + PreferKey.bitmapCacheSize -> preference.summary = getString(R.string.bitmap_cache_size_summary, value) else -> if (preference is ListPreference) { val index = preference.findIndexOfValue(value) // Set the summary to reflect the new value. diff --git a/app/src/main/res/values-es-rES/strings.xml b/app/src/main/res/values-es-rES/strings.xml index 310ecd7f4..4ff5bd117 100644 --- a/app/src/main/res/values-es-rES/strings.xml +++ b/app/src/main/res/values-es-rES/strings.xml @@ -988,5 +988,7 @@ Download Fail Upload WebDavBook + Current cache max size %1$s MB + bitmap cache size diff --git a/app/src/main/res/values-ja-rJP/strings.xml b/app/src/main/res/values-ja-rJP/strings.xml index 68498160f..6e4dcc414 100644 --- a/app/src/main/res/values-ja-rJP/strings.xml +++ b/app/src/main/res/values-ja-rJP/strings.xml @@ -991,5 +991,7 @@ Download Fail Upload WebDavBook + Current cache max size %1$s MB + bitmap cache size diff --git a/app/src/main/res/values-pt-rBR/strings.xml b/app/src/main/res/values-pt-rBR/strings.xml index 7551b7740..389fd7309 100644 --- a/app/src/main/res/values-pt-rBR/strings.xml +++ b/app/src/main/res/values-pt-rBR/strings.xml @@ -991,5 +991,7 @@ Download Fail Upload WebDavBook + Current cache max size %1$s MB + bitmap cache size diff --git a/app/src/main/res/values-zh-rHK/strings.xml b/app/src/main/res/values-zh-rHK/strings.xml index 6d8cc2c37..80381c88c 100644 --- a/app/src/main/res/values-zh-rHK/strings.xml +++ b/app/src/main/res/values-zh-rHK/strings.xml @@ -988,5 +988,8 @@ Download Fail Upload WebDav书籍 + 当前最大缓存 %1$s MB + 图片绘制缓存 + diff --git a/app/src/main/res/values-zh-rTW/strings.xml b/app/src/main/res/values-zh-rTW/strings.xml index 3952f76b2..d7026631b 100644 --- a/app/src/main/res/values-zh-rTW/strings.xml +++ b/app/src/main/res/values-zh-rTW/strings.xml @@ -990,5 +990,8 @@ Download Fail Upload WebDav书籍 + 当前最大缓存 %1$s MB + 图片绘制缓存 + diff --git a/app/src/main/res/values-zh/strings.xml b/app/src/main/res/values-zh/strings.xml index ca9c6c14b..79233a087 100644 --- a/app/src/main/res/values-zh/strings.xml +++ b/app/src/main/res/values-zh/strings.xml @@ -990,5 +990,8 @@ Download Fail 上传WebDav WebDav书籍 + 当前最大缓存 %1$s MB + 图片绘制缓存 + diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 93c683137..59d97e45a 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -991,5 +991,7 @@ Download Fail Upload WebDavBook + Current cache max size %1$s MB + bitmap cache size diff --git a/app/src/main/res/xml/pref_config_other.xml b/app/src/main/res/xml/pref_config_other.xml index 931deb5f9..8da45d5a6 100644 --- a/app/src/main/res/xml/pref_config_other.xml +++ b/app/src/main/res/xml/pref_config_other.xml @@ -75,12 +75,18 @@ android:key="Cronet" android:summary="@string/pref_cronet_summary" android:title="Cronet" /> + + +