For Lottie you need these 3 classes:
@GlideModule
class MedisafeGlideModule : AppGlideModule() {
override fun registerComponents(
context: Context, glide: Glide, registry: Registry) {
registry
.register(LottieComposition::class.java, LottieDrawable::class.java, LottieDrawableTranscoder())
.append(InputStream::class.java, LottieComposition::class.java, LottieDecoder())
}
override fun isManifestParsingEnabled() = false
}
Second one:
class LottieDecoder : ResourceDecoder<InputStream, LottieComposition> {
override fun handles(source: InputStream, options: Options): Boolean = true
@Throws(IOException::class)
override fun decode(source: InputStream, width: Int, height: Int, options: Options): Resource<LottieComposition> {
return try {
val lottieResult = LottieCompositionFactory.fromJsonInputStreamSync(source, null)
SimpleResource(lottieResult.value!!)
} catch (ex: Exception) {
throw IOException("Cannot load lottie from stream", ex)
}
}
}
Third one:
class LottieDrawableTranscoder : ResourceTranscoder<LottieComposition, LottieDrawable> {
override fun transcode(toTranscode: Resource<LottieComposition>, options: Options): Resource<LottieDrawable> {
val composition = toTranscode.get()
val lottieDrawable = LottieDrawable()
lottieDrawable.composition = composition
lottieDrawable.repeatCount = ValueAnimator.INFINITE
return SimpleResource(lottieDrawable)
}
}
How to use:
Glide.with(imageView)
.`as`(LottieDrawable::class.java)
.load(url)
.into(imageView)