Use OkHttp for Glide requests
This commit is contained in:
@@ -151,6 +151,8 @@ dependencies {
|
|||||||
// https://github.com/bumptech/glide/releases
|
// https://github.com/bumptech/glide/releases
|
||||||
def glide_version = "4.13.1"
|
def glide_version = "4.13.1"
|
||||||
implementation "com.github.bumptech.glide:glide:$glide_version"
|
implementation "com.github.bumptech.glide:glide:$glide_version"
|
||||||
|
implementation "com.github.bumptech.glide:okhttp3-integration:$glide_version"
|
||||||
|
kapt "com.github.bumptech.glide:compiler:$glide_version"
|
||||||
|
|
||||||
// https://github.com/androidbroadcast/ViewBindingPropertyDelegate/releases
|
// https://github.com/androidbroadcast/ViewBindingPropertyDelegate/releases
|
||||||
implementation "com.github.kirich1409:viewbindingpropertydelegate-noreflection:1.5.6"
|
implementation "com.github.kirich1409:viewbindingpropertydelegate-noreflection:1.5.6"
|
||||||
|
|||||||
@@ -0,0 +1,18 @@
|
|||||||
|
package gq.kirmanak.mealient.ui.images
|
||||||
|
|
||||||
|
import dagger.hilt.EntryPoint
|
||||||
|
import dagger.hilt.InstallIn
|
||||||
|
import dagger.hilt.components.SingletonComponent
|
||||||
|
import gq.kirmanak.mealient.di.AUTH_OK_HTTP
|
||||||
|
import okhttp3.OkHttpClient
|
||||||
|
import javax.inject.Named
|
||||||
|
import javax.inject.Singleton
|
||||||
|
|
||||||
|
@EntryPoint
|
||||||
|
@InstallIn(SingletonComponent::class)
|
||||||
|
interface GlideModuleEntryPoint {
|
||||||
|
|
||||||
|
@Singleton
|
||||||
|
@Named(AUTH_OK_HTTP)
|
||||||
|
fun provideOkHttp(): OkHttpClient
|
||||||
|
}
|
||||||
@@ -0,0 +1,32 @@
|
|||||||
|
package gq.kirmanak.mealient.ui.images
|
||||||
|
|
||||||
|
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 dagger.hilt.android.EntryPointAccessors.fromApplication
|
||||||
|
import timber.log.Timber
|
||||||
|
import java.io.InputStream
|
||||||
|
|
||||||
|
@GlideModule
|
||||||
|
class MealieGlideModule : AppGlideModule() {
|
||||||
|
|
||||||
|
override fun registerComponents(context: Context, glide: Glide, registry: Registry) {
|
||||||
|
super.registerComponents(context, glide, registry)
|
||||||
|
replaceOkHttp(context, registry)
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun replaceOkHttp(context: Context, registry: Registry) {
|
||||||
|
Timber.v("replaceOkHttp() called with: context = $context, registry = $registry")
|
||||||
|
val entryPoint = fromApplication(context, GlideModuleEntryPoint::class.java)
|
||||||
|
val okHttp = entryPoint.provideOkHttp()
|
||||||
|
registry.replace(
|
||||||
|
GlideUrl::class.java,
|
||||||
|
InputStream::class.java,
|
||||||
|
OkHttpUrlLoader.Factory(okHttp)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user