Created
June 4, 2022 14:25
-
-
Save molidev8/2087b78214333e1a4e0911a11846a7e3 to your computer and use it in GitHub Desktop.
A GlideModule to use OkHttp for network requests
This file contains 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
private const val SIZE_IN_BYTES: Long = 1024 * 1024 * 10 | |
@GlideModule | |
class MyGlideModule : AppGlideModule() { | |
override fun registerComponents(context: Context, glide: Glide, registry: Registry) { | |
val client = OkHttpClient.Builder() | |
.cache(Cache(context.cacheDir, SIZE_IN_BYTES)) | |
.build() | |
val factory = OkHttpUrlLoader.Factory(client) | |
glide.registry.replace(GlideUrl::class.java, InputStream::class.java, factory) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment