From b6bf3edb96bec42e5fb2286b326976629901520d Mon Sep 17 00:00:00 2001 From: Ridho Fahrorozi Hasyim Date: Tue, 16 Nov 2021 09:55:52 +0700 Subject: [PATCH] add Chuck Interceptor --- app/build.gradle | 4 ++++ .../java/com/mindorks/framework/mvvm/di/module/AppModule.kt | 6 ++++-- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index fdd52d9..b76e552 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -65,4 +65,8 @@ dependencies { implementation "org.jetbrains.kotlinx:kotlinx-coroutines-android:1.3.6" implementation "org.jetbrains.kotlinx:kotlinx-coroutines-core:1.3.6" + //Chuck Interceptor + debugImplementation 'com.readystatesoftware.chuck:library:1.1.0' + releaseImplementation 'com.readystatesoftware.chuck:library-no-op:1.1.0' + } diff --git a/app/src/main/java/com/mindorks/framework/mvvm/di/module/AppModule.kt b/app/src/main/java/com/mindorks/framework/mvvm/di/module/AppModule.kt index db1977e..ccbb370 100644 --- a/app/src/main/java/com/mindorks/framework/mvvm/di/module/AppModule.kt +++ b/app/src/main/java/com/mindorks/framework/mvvm/di/module/AppModule.kt @@ -6,6 +6,7 @@ import com.mindorks.framework.mvvm.data.api.ApiHelper import com.mindorks.framework.mvvm.data.api.ApiHelperImpl import com.mindorks.framework.mvvm.data.api.ApiService import com.mindorks.framework.mvvm.utils.NetworkHelper +import com.readystatesoftware.chuck.ChuckInterceptor import okhttp3.OkHttpClient import okhttp3.logging.HttpLoggingInterceptor import org.koin.android.ext.koin.androidContext @@ -14,7 +15,7 @@ import retrofit2.Retrofit import retrofit2.converter.moshi.MoshiConverterFactory val appModule = module { - single { provideOkHttpClient() } + single { provideOkHttpClient(androidContext()) } single { provideRetrofit(get(), BuildConfig.BASE_URL) } single { provideApiService(get()) } single { provideNetworkHelper(androidContext()) } @@ -26,11 +27,12 @@ val appModule = module { private fun provideNetworkHelper(context: Context) = NetworkHelper(context) -private fun provideOkHttpClient() = if (BuildConfig.DEBUG) { +private fun provideOkHttpClient(context: Context) = if (BuildConfig.DEBUG) { val loggingInterceptor = HttpLoggingInterceptor() loggingInterceptor.setLevel(HttpLoggingInterceptor.Level.BODY) OkHttpClient.Builder() .addInterceptor(loggingInterceptor) + .addInterceptor(ChuckInterceptor(context)) .build() } else OkHttpClient .Builder()