Skip to content

Instantly share code, notes, and snippets.

@molidev8
Created June 4, 2022 14:25
Show Gist options
  • Save molidev8/2087b78214333e1a4e0911a11846a7e3 to your computer and use it in GitHub Desktop.
Save molidev8/2087b78214333e1a4e0911a11846a7e3 to your computer and use it in GitHub Desktop.
A GlideModule to use OkHttp for network requests
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