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

Max retry count , Retry Handler for Url #654

Closed
vsahu1986 opened this issue Sep 28, 2015 · 2 comments
Closed

Max retry count , Retry Handler for Url #654

vsahu1986 opened this issue Sep 28, 2015 · 2 comments
Labels

Comments

@vsahu1986
Copy link

Hi, @TWiStErRob

I agree on Exception we can check for HTTP 404 and retry ,
Is there any way to inject RetryHandler for Max retry count for particular URL .

public class GlideYoutubeImageView extends ImageView {

    public GlideYoutubeImageView(Context context) {
        this(context, null);
    }

    public GlideYoutubeImageView(Context context, AttributeSet attrs) {
        this(context, attrs, 0);
    }

    public GlideYoutubeImageView(Context context, AttributeSet attrs, int defStyle) {
        super(context, attrs, defStyle);
    }

    @Override
    protected void onDetachedFromWindow() {
        super.onDetachedFromWindow();
        Drawable placeholder = getDrawable();
        if (placeholder instanceof AnimationDrawable) {
            ((AnimationDrawable) placeholder).stop();
            Glide.clear(this);
        }
    }

    @Override
    public void setImageBitmap(Bitmap bitmap) {
        if (bitmap != null) FadingDrawable.setBitmap(this, getContext(), bitmap);
    }

    public void setImageBitmapWithoutAnimation(Bitmap bitmap) {
        super.setImageBitmap(bitmap);
    }

    public void loadUrl(final float density, final String videoId) {
        Glide.with(getContext()).load(Utils.getYoutubeUrl(density, videoId)).asBitmap().error(R.drawable.ic_error_icon).listener(new RequestListener<String, Bitmap>() {
            @Override
            public boolean onException(Exception e, String model, Target<Bitmap> target, boolean isFirstResource) {
                e.printStackTrace();
                Log.e("model",model);
                if (isFirstResource)
                    loadUrl(1.5f, videoId);// this will keeping on adding the same request again after exception until Imageview detached 
                return false;
            }

            @Override
            public boolean onResourceReady(Bitmap resource, String model, Target<Bitmap> target, boolean isFromMemoryCache, boolean isFirstResource) {
                if (isFromMemoryCache) {
                    setImageBitmapWithoutAnimation(resource);
                } else {
                    setImageBitmap(resource);
                }
                return true;
            }
        }).into(this);
    }
}

This will keeping on adding the same request again after exception until Imageview detached

Considering solution from
#606
#451

@sjudd
Copy link
Collaborator

sjudd commented Sep 30, 2015

You can always build a custom ModelLoader and DataFetcher, or copy/paste one of Glide's defaults like HttpUrlLoader and HttpUrlFetcher. You can then build in as many retries as you'd like.

@sjudd sjudd added the question label Sep 30, 2015
@vsahu1986
Copy link
Author

Thanks @sjudd I will try this .

@sjudd sjudd closed this as completed Oct 15, 2015
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