Glide - call method after fallback or error when trying load photo

前端 未结 2 1519
野的像风
野的像风 2021-01-03 04:09

Glide - call method after fallback or error when trying load photo.

Hi!

Is there any a way to check if Glide load photo from link or use f

2条回答
  •  执念已碎
    2021-01-03 04:46

    This helps me:

    private void loadPicture(final ViewHolder holder, String photoUrl, final Boolean shouldLoadAgain) {
        holder.progressBar.setVisibility(View.VISIBLE);
    
        Glide
            .with(mActivity)
            .load(photoUrl)
            .fallback(R.drawable.bg_gradient)
            .error(R.drawable.bg_gradient)
            .centerCrop()
            .crossFade()
            .listener(new RequestListener() {
                @Override
                public boolean onException(Exception e, String model, Target target, boolean isFirstResource) {
                    holder.progressBar.setVisibility(View.GONE);
                    if (shouldLoadAgain)
                        loadPicture(holder, mPhotoUrl, false);
                    return false;
                }
    
                @Override
                public boolean onResourceReady(GlideDrawable resource, String model, Target target, boolean isFromMemoryCache, boolean isFirstResource) {
                    holder.progressBar.setVisibility(View.GONE);
                    return false;
                }
            })
            .diskCacheStrategy(DiskCacheStrategy.SOURCE)
            .into(holder.photo);
    }
    

提交回复
热议问题