Only load stills for low memory devices

// FREEBIE
This commit is contained in:
Moxie Marlinspike 2016-10-24 13:51:34 -07:00
parent 69d0242574
commit 2c7fcbed60

View File

@ -94,6 +94,11 @@ public class GiphyAdapter extends RecyclerView.Adapter<GiphyAdapter.GiphyViewHol
.downloadOnly(Target.SIZE_ORIGINAL, Target.SIZE_ORIGINAL) .downloadOnly(Target.SIZE_ORIGINAL, Target.SIZE_ORIGINAL)
.get(); .get();
} }
public synchronized void setModelReady() {
this.modelReady = true;
notifyAll();
}
} }
GiphyAdapter(Context context, List<GiphyImage> images) { GiphyAdapter(Context context, List<GiphyImage> images) {
@ -131,6 +136,15 @@ public class GiphyAdapter extends RecyclerView.Adapter<GiphyAdapter.GiphyViewHol
DrawableRequestBuilder<String> thumbnailRequest = Glide.with(context) DrawableRequestBuilder<String> thumbnailRequest = Glide.with(context)
.load(image.getStillUrl()); .load(image.getStillUrl());
if (Util.isLowMemory(context)) {
Glide.with(context)
.load(image.getStillUrl())
.placeholder(new ColorDrawable(Util.getRandomElement(MaterialColor.values()).toConversationColor(context)))
.diskCacheStrategy(DiskCacheStrategy.ALL)
.into(holder.thumbnail);
holder.setModelReady();
} else {
Glide.with(context) Glide.with(context)
.load(image.getGifUrl()) .load(image.getGifUrl())
.thumbnail(thumbnailRequest) .thumbnail(thumbnailRequest)
@ -139,6 +153,7 @@ public class GiphyAdapter extends RecyclerView.Adapter<GiphyAdapter.GiphyViewHol
.listener(holder) .listener(holder)
.into(holder.thumbnail); .into(holder.thumbnail);
} }
}
@Override @Override
public int getItemCount() { public int getItemCount() {