Last active
May 27, 2018 19:34
-
-
Save naturalwarren/02855e8e4f2897ad826c5d6ba3c76b69 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@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