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

Return drawable with on resource ready callback #16

Open
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

abhriyaroy
Copy link

Returning the drawable as a callback will allow the user to use the drawable as any manner which seems fit and not just bound to setting it to an Imageview.

Abhriya added 4 commits March 4, 2021 20:08
…b.com:abhriyaroy/GlideToVectorYou into return-drawable_with-onResourceReady-callback
When using a listener, the drawable obtained in the callback can be used instead of supplying an imageview as an extra argument. This will cater to the cases, where the user only wants to load a PictureDrawable without setting it to any specific imageview.
@@ -50,7 +53,7 @@ public GlideToVectorYou setPlaceHolder(int placeHolderLoading, int placeHolderEr
return instance;
}

public void load(Uri uri, ImageView imageView) {
public void load(Uri uri) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will break existing implementations. Maybe add a new method with the method signature that you want?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure. Kept the older method and just added a new one.

@@ -41,11 +41,9 @@ public boolean onLoadFailed(GlideException e, Object model, Target<PictureDrawab
@Override
public boolean onResourceReady(PictureDrawable resource, Object model,
Target<PictureDrawable> target, DataSource dataSource, boolean isFirstResource) {
ImageView view = ((ImageViewTarget<?>) target).getView();

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You might want to keep this as is for backward compatibility as well

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes. I didn't consider backward compatibility. Have modified the same.

public interface GlideToVectorYouListener {
void onLoadFailed();
void onResourceReady();
void onResourceReady(PictureDrawable pictureDrawable);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Depending on whether the PictureDrawable can be null or not, an annotation here would be helpful. For Kotlin usages

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added @Nullable

- Add support for backward compaitibility by keeping previous method for normal loading
- Add nullable annotation to onResourceReady
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants