Created
May 30, 2018 21:28
-
-
Save mtilbrook-dev/ef9a6393964adf76c154cac99e6109f3 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 | |
object AppModule { | |
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