penfeizhou / APNG4Android

Android animation support for APNG & Animated WebP & Gif & Animated AVIF, High performance
Apache License 2.0
579 stars 76 forks source link

ResourceDecoder will not work when it has lower priority #138

Closed liushuai42 closed 2 years ago

liushuai42 commented 2 years ago

New Issue Checklist

Issue Info

Info Value
Device Info Mi A1
System Version 9.0
APNG4Android Library Version 2.17.0
Repro rate all the time (100%)
Repro with our demo project use case not present in demo project
Demo project link APNG4Android-WEBP-BUG

Issue Description and Steps

After I write a ResourceDecoder to load NinePatchDrawable, which will cause APNG4Android Loaders not work. My loader returned false will fallback to Glide Default ResourceDecoders but APNG4Android's Decoders。

@GlideModule
class NineGlideModule : LibraryGlideModule() {
    override fun registerComponents(context: Context, glide: Glide, registry: Registry) {
        super.registerComponents(context, glide, registry)
        registry.prepend(ByteBuffer::class.java, Drawable::class.java, NinePatchResourceDecoder())
    }
}

class NinePatchResourceDecoder : ResourceDecoder<ByteBuffer, Drawable> {
    /**
     * Just a mock ResourceDecoder, won't work, return false
     */
    override fun handles(source: ByteBuffer, options: Options) = false

    override fun decode(
        source: ByteBuffer,
        width: Int,
        height: Int,
        options: Options
    ): Resource<Drawable>? {
        TODO("Not yet implemented")
    }
}

I found a solution to fix this issue, exclude the GlideAnimationModule and register it manually, which will promote GlideAnimationModule priority.

@Excludes(GlideAnimationModule::class)
@GlideModule
class MyAppGlideModule : AppGlideModule() {
    override fun registerComponents(context: Context, glide: Glide, registry: Registry) {
        super.registerComponents(context, glide, registry)

        // Make it the last line with highest priority
        GlideAnimationModule().registerComponents(context, glide, registry)
    }
}

My question is can you provide another way to fix this issue elegant?

jingpeng commented 2 years ago

This is not this library aims to do, and also I think your solution which works is good