GlideModule.kt 1022 Bytes
Newer Older
1
package ru.terrakok.gitlabclient.glide
2 3 4 5 6 7 8 9 10

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 okhttp3.OkHttpClient
11
import ru.terrakok.gitlabclient.di.DI
12 13 14 15 16 17 18 19 20
import toothpick.Toothpick
import java.io.InputStream

/**
 * Created by Alexei Korshun on 25/10/2018.
 */
@GlideModule
class GlideModule : AppGlideModule() {

21 22 23 24
    private val okHttpClient: OkHttpClient =
        Toothpick
            .openScope(DI.SERVER_SCOPE)
            .getInstance(OkHttpClient::class.java)
25 26 27 28 29 30

    override fun registerComponents(context: Context, glide: Glide, registry: Registry) {
        val factory = OkHttpUrlLoader.Factory(okHttpClient)

        glide.registry.replace(GlideUrl::class.java, InputStream::class.java, factory)
    }
31 32

    override fun isManifestParsingEnabled() = false
33
}