How to use ImagePipeline.isInDiskCache(uri) in DraweeHolder
See original GitHub issueIn our app we use custom views to show Images. Everything works fine, but when I tried to use ImagePipeline.isInDiskCache(uri)
wrong images started to set in wrong places.
I use DraweeHolder to show the images.
Here is my code:
public void draw(Canvas canvas) {
Drawable drawable = draweeHolder.getTopLevelDrawable();
drawable.setBounds(0, 0, width, height);
drawable.draw(canvas);
}
private void checkImageCache(String imgUrl, String thumbUrl) {
ImagePipeline imagePipeline = Fresco.getImagePipeline();
Uri uri = Uri.parse(imgUrl);
DataSource<Boolean> inDiskCacheSource = imagePipeline.isInDiskCache(uri);
DataSubscriber<Boolean> subscriber = new BaseDataSubscriber<Boolean>() {
@Override
protected void onNewResultImpl(DataSource<Boolean> dataSource) {
if (!dataSource.isFinished()) {
return;
}
boolean isInCache = dataSource.getResult();
if (isInCache) {
loadImage(imgUrl, finalThumbUrl);
} else {
if (isAutoDownloadAllowed()) {
loadImage(imgUrl, thumbUrl);
draweeHolder.getHierarchy().setProgressBarImage(new CircleProgressBarDrawable());
} else {
loadThumb(thumbUrl);
}
}
}
@Override
protected void onFailureImpl(DataSource<Boolean> dataSource) {
Log.d(TAG, "onFailureImpl: " + dataSource.getFailureCause());
}
};
boolean inMemoryCache = imagePipeline.isInBitmapMemoryCache(uri);
if (inMemoryCache) {
loadImage(imgUrl, thumbUrl);
} else {
inDiskCacheSource.subscribe(subscriber, Runnable::run);
}
}
private void loadImage(String imageUrl, String thumbUrl) {
ControllerListener<ImageInfo> controllerListener = new BaseControllerListener<ImageInfo>() {
@Override
public void onFinalImageSet(String id, ImageInfo imageInfo, Animatable animatable) {
parent.invalidate();
}
@Override
public void onFailure(String id, Throwable throwable) {
parent.invalidate();
loadThumb(thumbUrl);
}
};
PipelineDraweeControllerBuilder controllerBuilder = Fresco.newDraweeControllerBuilder()
.setControllerListener(controllerListener)
.setOldController(draweeHolder.getController())
.setAutoPlayAnimations(true)
.setImageRequest(ImageRequest.fromUri(imageUrl));
draweeHolder.setController(controllerBuilder.build());
}
private void loadThumb(String thumbUrl) {
ControllerListener<ImageInfo> controllerListener = new BaseControllerListener<ImageInfo>() {
@Override
public void onFinalImageSet(String id, ImageInfo imageInfo, Animatable animatable) {
parent.invalidate();
}
@Override
public void onFailure(String id, Throwable throwable) {
parent.invalidate();
}
};
DraweeController controllerBuilder = Fresco.newDraweeControllerBuilder()
.setImageRequest(MediaHelper.getGifThumbnailRequest(thumbUrl))
.setControllerListener(controllerListener)
.setOldController(draweeHolder.getController())
.build();
draweeHolder.setController(controllerBuilder);
}
Issue Analytics
- State:
- Created 7 years ago
- Comments:9 (5 by maintainers)
Top Results From Across the Web
com.facebook.imagepipeline.request.ImageRequest Example
Learn how to use java api com.facebook.imagepipeline.request. ... public static void load(Uri uri, SimpleDraweeView draweeView, BasePostprocessor processor, ...
Read more >ImagePipeline - Fresco API
Removes all images with the specified Uri from memory cache. ... cache key entirely from the URI. If that is not the case,...
Read more >第三方图片加载组件Fresco使用指南-51CTO.COM
内存缓存的检查是同步的: ImagePipeline imagePipeline = Fresco.getImagePipeline(); Uri uri; boolean inMemoryCache = imagePipeline.
Read more >fresco清理过期 - CSDN
DataSource<Boolean> inDiskCacheSource = imagePipeline.isInDiskCache(uri); DataSubscriber<Boolean> subscriber = new BaseDataSubscriber<Boolean>() { @Override ...
Read more >Fresco初識 - 台部落
Fresco包含Drawees、The Image Pipeline兩個部分。我們先了解一下他們。 ... isInDiskCache(uri); DataSubscriber<Boolean> subscriber = new ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Hello,
If pictures are ordered, maybe you should use one ordered check and not an async one :
https://github.com/facebook/fresco/issues/603
This should slowered the cache check but gives pictures in right order.
Eric
@oprisnik Thank you, I will look into that direction.