Код: Выделить всё
@Module
@InstallIn(SingletonComponent::class)
object AppModule {
/*
@Singleton
TR -> Tüm uygulamada oluşturulan tek örnek kullanılacak bir daha instance oluşturmayacak ---silinebilir
EN -> The only instance created in the entire application will be used and will not create another instance ---can be deleted
*/
private var retrofitInstance: Retrofit? = null
private fun createRetrofitInstance(): Retrofit{
val okHttpClient = OkHttpClient.Builder()
.connectTimeout(1, TimeUnit.MINUTES)
.readTimeout(1, TimeUnit.MINUTES)
.writeTimeout(1, TimeUnit.MINUTES)
.apply {
if (**Utils.isDeveloper**) { // Chuck On/Off Preference
addInterceptor(ChuckInterceptor(Utils.context))
}
}
.build()
return Retrofit.Builder()
.baseUrl(WebServiceUtils.generateBaseUrl())
.addConverterFactory(GsonConverterFactory.create())
.client(okHttpClient)
.build()
}`
fun updateRetrofitInstance() {
retrofitInstance = createRetrofitInstance()
}
@Provides
fun provideRetrofitInstance(): Retrofit {
if (retrofitInstance == null) {
retrofitInstance = createRetrofitInstance()
}
return retrofitInstance!!
}
@Provides
fun provideTransactionService(retrofit: Retrofit): TransferRestInterface{
return retrofit.create(TransferRestInterface::class.java)
}
}
Код: Выделить всё
apply {
if (Utils.isDeveloper) { // Chuck On/Off Preference
addInterceptor(ChuckInterceptor(Utils.context))
}
}
Причина этого заключается в том, что при первом открытии программы следующая часть работает:
Код: Выделить всё
@Provides
fun provideTransactionService(retrofit: Retrofit): TransferRestInterface{
return retrofit.create(TransferRestInterface::class.java)
}
Подробнее здесь: https://stackoverflow.com/questions/783 ... ialization
Мобильная версия