Skip to content

Instantly share code, notes, and snippets.

@hafs-r
Created October 7, 2019 13:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hafs-r/18bd6b7a222cfcedd1ea082c5ae2e26e to your computer and use it in GitHub Desktop.
Save hafs-r/18bd6b7a222cfcedd1ea082c5ae2e26e to your computer and use it in GitHub Desktop.
@Provides
@Singleton
internal fun provideOkhttpClient(
cache: Cache,
networkMonitor:NetworkMonitor,
@ApplicationContext context: Context,
eventBus: RxEventBus,
deviceType: CurrentDeviceType): OkHttpClient {
val client = OkHttpClient.Builder()
.cache(cache)
.connectTimeout(CONNECTION_TIME_OUT.toLong(),TimeUnit.SECONDS)
.readTimeout(READ_TIME_OUT.toLong(), TimeUnit.SECONDS)
.addNetworkInterceptor(TimberLoggingInterceptor())
.addInterceptor(FakeInterceptor(context))
return client.build()
}
@Provides
@Singleton
internal fun provideRetrofit(
gson: Gson,
okHttpClient: OkHttpClient): Retrofit {
val restAdapterBuilder = Retrofit.Builder()
.client(okHttpClient)
.baseUrl(Constants.API_BASE_URL)
.addConverterFactory(GsonConverterFactory.create(gson))
.addCallAdapterFactory(RxJavaCallAdapterFactory.create())
return restAdapterBuilder.build()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment