Reputation: 115
@Module @InstallIn(SingletonComponent::class)
object AppEntryModule {
private val client = OkHttpClient.Builder().apply {
addInterceptor(MyInterceptor( ????? ))
}.build()
@Provides
@Singleton
fun provideRetrofit(): Retrofit =
Retrofit.Builder()
.baseUrl(MOCK_URL)
.client(client)
.addConverterFactory(GsonConverterFactory.create())
.build()
}
class MyInterceptor @Inject constructor( private val viewLifecycleOwner: LifecycleOwner ) : Interceptor { {}
Upvotes: 0
Views: 59
Reputation: 115
I found solution:
object AppEntryModule {
@Provides
@Singleton
fun provideRetrofit(@ApplicationContext appContext: Context): Retrofit {
val client = OkHttpClient.Builder().apply {
addInterceptor(MyInterceptor(MyPreferences(appContext)))
}.build()
return Retrofit.Builder()
.baseUrl(MOCK_URL)
.client(client)
.addConverterFactory(GsonConverterFactory.create())
.build()
}
Upvotes: 0