Disable disk caching when using MediaStore
Since the MediaStore covers are already cached by the android system, disable the auto-caching that Coil uses to save space.
This commit is contained in:
parent
39ba1c38ec
commit
14fc47913e
3 changed files with 27 additions and 1 deletions
|
|
@ -8,6 +8,8 @@ import android.view.WindowInsets
|
|||
import androidx.appcompat.app.AppCompatActivity
|
||||
import androidx.appcompat.app.AppCompatDelegate
|
||||
import androidx.databinding.DataBindingUtil
|
||||
import coil.Coil
|
||||
import org.oxycblt.auxio.coil.createImageLoader
|
||||
import org.oxycblt.auxio.databinding.ActivityMainBinding
|
||||
import org.oxycblt.auxio.playback.PlaybackService
|
||||
import org.oxycblt.auxio.settings.SettingsManager
|
||||
|
|
@ -39,6 +41,8 @@ class MainActivity : AppCompatActivity() {
|
|||
if (isEdgeOn()) {
|
||||
doEdgeToEdgeSetup(binding)
|
||||
}
|
||||
|
||||
Coil.setImageLoader(createImageLoader(applicationContext))
|
||||
}
|
||||
|
||||
override fun onStart() {
|
||||
|
|
|
|||
|
|
@ -3,10 +3,13 @@ package org.oxycblt.auxio.coil
|
|||
import android.content.Context
|
||||
import android.graphics.Bitmap
|
||||
import android.net.Uri
|
||||
import android.util.Log
|
||||
import android.widget.ImageView
|
||||
import androidx.core.graphics.drawable.toBitmap
|
||||
import androidx.databinding.BindingAdapter
|
||||
import coil.Coil
|
||||
import coil.ImageLoader
|
||||
import coil.request.CachePolicy
|
||||
import coil.request.ImageRequest
|
||||
import org.oxycblt.auxio.R
|
||||
import org.oxycblt.auxio.logE
|
||||
|
|
@ -24,6 +27,25 @@ val settingsManager: SettingsManager by lazy {
|
|||
SettingsManager.getInstance()
|
||||
}
|
||||
|
||||
/**
|
||||
* Create the custom [ImageLoader] used by Auxio, which doesn't cache album art to the disk by default.
|
||||
*/
|
||||
fun createImageLoader(context: Context): ImageLoader {
|
||||
Log.d("createImageLoader", "Creating image loader.")
|
||||
|
||||
val builder = ImageLoader.Builder(context)
|
||||
.crossfade(true)
|
||||
|
||||
// To save memory/improve speed, allow disc caching when if quality covers are enabled.
|
||||
if (settingsManager.useQualityCovers) {
|
||||
builder.diskCachePolicy(CachePolicy.ENABLED)
|
||||
} else {
|
||||
builder.diskCachePolicy(CachePolicy.DISABLED)
|
||||
}
|
||||
|
||||
return builder.build()
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a bitmap for a song. onDone will be called when the bitmap is loaded.
|
||||
* **Do not use this on the UI elements, instead use the Binding Adapters.**
|
||||
|
|
|
|||
|
|
@ -68,7 +68,7 @@
|
|||
<string name="setting_show_covers_desc">Turn off to save memory usage</string>
|
||||
|
||||
<string name="setting_quality_covers">Ignore MediaStore covers</string>
|
||||
<string name="setting_quality_covers_desc">Results in higher quality album covers, but causes slower loading times</string>
|
||||
<string name="setting_quality_covers_desc">Results in higher quality album covers at the cost of slower loading times and higher memory usage</string>
|
||||
|
||||
<string name="setting_use_alt_action">Use alternate notification action</string>
|
||||
<string name="setting_use_alt_loop">Prefer repeat mode action</string>
|
||||
|
|
|
|||
Loading…
Reference in a new issue