Adjustments to the lazy initialization of the app

This commit is contained in:
Vitor Pamplona
2025-10-20 18:41:00 -04:00
parent fabec35593
commit a163c4188f
2 changed files with 8 additions and 11 deletions

View File

@@ -248,7 +248,7 @@ class AppModules(
fun contentResolverFn(): ContentResolver = appContext.contentResolver fun contentResolverFn(): ContentResolver = appContext.contentResolver
fun setImageLoader() { fun setImageLoader() {
ImageLoaderSetup.setup(appContext, diskCache, memoryCache) { url -> ImageLoaderSetup.setup(appContext, { diskCache }, { memoryCache }) { url ->
okHttpClients.getHttpClient(roleBasedHttpClientBuilder.shouldUseTorForImageDownload(url)) okHttpClients.getHttpClient(roleBasedHttpClientBuilder.shouldUseTorForImageDownload(url))
} }
} }
@@ -270,15 +270,12 @@ class AppModules(
applicationIOScope.launch { applicationIOScope.launch {
// preloads tor preferences // preloads tor preferences
torPrefs torPrefs
}
// initializes diskcache on an IO thread.
applicationIOScope.launch {
// Sets Coil - Tor - OkHttp link // Sets Coil - Tor - OkHttp link
setImageLoader() setImageLoader()
// prepares coil's disk cache
diskCache
// prepares exoplayer's disk cache
videoCache
} }
// registers to receive events // registers to receive events

View File

@@ -59,15 +59,15 @@ class ImageLoaderSetup {
@OptIn(DelicateCoilApi::class) @OptIn(DelicateCoilApi::class)
fun setup( fun setup(
app: Context, app: Context,
diskCache: DiskCache, diskCache: () -> DiskCache,
memoryCache: MemoryCache, memoryCache: () -> MemoryCache,
callFactory: (url: String) -> Call.Factory, callFactory: (url: String) -> Call.Factory,
) { ) {
SingletonImageLoader.setUnsafe( SingletonImageLoader.setUnsafe(
ImageLoader ImageLoader
.Builder(app) .Builder(app)
.diskCache { diskCache } .diskCache(diskCache)
.memoryCache { memoryCache } .memoryCache(memoryCache)
.precision(Precision.INEXACT) .precision(Precision.INEXACT)
.logger(debugLogger) .logger(debugLogger)
.components { .components {