-
-
Save anonymous/e50bdfc1c1d0382c1060f649670c6418 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static class CatsViewHolder extends RecyclerView.ViewHolder { | |
protected ImageView image; | |
private final ProgressBar progress; | |
private final MyProgressTarget<GlideDrawable> target; | |
public CatsViewHolder(View v) { | |
super(v); | |
image = (ImageView) v.findViewById(R.id.image); | |
progress = (ProgressBar) v.findViewById(R.id.progress); | |
target = new MyProgressTarget<>(new GlideDrawableImageViewTarget(image), progress, image); | |
} | |
void bind(String url, DrawableRequestBuilder<String> thumbnailRequest) { | |
target.setModel(url); // update target's cache | |
Glide.with(image.getContext()) | |
.load(url) | |
// .asBitmap() | |
.diskCacheStrategy(DiskCacheStrategy.SOURCE) | |
.listener(new RequestListener<String, GlideDrawable>() { | |
@Override | |
public boolean onException(Exception e, String model, Target<GlideDrawable> target, boolean isFirstResource) { | |
if (BuildConfig.DEBUG) | |
Log.e("IMAGE_EXCEPTION", "Exception " + e.toString()); | |
return false; | |
} | |
@Override | |
public boolean onResourceReady(GlideDrawable resource, String model, Target<GlideDrawable> target, boolean isFromMemoryCache, boolean isFirstResource) { | |
return false; | |
} | |
}) | |
// .placeholder(R.drawable.github_232_progress) | |
.thumbnail(thumbnailRequest) | |
.centerCrop() // needs explicit transformation, because we're using a custom target | |
.into(target) | |
; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment