Enable image caching by default and set size to 20MB
This commit is contained in:
parent
a7e63eb1bb
commit
cce2513c7e
3 changed files with 13 additions and 9 deletions
|
@ -9,21 +9,19 @@ import com.bumptech.glide.load.engine.DiskCacheStrategy.RESOURCE
|
||||||
import com.bumptech.glide.load.engine.cache.InternalCacheDiskCacheFactory
|
import com.bumptech.glide.load.engine.cache.InternalCacheDiskCacheFactory
|
||||||
import com.bumptech.glide.module.AppGlideModule
|
import com.bumptech.glide.module.AppGlideModule
|
||||||
import com.bumptech.glide.request.RequestOptions
|
import com.bumptech.glide.request.RequestOptions
|
||||||
|
import dev.jdtech.jellyfin.utils.Constants
|
||||||
import kotlinx.coroutines.MainScope
|
import kotlinx.coroutines.MainScope
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
import timber.log.Timber
|
import timber.log.Timber
|
||||||
|
|
||||||
private const val cacheDefaultSize = 250
|
|
||||||
|
|
||||||
@GlideModule
|
@GlideModule
|
||||||
class GlideModule : AppGlideModule() {
|
class GlideModule : AppGlideModule() {
|
||||||
|
|
||||||
override fun applyOptions(context: Context, builder: GlideBuilder) {
|
override fun applyOptions(context: Context, builder: GlideBuilder) {
|
||||||
val preferences = PreferenceManager.getDefaultSharedPreferences(context)
|
val preferences = PreferenceManager.getDefaultSharedPreferences(context)
|
||||||
val use = preferences.getBoolean("use_image_cache", false)
|
val use = preferences.getBoolean(Constants.PREF_IMAGE_CACHE, true)
|
||||||
|
|
||||||
if (use) {
|
if (use) {
|
||||||
val sizeMb = preferences.getString("image_cache_size", "$cacheDefaultSize")?.toInt()!!
|
val sizeMb = preferences.getString(Constants.PREF_IMAGE_CACHE_SIZE, "${Constants.DEFAULT_CACHE_SIZE}")?.toInt()!!
|
||||||
val sizeB = 1024L * 1024 * sizeMb
|
val sizeB = 1024L * 1024 * sizeMb
|
||||||
Timber.d("Setting image cache to use $sizeMb MB of disk space")
|
Timber.d("Setting image cache to use $sizeMb MB of disk space")
|
||||||
|
|
||||||
|
|
|
@ -11,4 +11,9 @@ object Constants {
|
||||||
const val PREF_PLAYER_GESTURES = "pref_player_gestures"
|
const val PREF_PLAYER_GESTURES = "pref_player_gestures"
|
||||||
const val PREF_PLAYER_BRIGHTNESS_REMEMBER = "pref_player_brightness_remember"
|
const val PREF_PLAYER_BRIGHTNESS_REMEMBER = "pref_player_brightness_remember"
|
||||||
const val PREF_PLAYER_BRIGHTNESS = "pref_player_brightness"
|
const val PREF_PLAYER_BRIGHTNESS = "pref_player_brightness"
|
||||||
|
const val PREF_IMAGE_CACHE = "pref_image_cache"
|
||||||
|
const val PREF_IMAGE_CACHE_SIZE = "pref_image_cache_size"
|
||||||
|
|
||||||
|
// caching
|
||||||
|
const val DEFAULT_CACHE_SIZE = 20
|
||||||
}
|
}
|
|
@ -1,14 +1,15 @@
|
||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<PreferenceScreen xmlns:app="http://schemas.android.com/apk/res-auto">
|
<PreferenceScreen xmlns:app="http://schemas.android.com/apk/res-auto">
|
||||||
<SwitchPreference
|
<SwitchPreference
|
||||||
app:key="use_image_cache"
|
app:defaultValue="true"
|
||||||
|
app:key="pref_image_cache"
|
||||||
app:summary="@string/settings_use_cache_summary"
|
app:summary="@string/settings_use_cache_summary"
|
||||||
app:title="@string/settings_use_cache_title" />
|
app:title="@string/settings_use_cache_title" />
|
||||||
<EditTextPreference
|
<EditTextPreference
|
||||||
app:defaultValue="250"
|
app:defaultValue="20"
|
||||||
app:dependency="use_image_cache"
|
app:dependency="pref_image_cache"
|
||||||
app:dialogMessage="@string/settings_cache_size_message"
|
app:dialogMessage="@string/settings_cache_size_message"
|
||||||
app:key="image_cache_size"
|
app:key="pref_image_cache_size"
|
||||||
app:title="@string/settings_cache_size"
|
app:title="@string/settings_cache_size"
|
||||||
app:useSimpleSummaryProvider="true" />
|
app:useSimpleSummaryProvider="true" />
|
||||||
</PreferenceScreen>
|
</PreferenceScreen>
|
Loading…
Reference in a new issue