I use Fresco library to show animated gif files in RecyclerView and android. My code is pretty simple, I do this in onBindViewHolder():
DraweeController controller = Fresco.newDraweeControllerBuilder()
.setUri(url)
.setAutoPlayAnimations(true)
.build();
simpleDraweeView.setController(controller);
Everything is fine, but it looks like GIF images are not cached and reloaded when I scroll up or down. So I decided to show preview for GIF files just like simple images. Seems to setLocalThumbnailPreviewsEnabled(true) for ImageRequest doesn't work for GIF images. Then I tried to use ImageDecodeOptionsBuilder with setForceStaticImage(true) - it displays GIFs as static images (almost what I need, but I need to start animation after static image is loaded). Here is the all my code:
Uri imageUri = Uri.parse(url);
ImageDecodeOptionsBuilder decodeOptionsBuilder = new ImageDecodeOptionsBuilder();
decodeOptionsBuilder.setForceStaticImage(true);
decodeOptionsBuilder.setDecodePreviewFrame(true);
ImageDecodeOptions imageDecodeOptions = new ImageDecodeOptions(decodeOptionsBuilder);
ImageRequest request = ImageRequestBuilder.newBuilderWithSource(imageUri)
.setImageDecodeOptions(imageDecodeOptions)
.setLocalThumbnailPreviewsEnabled(true)
.build();
DraweeController controller = Fresco.newDraweeControllerBuilder()
.setImageRequest(request)
.setAutoPlayAnimations(true)
.build();
simpleDraweeView.setController(controller);
I also tried to play with setAutoPlayAnimations(true/false) and other parameters (like decodeOptionsBuilder.setDecodePreviewFrame(true)) but still without success.
So my question is: how I can show the static images as preview images (like placeholders) for GIFs? If It's first(or some other) frame from GIF it would be cool. Any help is appreciated.