Skip to content

Instantly share code, notes, and snippets.

@naturalwarren
Last active May 27, 2018 19:34
Show Gist options
  • Save naturalwarren/02855e8e4f2897ad826c5d6ba3c76b69 to your computer and use it in GitHub Desktop.
Save naturalwarren/02855e8e4f2897ad826c5d6ba3c76b69 to your computer and use it in GitHub Desktop.
@Module
abstract class AppModule {
@Module
companion object {
private const val HTTP_RESPONSE_CACHE = (10 * 1024 * 1024).toLong()
@AppScope @Provides @JvmStatic
fun httpClient(cache: Cache): OkHttpClient {
if (Looper.getMainLooper() == Looper.myLooper())
throw IllegalStateException("Initializing OkHttpClient on main thread.")
return OkHttpClient.Builder()
.cache(cache)
.build()
}
@AppScope @Provides @JvmStatic
fun cache(@AppContext context: Context): Cache {
if (Looper.getMainLooper() == Looper.myLooper())
throw IllegalStateException("Initializing cache on main thread.")
return Cache(context.cacheDir, HTTP_RESPONSE_CACHE)
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment