feat(ImageProvider): add bitmapLrucache size setting

pull/1921/head
Xwite 3 years ago
parent caa36f1f23
commit 83bc051f79
  1. 3
      app/src/main/java/io/legado/app/constant/PreferKey.kt
  2. 6
      app/src/main/java/io/legado/app/help/config/AppConfig.kt
  3. 4
      app/src/main/java/io/legado/app/ui/book/read/page/provider/ImageProvider.kt
  4. 15
      app/src/main/java/io/legado/app/ui/config/OtherConfigFragment.kt
  5. 2
      app/src/main/res/values-es-rES/strings.xml
  6. 2
      app/src/main/res/values-ja-rJP/strings.xml
  7. 2
      app/src/main/res/values-pt-rBR/strings.xml
  8. 3
      app/src/main/res/values-zh-rHK/strings.xml
  9. 3
      app/src/main/res/values-zh-rTW/strings.xml
  10. 3
      app/src/main/res/values-zh/strings.xml
  11. 2
      app/src/main/res/values/strings.xml
  12. 6
      app/src/main/res/xml/pref_config_other.xml

@ -82,6 +82,7 @@ object PreferKey {
const val syncBookProgress = "syncBookProgress" const val syncBookProgress = "syncBookProgress"
const val cronet = "Cronet" const val cronet = "Cronet"
const val antiAlias = "antiAlias" const val antiAlias = "antiAlias"
const val bitmapCacheSize = "bitmapCacheSize"
const val preDownloadNum = "preDownloadNum" const val preDownloadNum = "preDownloadNum"
const val autoRefresh = "auto_refresh" const val autoRefresh = "auto_refresh"
const val defaultToRead = "defaultToRead" const val defaultToRead = "defaultToRead"
@ -107,7 +108,6 @@ object PreferKey {
const val welcomeShowIcon = "welcomeShowIcon" const val welcomeShowIcon = "welcomeShowIcon"
const val welcomeShowIconDark = "welcomeShowIconDark" const val welcomeShowIconDark = "welcomeShowIconDark"
const val cPrimary = "colorPrimary" const val cPrimary = "colorPrimary"
const val cAccent = "colorAccent" const val cAccent = "colorAccent"
const val cBackground = "colorBackground" const val cBackground = "colorBackground"
@ -121,4 +121,5 @@ object PreferKey {
const val cNBBackground = "colorBottomBackgroundNight" const val cNBBackground = "colorBottomBackgroundNight"
const val bgImageN = "backgroundImageNight" const val bgImageN = "backgroundImageNight"
const val bgImageNBlurring = "backgroundImageNightBlurring" const val bgImageNBlurring = "backgroundImageNightBlurring"
} }

@ -323,5 +323,11 @@ object AppConfig : SharedPreferences.OnSharedPreferenceChangeListener {
} }
return ua 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.exception.NoStackTraceException
import io.legado.app.help.BookHelp import io.legado.app.help.BookHelp
import io.legado.app.help.coroutine.Coroutine 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.model.localBook.EpubFile
import io.legado.app.utils.BitmapUtils import io.legado.app.utils.BitmapUtils
import io.legado.app.utils.FileUtils import io.legado.app.utils.FileUtils
@ -32,8 +33,7 @@ object ImageProvider {
*缓存bitmap LruCache实现 *缓存bitmap LruCache实现
*/ */
private const val M = 1024 * 1024 private const val M = 1024 * 1024
private val cacheSize = private val cacheSize = AppConfig.bitmapCacheSize * M
max(50 * M, min(100 * M, (Runtime.getRuntime().maxMemory() / 8).toInt()))
val bitmapLruCache = object : LruCache<String, Bitmap>(cacheSize) { val bitmapLruCache = object : LruCache<String, Bitmap>(cacheSize) {
override fun sizeOf(key: String, bitmap: Bitmap): Int { override fun sizeOf(key: String, bitmap: Bitmap): Int {

@ -56,6 +56,7 @@ class OtherConfigFragment : PreferenceFragment(),
upPreferenceSummary(PreferKey.defaultBookTreeUri, it) upPreferenceSummary(PreferKey.defaultBookTreeUri, it)
} }
upPreferenceSummary(PreferKey.checkSource, CheckSource.summary) upPreferenceSummary(PreferKey.checkSource, CheckSource.summary)
upPreferenceSummary(PreferKey.bitmapCacheSize, AppConfig.bitmapCacheSize.toString())
} }
override fun onViewCreated(view: View, savedInstanceState: Bundle?) { override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
@ -104,6 +105,14 @@ class OtherConfigFragment : PreferenceFragment(),
PreferKey.cleanCache -> clearCache() PreferKey.cleanCache -> clearCache()
PreferKey.uploadRule -> showDialogFragment<DirectLinkUploadConfig>() PreferKey.uploadRule -> showDialogFragment<DirectLinkUploadConfig>()
PreferKey.checkSource -> showDialogFragment<CheckSourceConfig>() 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) return super.onPreferenceTreeClick(preference)
} }
@ -141,6 +150,11 @@ class OtherConfigFragment : PreferenceFragment(),
PreferKey.checkSource -> listView.post { PreferKey.checkSource -> listView.post {
upPreferenceSummary(PreferKey.checkSource, CheckSource.summary) 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) getString(R.string.pre_download_s, value)
PreferKey.threadCount -> preference.summary = getString(R.string.threads_num, value) PreferKey.threadCount -> preference.summary = getString(R.string.threads_num, value)
PreferKey.webPort -> preference.summary = getString(R.string.web_port_summary, 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) { else -> if (preference is ListPreference) {
val index = preference.findIndexOfValue(value) val index = preference.findIndexOfValue(value)
// Set the summary to reflect the new value. // Set the summary to reflect the new value.

@ -988,5 +988,7 @@
<string name="download_book_fail">Download Fail</string> <string name="download_book_fail">Download Fail</string>
<string name="upload_to_remote">Upload</string> <string name="upload_to_remote">Upload</string>
<string name="add_remote_book">WebDavBook</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 --> <!-- string end -->
</resources> </resources>

@ -991,5 +991,7 @@
<string name="download_book_fail">Download Fail</string> <string name="download_book_fail">Download Fail</string>
<string name="upload_to_remote">Upload</string> <string name="upload_to_remote">Upload</string>
<string name="add_remote_book">WebDavBook</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 --> <!-- string end -->
</resources> </resources>

@ -991,5 +991,7 @@
<string name="download_book_fail">Download Fail</string> <string name="download_book_fail">Download Fail</string>
<string name="upload_to_remote">Upload</string> <string name="upload_to_remote">Upload</string>
<string name="add_remote_book">WebDavBook</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 --> <!-- string end -->
</resources> </resources>

@ -988,5 +988,8 @@
<string name="download_book_fail">Download Fail</string> <string name="download_book_fail">Download Fail</string>
<string name="upload_to_remote">Upload</string> <string name="upload_to_remote">Upload</string>
<string name="add_remote_book">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 --> <!-- string end -->
</resources> </resources>

@ -990,5 +990,8 @@
<string name="download_book_fail">Download Fail</string> <string name="download_book_fail">Download Fail</string>
<string name="upload_to_remote">Upload</string> <string name="upload_to_remote">Upload</string>
<string name="add_remote_book">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 --> <!-- string end -->
</resources> </resources>

@ -990,5 +990,8 @@
<string name="download_book_fail">Download Fail</string> <string name="download_book_fail">Download Fail</string>
<string name="upload_to_remote">上传WebDav</string> <string name="upload_to_remote">上传WebDav</string>
<string name="add_remote_book">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 --> <!-- string end -->
</resources> </resources>

@ -991,5 +991,7 @@
<string name="download_book_fail">Download Fail</string> <string name="download_book_fail">Download Fail</string>
<string name="upload_to_remote">Upload</string> <string name="upload_to_remote">Upload</string>
<string name="add_remote_book">WebDavBook</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 --> <!-- string end -->
</resources> </resources>

@ -75,12 +75,18 @@
android:key="Cronet" android:key="Cronet"
android:summary="@string/pref_cronet_summary" android:summary="@string/pref_cronet_summary"
android:title="Cronet" /> android:title="Cronet" />
<io.legado.app.lib.prefs.SwitchPreference <io.legado.app.lib.prefs.SwitchPreference
android:defaultValue="false" android:defaultValue="false"
android:key="antiAlias" android:key="antiAlias"
android:summary="@string/pref_anti_alias_summary" android:summary="@string/pref_anti_alias_summary"
android:title="@string/anti_alias" /> 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 <io.legado.app.lib.prefs.Preference
android:key="preDownloadNum" android:key="preDownloadNum"
android:summary="@string/pre_download_s" android:summary="@string/pre_download_s"

Loading…
Cancel
Save