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