Issue 1:
i need to show gif in recyle view android, i am currently using glide and sending gif request to download gif in the onbindviewholder callback

the scroll is smooth but the gif download is very slow with glide,can anybody suggest better mechanism.

current code is

package com.example.akash.videogramassignment.adapters;

import android.app.Activity;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.bumptech.glide.Glide;
import com.bumptech.glide.load.engine.DiskCacheStrategy;
import com.example.akash.videogramassignment.R;
import com.example.akash.videogramassignment.apputils.AppUtils;
import com.example.akash.videogramassignment.models.videoassignment.GridBaseData;
import com.example.akash.videogramassignment.viewholders.GIFItemViewHolder;

import java.util.ArrayList;
import java.util.List;

/**
* Created by akash on 12/3/16.
*/
public class VideoGramDataAdapter extends RecyclerView.Adapter<GIFItemViewHolder> /*implements OnItemClickListener*/ {
private List<GridBaseData> mHomePageItemList = new ArrayList<>();
private final int deviceWidth = AppUtils.getDeviceWidth();
/*Map<Integer, GifDrawable> params = new HashMap(mHomePageItemList.size()) {
@Override
public GifDrawable get(Object key) {
if (!containsKey(key))
return null;
return (GifDrawable) super.get(key);
}
};
Map<Integer, Boolean> isGifRequest = new HashMap(mHomePageItemList.size()) {
@Override
public Boolean get(Object key) {
if (!containsKey(key))
return false;
return (Boolean) super.get(key);
}
};*/

private Activity mContext;
private GIFItemViewHolder GIFItemViewHolder;

public VideoGramDataAdapter(List<GridBaseData> homePageListItemList, Activity context) {
mHomePageItemList = homePageListItemList;
mContext = context;

}

@Override
public GIFItemViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.layout_gif_item_tuple, parent, false);
return new GIFItemViewHolder(view);
}

@Override
public void onBindViewHolder(GIFItemViewHolder holder, int position) {
/* float factor = deviceWidth/(mHomePageItemList.get(position).grid.width);
int height = (int)factor*(mHomePageItemList.get(position).grid.height);
holder.tupleContainer.setLayoutParams(new ViewGroup.LayoutParams(
deviceWidth, height)); */
//Glide.with(mContext).load(R.layout.layout_spinner).override(Integer.valueOf(mHomePageItemList.get(position).grid.height), deviceWidth); // resizes the image to these dimensions (in pixel). does not respect aspect ratio.into(holder.mItemIcon);
/*if (isGifRequest != null *//*&& isGifRequest.get(position) *//* && params != null && params.get(position) != null) {*/
Glide.with(mContext).load(mHomePageItemList.get(position).grid.gif_url)
.asGif()
.diskCacheStrategy(DiskCacheStrategy.RESULT)
//.override(/*Integer.valueOf(mHomePageItemList.get(position).grid.height)*/(deviceWidth*3)/4, deviceWidth)
.into(holder.mItemIcon);
/*} else
Glide.with(mContext).load(mHomePageItemList.get(position).ppurl).into(GIFItemViewHolder.mItemIcon);*/

}

@Override
public int getItemCount() {
return mHomePageItemList != null ? (mHomePageItemList.size()) : 0;
}

public void addAll(List<? extends GridBaseData> items) {
mHomePageItemList.addAll(items);
}

/* @Override
public void onItemClick(int position, View v) {
if (GIFItemViewHolder != null && mContext != null) {
if (params.get(position) == null) {
downloadImage(position, v);
isGifRequest.put(position, true);
} else {
ImageView imageView = (ImageView) v;
//imageView.setImageDrawable(params.get(position));
Glide.with(mContext).load(params.get(position)).into(imageView);
}
}
if (mContext != null) {
LogUtils.makeToast("called" + position, mContext.getApplicationContext());
}
}*/

/*private void downloadImage(final int position, View v) {
ImageView imageView = (ImageView) v;
*//* Glide.with(mContext).load(mHomePageItemList.get(position).grid.gif_url).asGif()
.into(new SimpleTarget<GifTypeRequest>() {
@Override
public void onResourceReady(GifTypeRequest resource, GlideAnimation glideAnimation) {
params.put(position, resource);
//Glide.with(this).load(R.raw.sample_gif).into(imageViewTarget);
}
});*//*
Glide.with(mContext).load(mHomePageItemList.get(position).grid.gif_url).asGif().listener(new RequestListener<String, GifDrawable>() {
@Override
public boolean onException(Exception e, String model, Target<GifDrawable> target, boolean isFirstResource) {
return false;
}

@Override
public boolean onResourceReady(GifDrawable resource, String model, Target<GifDrawable> target, boolean isFromMemoryCache, boolean isFirstResource) {
params.put(position, resource);
return false;
}

}).into(imageView);
}*/

@Override
public void onViewRecycled(GIFItemViewHolder holder) {
super.onViewRecycled(holder);
Glide.clear(holder.mItemIcon);
}
}

Issue 2:
We just started using Glide and I've been comparing the default RESULT disk cache strategy vs. SOURCE and I'm noticing that SOURCE is noticeably faster to render a newly net-retrieved image to the screen.

I'm playing with two second-gen Nexus 7's with Lollipop side-by-side with images ~200K, 700x700 average. I made the most minimal example I can and have ~100 images in a vanilla RecyclerView with a LinearLayoutManager where 4-5 images will be visible on screen at a time. If I start up both configurations from scratch and scroll to the very bottom of the view the SOURCE config finishes showing the images in less than a second whereas the RESULT config finishes showing them in 2-4 seconds. This is consistent with regular scrolling where images come down one at a time: SOURCE is always faster than RESULT.

Without diving in too deep into the code myself I'm suspecting that RESULT resizes the image before it shows it on screen. I'd imagine you could make it as fast as SOURCE if on the first/network retrieval you immediately show the full image in the view like SOURCE but on a background thread continue resizing the image and store it in the disk cache resized so on the second request it shows up resized.

And now that I've actually typed all that out I can see how that might be unexpected for someone not using something like fitCenter() where the difference between SOURCE and RESULT looks almost the same on screen...hmmm.

Does this use case sound interesting to you, though? I assume there're probably extension points where I could create the behavior I want using custom targets or something but I do really like how Glide handles all the view/adapter/recycling stuff behind the curtains for me.

Any suggestions for how to accomplish this with existing apis or if this is a valid enhancement request?

Thanks much!

Details:

RecyclerView.Adapter

@Override
public void onBindViewHolder(ViewHolder holder, int position) {
Glide.with(holder.itemView.getContext())
.load(thumbnails[position])
.fitCenter()
.crossFade()
// .diskCacheStrategy(DiskCacheStrategy.SOURCE)
.into(holder.image);
}

View Layout

<?xml version="1.0" encoding="utf-8"?>
<ImageView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="200dp"
android:scaleType="centerCrop"
android:background="#444444"
android:layout_marginBottom="10dp" />