From d59e38ee9d11da186131b602425231eff0896956 Mon Sep 17 00:00:00 2001 From: Shinokuni Date: Sat, 5 Sep 2020 14:05:16 +0200 Subject: [PATCH] Use project level okhttp client with glide --- .../com/readrops/app/utils/GlideModule.java | 10 --------- .../readrops/app/utils/ReadropsGlideModule.kt | 21 +++++++++++++++++++ 2 files changed, 21 insertions(+), 10 deletions(-) delete mode 100644 app/src/main/java/com/readrops/app/utils/GlideModule.java create mode 100644 app/src/main/java/com/readrops/app/utils/ReadropsGlideModule.kt diff --git a/app/src/main/java/com/readrops/app/utils/GlideModule.java b/app/src/main/java/com/readrops/app/utils/GlideModule.java deleted file mode 100644 index 7d765a40..00000000 --- a/app/src/main/java/com/readrops/app/utils/GlideModule.java +++ /dev/null @@ -1,10 +0,0 @@ -package com.readrops.app.utils; - -import androidx.annotation.NonNull; - -import com.bumptech.glide.module.AppGlideModule; - -@com.bumptech.glide.annotation.GlideModule -public class GlideModule extends AppGlideModule { - -} diff --git a/app/src/main/java/com/readrops/app/utils/ReadropsGlideModule.kt b/app/src/main/java/com/readrops/app/utils/ReadropsGlideModule.kt new file mode 100644 index 00000000..3138c7dd --- /dev/null +++ b/app/src/main/java/com/readrops/app/utils/ReadropsGlideModule.kt @@ -0,0 +1,21 @@ +package com.readrops.app.utils + +import android.content.Context +import com.bumptech.glide.Glide +import com.bumptech.glide.Registry +import com.bumptech.glide.annotation.GlideModule +import com.bumptech.glide.integration.okhttp3.OkHttpUrlLoader +import com.bumptech.glide.load.model.GlideUrl +import com.bumptech.glide.module.AppGlideModule +import com.readrops.api.utils.HttpManager +import java.io.InputStream + +@GlideModule +class ReadropsGlideModule : AppGlideModule() { + + override fun registerComponents(context: Context, glide: Glide, registry: Registry) { + val factory = OkHttpUrlLoader.Factory(HttpManager.getInstance().okHttpClient) + + glide.registry.replace(GlideUrl::class.java, InputStream::class.java, factory) + } +} \ No newline at end of file