|
|
|
@ -17,6 +17,7 @@
|
|
|
|
|
package com.google.samples.apps.nowinandroid.core.network.di
|
|
|
|
|
|
|
|
|
|
import android.content.Context
|
|
|
|
|
import androidx.tracing.trace
|
|
|
|
|
import coil.ImageLoader
|
|
|
|
|
import coil.decode.SvgDecoder
|
|
|
|
|
import coil.util.DebugLogger
|
|
|
|
@ -51,7 +52,8 @@ internal object NetworkModule {
|
|
|
|
|
|
|
|
|
|
@Provides
|
|
|
|
|
@Singleton
|
|
|
|
|
fun okHttpCallFactory(): Call.Factory = OkHttpClient.Builder()
|
|
|
|
|
fun okHttpCallFactory(): Call.Factory = trace("NiaOkHttpClient") {
|
|
|
|
|
OkHttpClient.Builder()
|
|
|
|
|
.addInterceptor(
|
|
|
|
|
HttpLoggingInterceptor()
|
|
|
|
|
.apply {
|
|
|
|
@ -61,6 +63,7 @@ internal object NetworkModule {
|
|
|
|
|
},
|
|
|
|
|
)
|
|
|
|
|
.build()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Since we're displaying SVGs in the app, Coil needs an ImageLoader which supports this
|
|
|
|
@ -72,13 +75,13 @@ internal object NetworkModule {
|
|
|
|
|
@Provides
|
|
|
|
|
@Singleton
|
|
|
|
|
fun imageLoader(
|
|
|
|
|
okHttpCallFactory: Call.Factory,
|
|
|
|
|
// We specifically request dagger.Lazy here, so that it's not instantiated from Dagger.
|
|
|
|
|
okHttpCallFactory: dagger.Lazy<Call.Factory>,
|
|
|
|
|
@ApplicationContext application: Context,
|
|
|
|
|
): ImageLoader = ImageLoader.Builder(application)
|
|
|
|
|
.callFactory(okHttpCallFactory)
|
|
|
|
|
.components {
|
|
|
|
|
add(SvgDecoder.Factory())
|
|
|
|
|
}
|
|
|
|
|
): ImageLoader = trace("NiaImageLoader") {
|
|
|
|
|
ImageLoader.Builder(application)
|
|
|
|
|
.callFactory { okHttpCallFactory.get() }
|
|
|
|
|
.components { add(SvgDecoder.Factory()) }
|
|
|
|
|
// Assume most content images are versioned urls
|
|
|
|
|
// but some problematic images are fetching each time
|
|
|
|
|
.respectCacheHeaders(false)
|
|
|
|
@ -88,4 +91,5 @@ internal object NetworkModule {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
.build()
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|