diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/AppModules.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/AppModules.kt index 241ffd9a7..51d780ae9 100644 --- a/amethyst/src/main/java/com/vitorpamplona/amethyst/AppModules.kt +++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/AppModules.kt @@ -248,7 +248,7 @@ class AppModules( fun contentResolverFn(): ContentResolver = appContext.contentResolver fun setImageLoader() { - ImageLoaderSetup.setup(appContext, diskCache, memoryCache) { url -> + ImageLoaderSetup.setup(appContext, { diskCache }, { memoryCache }) { url -> okHttpClients.getHttpClient(roleBasedHttpClientBuilder.shouldUseTorForImageDownload(url)) } } @@ -270,15 +270,12 @@ class AppModules( applicationIOScope.launch { // preloads tor preferences torPrefs + } + // initializes diskcache on an IO thread. + applicationIOScope.launch { // Sets Coil - Tor - OkHttp link setImageLoader() - - // prepares coil's disk cache - diskCache - - // prepares exoplayer's disk cache - videoCache } // registers to receive events diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/service/images/ImageLoaderSetup.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/service/images/ImageLoaderSetup.kt index 46edbff4e..49b9b3ada 100644 --- a/amethyst/src/main/java/com/vitorpamplona/amethyst/service/images/ImageLoaderSetup.kt +++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/service/images/ImageLoaderSetup.kt @@ -59,15 +59,15 @@ class ImageLoaderSetup { @OptIn(DelicateCoilApi::class) fun setup( app: Context, - diskCache: DiskCache, - memoryCache: MemoryCache, + diskCache: () -> DiskCache, + memoryCache: () -> MemoryCache, callFactory: (url: String) -> Call.Factory, ) { SingletonImageLoader.setUnsafe( ImageLoader .Builder(app) - .diskCache { diskCache } - .memoryCache { memoryCache } + .diskCache(diskCache) + .memoryCache(memoryCache) .precision(Precision.INEXACT) .logger(debugLogger) .components {