mirror of
https://github.com/gedoor/legado.git
synced 2025-08-10 00:52:30 +00:00
feat(ImageProvider): add bitmapLrucache size setting
This commit is contained in:
@@ -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"
|
||||
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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<String, Bitmap>(cacheSize) {
|
||||
|
||||
override fun sizeOf(key: String, bitmap: Bitmap): Int {
|
||||
|
||||
@@ -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<DirectLinkUploadConfig>()
|
||||
PreferKey.checkSource -> showDialogFragment<CheckSourceConfig>()
|
||||
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.
|
||||
|
||||
@@ -988,5 +988,7 @@
|
||||
<string name="download_book_fail">Download Fail</string>
|
||||
<string name="upload_to_remote">Upload</string>
|
||||
<string name="add_remote_book">WebDavBook</string>
|
||||
<string name="bitmap_cache_size_summary">Current cache max size %1$s MB</string>
|
||||
<string name="bitmap_cache_size">bitmap cache size</string>
|
||||
<!-- string end -->
|
||||
</resources>
|
||||
|
||||
@@ -991,5 +991,7 @@
|
||||
<string name="download_book_fail">Download Fail</string>
|
||||
<string name="upload_to_remote">Upload</string>
|
||||
<string name="add_remote_book">WebDavBook</string>
|
||||
<string name="bitmap_cache_size_summary">Current cache max size %1$s MB</string>
|
||||
<string name="bitmap_cache_size">bitmap cache size</string>
|
||||
<!-- string end -->
|
||||
</resources>
|
||||
|
||||
@@ -991,5 +991,7 @@
|
||||
<string name="download_book_fail">Download Fail</string>
|
||||
<string name="upload_to_remote">Upload</string>
|
||||
<string name="add_remote_book">WebDavBook</string>
|
||||
<string name="bitmap_cache_size_summary">Current cache max size %1$s MB</string>
|
||||
<string name="bitmap_cache_size">bitmap cache size</string>
|
||||
<!-- string end -->
|
||||
</resources>
|
||||
|
||||
@@ -988,5 +988,8 @@
|
||||
<string name="download_book_fail">Download Fail</string>
|
||||
<string name="upload_to_remote">Upload</string>
|
||||
<string name="add_remote_book">WebDav书籍</string>
|
||||
<string name="bitmap_cache_size_summary">当前最大缓存 %1$s MB</string>
|
||||
<string name="bitmap_cache_size">图片绘制缓存</string>
|
||||
|
||||
<!-- string end -->
|
||||
</resources>
|
||||
|
||||
@@ -990,5 +990,8 @@
|
||||
<string name="download_book_fail">Download Fail</string>
|
||||
<string name="upload_to_remote">Upload</string>
|
||||
<string name="add_remote_book">WebDav书籍</string>
|
||||
<string name="bitmap_cache_size_summary">当前最大缓存 %1$s MB</string>
|
||||
<string name="bitmap_cache_size">图片绘制缓存</string>
|
||||
|
||||
<!-- string end -->
|
||||
</resources>
|
||||
|
||||
@@ -990,5 +990,8 @@
|
||||
<string name="download_book_fail">Download Fail</string>
|
||||
<string name="upload_to_remote">上传WebDav</string>
|
||||
<string name="add_remote_book">WebDav书籍</string>
|
||||
<string name="bitmap_cache_size_summary">当前最大缓存 %1$s MB</string>
|
||||
<string name="bitmap_cache_size">图片绘制缓存</string>
|
||||
|
||||
<!-- string end -->
|
||||
</resources>
|
||||
|
||||
@@ -991,5 +991,7 @@
|
||||
<string name="download_book_fail">Download Fail</string>
|
||||
<string name="upload_to_remote">Upload</string>
|
||||
<string name="add_remote_book">WebDavBook</string>
|
||||
<string name="bitmap_cache_size_summary">Current cache max size %1$s MB</string>
|
||||
<string name="bitmap_cache_size">bitmap cache size</string>
|
||||
<!-- string end -->
|
||||
</resources>
|
||||
|
||||
@@ -75,12 +75,18 @@
|
||||
android:key="Cronet"
|
||||
android:summary="@string/pref_cronet_summary"
|
||||
android:title="Cronet" />
|
||||
|
||||
<io.legado.app.lib.prefs.SwitchPreference
|
||||
android:defaultValue="false"
|
||||
android:key="antiAlias"
|
||||
android:summary="@string/pref_anti_alias_summary"
|
||||
android:title="@string/anti_alias" />
|
||||
|
||||
<io.legado.app.lib.prefs.Preference
|
||||
android:key="bitmapCacheSize"
|
||||
android:summary="@string/bitmap_cache_size_summary"
|
||||
android:title="@string/bitmap_cache_size" />
|
||||
|
||||
<io.legado.app.lib.prefs.Preference
|
||||
android:key="preDownloadNum"
|
||||
android:summary="@string/pre_download_s"
|
||||
|
||||
Reference in New Issue
Block a user