0

I am using fersco library for loading local image. Initially i am displaying placeholder image in each item.Once the image is downloaded then i am storing that image in to local path and then load image via setImageUri function. If i am scrolling fast at the time of downloading image it display different image and re-appearing some time keep on changing if i am stop scrolling.

My SimpleDraweeView :

<com.facebook.drawee.view.SimpleDraweeView
            android:id="@+id/fake_image"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_centerHorizontal="true"
            android:layout_centerVertical="true"
           android:layout_gravity="center|center_horizontal|center_vertical"
            android:adjustViewBounds="true"
            android:contentDescription="@string/app_name"
            android:scaleType="centerInside" /> 

My Adapter Code is :

GenericDraweeHierarchy hierarchy = setHierarchyForDraweeView(mImageView, 300);

hierarchy.setFailureImage(mContext.getResources().getDrawable(R.drawable.broken_image_black)); mSimpleDraweeView.setImageURI(Uri.fromFile(new File(mPath/local path/)));

SetHierarchyForDraweeView Function :

private GenericDraweeHierarchy setHierarchyForDraweeView(SimpleDraweeView draweeView, int duration) {
    if (draweeView != null) {
        if (draweeView.getHierarchy() == null) {
            GenericDraweeHierarchyBuilder builder = new GenericDraweeHierarchyBuilder(mContext.getResources());
            GenericDraweeHierarchy hierarchy = builder
                    .setFadeDuration(duration)
                    .setPlaceholderImage(new AsyncColorDrawable(mContext.getResources()))
                    .setFailureImage(mContext.getResources().getDrawable(R.drawable.broken_image_black))
                    .build();
            draweeView.setHierarchy(hierarchy);
        } else {
            GenericDraweeHierarchy hierarchy = draweeView.getHierarchy();
            hierarchy.setFadeDuration(duration);
            return hierarchy;
        }
    }
    return null;
}

AsyncColorDrawable Class :

private class AsyncColorDrawable extends ColorDrawable {
    public AsyncColorDrawable(Resources res) {
        super(res.getColor(R.color.RED));
    }
}

I am doing anything wrong ?

Arun
  • 510
  • 1
  • 4
  • 21

1 Answers1

0

I see several things that should be fixed, but none of which would explain incorrect loading. I will be able to help, but I'll need the logcat logs as explained here. Also, there is one thing I don't fully understand. From your description it seems that you are downloading your images manually, saving them to disk and when they are downloaded you set the Uri. Why not using Fresco to automatically download and disk-cache images for you? Can you provide this piece of code as well, because the issue might very well be there.

Things that should be fixed:

  1. adjustViewBounds and scaleType attributtes are not supported by SimpleDraweeView. Drawee operates on several images at once (placeholder, failure image, actual image, etc.) Each can have its own scale type so you need to use Drawee atrributes as explained here.

  2. If you are inflating your view from XML, draweeView.getHierarchy should never be null. You would have a NullPointerException anyway because you are not returning hierarchy from that if-branch. So, you can specify your failure image via XML too, no need to do that programmatically. Same for the fade duration if you always use the same value.

plamenko
  • 1,068
  • 1
  • 8
  • 10
  • Thanks for your reply. If i clear the memory cache (if image is not available in MemoryCache) and reload it then its work fine. – Arun Mar 11 '16 at 06:15
  • Karun-2189, what do you mean? Are you saying that there is an issue in Fresco caching logic? If so can you elaborate so we can investigate? Again, I don't fully understand how you are downloading the image, but if it happens that you use the same filename for a different image, then yes, you need to clear the image from the memory cache first and then reload it. Otherwise we will find the old image in the cache and there is no way to know that the underlying file actually changed. – plamenko Mar 12 '16 at 12:10
  • plamenko, I am not downloading the image. I am loading image from local storage. I am using using listView, each row contain simpledraweeview. I am using same file for different images, adapter will reuse the view may be this will be the issue. But i am using gridview also this issue does not occur for gird. I don't know why this is not occur for gridview. – Arun Mar 14 '16 at 06:47