Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Glide 4.x.x Custom ResourceDecoder for single Glide load #3522

Closed
VuXuanBach opened this issue Feb 15, 2019 · 3 comments
Closed

Glide 4.x.x Custom ResourceDecoder for single Glide load #3522

VuXuanBach opened this issue Feb 15, 2019 · 3 comments
Labels

Comments

@VuXuanBach
Copy link

In verion 4.x.x, Glide can take in custom ResourceDecoder through AppGlideModule

@GlideModule
class MyAppGlideModule : AppGlideModule() {
    override fun registerComponents(context: Context, glide: Glide, registry: Registry) {
        registry.prepend(String::class.java, Bitmap::class.java, GalleryDecoder(context))
    }
}

However, this will apply the custom decoder to all Glide loads. Now, after reading through Glide code, I see that the custom decoder is identified by a thing called bucket, and one of the comment in the code said You may also add custom buckets which are identified as a unique string.
So is it possible to apply the bucket (corresponding with a custom ResourceDecoder) on a specific Glide load?

Note that in Glide 3.x.x, you can do this easily:

Glide.with(context)
          .load(file)
          .asBitmap()
          .decoder(new GalleryDecoder(context, item))
@sjudd
Copy link
Collaborator

sjudd commented Feb 15, 2019

We definitely made this harder in Glide 4.0, on the assumption that this use case was relatively rare and that for those cases it would be better to accept some additional overhead to reduce the clutter in the API and the number of unnecessary allocations.

The recommended way in v4 of using your own decoder is either to create custom resource types, or to replace Glide's default decoder. Since you appear to be handling standard data types and producing a standard resource type (Bitmap), the custom resource type option is more work. Instead you could consider creating your own ResourceDecoder that checks an Option to decide whether to use GalleryDecoder or Glide's default.

Buckets aren't sufficient because they apply to all loads. Buckets are a (mostly) internal tool to make sure that decoders are attempted in the order we expect.

@VuXuanBach
Copy link
Author

Great, thank you, I'll try your solution

@stale
Copy link

stale bot commented Feb 25, 2019

This issue has been automatically marked as stale because it has not had activity in the last seven days. It will be closed if no further activity occurs within the next seven days. Thank you for your contributions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants