Skip to content

Instantly share code, notes, and snippets.

@mohsenoid
Last active February 4, 2018 17:36
Show Gist options
  • Save mohsenoid/a70507c1bdb5f9cef4bf2aa119878614 to your computer and use it in GitHub Desktop.
Save mohsenoid/a70507c1bdb5f9cef4bf2aa119878614 to your computer and use it in GitHub Desktop.
package com.mirhoseini.stylight.domain;
/*...*/
@Module
public class ClientModule {
/*...*/
@Singleton
@Provides
public OkHttpClient provideOkHttpClient(HttpLoggingInterceptor loggingInterceptor,
@Named("networkTimeoutInSeconds") int networkTimeoutInSeconds,
@Named("isDebug") boolean isDebug,
Cache cache,
@Named("cacheInterceptor") Interceptor cacheInterceptor,
@Named("offlineInterceptor") Interceptor offlineCacheInterceptor,
@Named("retryInterceptor") Interceptor retryInterceptor) {
OkHttpClient.Builder okHttpClient = new OkHttpClient.Builder()
.addNetworkInterceptor(cacheInterceptor)
.addInterceptor(offlineCacheInterceptor)
.addInterceptor(retryInterceptor)
.cache(cache)
.connectTimeout(networkTimeoutInSeconds, TimeUnit.SECONDS);
//show logs if app is in Debug mode
if (isDebug)
okHttpClient.addInterceptor(loggingInterceptor);
return okHttpClient.build();
}
/*...*/
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment