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

Load another image by another url if first failed. #845

Closed
ghost opened this issue Dec 26, 2015 · 1 comment
Closed

Load another image by another url if first failed. #845

ghost opened this issue Dec 26, 2015 · 1 comment
Labels

Comments

@ghost
Copy link

ghost commented Dec 26, 2015

Hello, I have two image url types, and not every image is available by firt url type. I want to load it by second type if first failed.
I tried to load in onException() method and it works, but sometimes after refresh it loads nothing and gives no exception of second loading

I tried to set cache strategy to NONE of second loading, but didnt help
my code

RequestListener<String, GlideDrawable> glideDrawableRequestListener = new RequestListener<String, GlideDrawable>() {
    @Override
    public boolean onException(Exception e, String model, Target<GlideDrawable> target, boolean isFirstResource) {
        Glide.with(context)
                .load(fullUrl)
                .listener(new RequestListener<String, GlideDrawable>() {
                    @Override
                    public boolean onException(Exception e, String model, Target<GlideDrawable> target, boolean isFirstResource) {
                        return false;
                    }
                    @Override
                    public boolean onResourceReady(GlideDrawable resource, String model, Target<GlideDrawable> target, boolean isFromMemoryCache, boolean isFirstResource) {
                        holder.nameView.setText(list.get(i).getUserName());
                        holder.likeValue.setText(list.get(i).getLikes() + "");
                        holder.dateView.setText(list.get(i).getDate());
                        holder.progressBar.setVisibility(View.GONE);
                        holder.imageTitle.setText(list.get(i).getImgtitle());
                        Bitmap bitmap = ((GlideBitmapDrawable) resource).getBitmap();
                        if (bitmap != null) {
                            holder.gridLikeIcon.setImageDrawable(new IconDrawable(context, GlobalVariable.LIKE_ICON)
                                    .colorRes(R.color.im_yellow));
                        }
                        return false;
                    }
                })
                .placeholder(R.color.transparent)
                .diskCacheStrategy(DiskCacheStrategy.NONE)
                .into(holder.gridImageView);
        return false;
    }
    @Override
    public boolean onResourceReady(GlideDrawable resource, String model, Target<GlideDrawable> target, boolean isFromMemoryCache, boolean isFirstResource) {
        holder.nameView.setText(list.get(i).getUserName());
        holder.likeValue.setText(list.get(i).getLikes() + "");
        holder.dateView.setText(list.get(i).getDate());
        holder.progressBar.setVisibility(View.GONE);
        holder.imageTitle.setText(list.get(i).getImgtitle());
        Bitmap bitmap = ((GlideBitmapDrawable) resource).getBitmap();
        if (bitmap != null) {
            holder.gridLikeIcon.setImageDrawable(new IconDrawable(context, GlobalVariable.LIKE_ICON)
                    .colorRes(R.color.im_yellow));
        }
        return false;
    }
};

Glide.with(context)
        .load(thumbnailUrl)
        .listener(glideDrawableRequestListener)
        .placeholder(R.color.transparent)
        .diskCacheStrategy(DiskCacheStrategy.ALL)
        .into(holder.gridImageView);
@TWiStErRob
Copy link
Collaborator

Looks like we discussed this in #606, please check out my custom fetcher solution there.
In any case there's a feature candidate in #451.

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

1 participant