oligazar
6/22/2017 - 12:01 PM

Stetho

Stetho

**
 * Created by Admin on 6/22/17.
 * In debug build variant it will set up Stetho to use.
 * in release build variant it will do nothing
 * if you put file into debug folder of main directory make sure to delete file with
 * the same name from the main directory as it will lead to conflict
 */
 
 /** Also see gradle and proguard gists
 */
 // release build variant
object StethoUtils {

    fun install(application: Application) {
        // In release build variant do nothing
    }
}

// debug bild variant
object StethoUtils {

    fun install(application: Application) {
        Stetho.initialize(
                Stetho.newInitializerBuilder(application)
                        .enableDumpapp(Stetho.defaultDumperPluginsProvider(application))
//                        .enableWebKitInspector(Stetho.defaultInspectorModulesProvider(application))
                        .enableWebKitInspector(RealmInspectorModulesProvider.builder(application).build())
                        .build())
    }
}
 // This goes into debug folder under src folder 
 // The another one that sits in release folder doesn't add StethoInterceptor
 @Provides
    @Singleton
    fun provideOkHttpClient(cache: Cache): OkHttpClient {
        val interceptor = HttpLoggingInterceptor()
        interceptor.level = HttpLoggingInterceptor.Level.BODY
        return OkHttpClient.Builder()
                .addInterceptor(interceptor)
                // You should add Stetho interceptor only in debug build variant
                .addNetworkInterceptor(StethoInterceptor())
                .cache(cache)
//                .connectTimeout(30, TimeUnit.SECONDS)
//                .readTimeout(30, TimeUnit.SECONDS)
//                .writeTimeout(30, TimeUnit.SECONDS)
                .build()
    }