Dont clear ImageLoader on recreation
Make it so that the ImageLoader is only refreshed when the configuration needs to be changed, instead of on every recreation.
This commit is contained in:
parent
6c37ba7d3e
commit
7b0a69f8c0
3 changed files with 24 additions and 15 deletions
|
@ -23,8 +23,6 @@ class MainActivity : AppCompatActivity() {
|
|||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
|
||||
// --- UI SETUP ---
|
||||
|
||||
val binding = DataBindingUtil.setContentView<ActivityMainBinding>(
|
||||
this, R.layout.activity_main
|
||||
)
|
||||
|
@ -42,7 +40,9 @@ class MainActivity : AppCompatActivity() {
|
|||
doEdgeToEdgeSetup(binding)
|
||||
}
|
||||
|
||||
Coil.setImageLoader(createImageLoader(applicationContext))
|
||||
createImageLoader(applicationContext)?.let {
|
||||
Coil.setImageLoader(it)
|
||||
}
|
||||
}
|
||||
|
||||
override fun onStart() {
|
||||
|
|
|
@ -26,24 +26,31 @@ val settingsManager: SettingsManager by lazy {
|
|||
}
|
||||
|
||||
/**
|
||||
* Create the custom [ImageLoader] used by Auxio, which automates some convienence things.
|
||||
* Create the custom [ImageLoader] used by Auxio. Primarily handles whether disk-caching should be done.
|
||||
* @return A new [ImageLoader], null if the current loader already satisfies what is needed.
|
||||
*/
|
||||
fun createImageLoader(context: Context): ImageLoader {
|
||||
fun createImageLoader(context: Context): ImageLoader? {
|
||||
Log.d("createImageLoader", "Creating image loader.")
|
||||
|
||||
val builder = ImageLoader.Builder(context)
|
||||
.crossfade(true)
|
||||
.placeholder(android.R.color.transparent)
|
||||
val currentLoader = Coil.imageLoader(context)
|
||||
|
||||
// To save memory/improve speed, allow disc caching when if quality covers are enabled.
|
||||
// Enable disk caching if quality covers are being used so that its more efficient.
|
||||
// Don't bother if not however, as the covers are already cached on-disk.
|
||||
if (settingsManager.useQualityCovers) {
|
||||
builder.diskCachePolicy(CachePolicy.ENABLED)
|
||||
} else {
|
||||
// Otherwise disable it since the covers are already cached, really.
|
||||
builder.diskCachePolicy(CachePolicy.DISABLED)
|
||||
}
|
||||
if (currentLoader.defaults.diskCachePolicy != CachePolicy.ENABLED) {
|
||||
builder.diskCachePolicy(CachePolicy.ENABLED)
|
||||
|
||||
return builder.build()
|
||||
return builder.build()
|
||||
}
|
||||
} else {
|
||||
if (currentLoader.defaults.diskCachePolicy != CachePolicy.DISABLED) {
|
||||
builder.diskCachePolicy(CachePolicy.DISABLED)
|
||||
|
||||
return builder.build()
|
||||
}
|
||||
}
|
||||
return null
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -223,5 +230,7 @@ fun ImageRequest.Builder.doCoverSetup(context: Context, data: BaseModel): ImageR
|
|||
*/
|
||||
private fun ImageView.getDefaultRequest(): ImageRequest.Builder {
|
||||
return ImageRequest.Builder(context)
|
||||
.crossfade(true)
|
||||
.placeholder(android.R.color.transparent)
|
||||
.target(this)
|
||||
}
|
||||
|
|
|
@ -31,7 +31,7 @@ class MosaicFetcher(private val context: Context) : Fetcher<List<Uri>> {
|
|||
val streams = mutableListOf<InputStream>()
|
||||
|
||||
// Load the streams, the lower-quality MediaStore covers are used simply because using
|
||||
// the raw ones would make loading far too long. Its not that noticable either.
|
||||
// the raw ones would make loading far too long. Its not that noticeable either.
|
||||
data.forEach {
|
||||
val stream: InputStream? = context.contentResolver.openInputStream(it)
|
||||
|
||||
|
|
Loading…
Reference in a new issue