0

I am using gridview. In grid each item contain a simpledraweeview, when i add a new item in first place and notify the adapter at that time first and last item having the same image. (It only occur in below lollipop)

XML SimpleDraweeView :

<com.facebook.drawee.view.SimpleDraweeView
                android:id="@+id/id_imageview"
                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/COM_NOTEBOOK_NOTEBOOK"
                android:scaleType="centerInside"
                app:imageUrl="@{url}" />

Image loading code :

public void justLoadImage(final String mPath, final SimpleDraweeView mImageView, int width, int height) {
    try {

        if (TextUtils.isEmpty(mPath) || mImageView == null) {
            return;
        }

        if (!isBitmapAvailableInMemCache(mPath)) {
            GenericDraweeHierarchy hierarchy = setHierarchyForDraweeView(mImageView, 150);
            hierarchy.setPlaceholderImage(mAsyncColorDrawable);
            hierarchy.setFailureImage(mContext.getResources().getDrawable(R.drawable.broken_image_black));
        }

        ImageRequest request;
        if (mPath.endsWith(".jpg")) {//No i18n
            request = ImageRequestBuilder.newBuilderWithSource(Uri.fromFile(new File(mPath)))
                    .setLocalThumbnailPreviewsEnabled(true)
                    .setResizeOptions(new ResizeOptions(width, height))
                    .build();
        } else {
            request = ImageRequestBuilder.newBuilderWithSource(Uri.fromFile(new File(mPath)))
                    .setLocalThumbnailPreviewsEnabled(true)
                    .build();
        }

        DraweeController draweeController = Fresco.newDraweeControllerBuilder()
                .setControllerListener(new ControllerListener<ImageInfo>() {
                    @Override
                    public void onSubmit(String id, Object callerContext) {

                    }

                    @Override
                    public void onFinalImageSet(String id, @Nullable ImageInfo imageInfo, @Nullable Animatable animatable) {
                    }

                    @Override
                    public void onIntermediateImageSet(String id, @Nullable ImageInfo imageInfo) {

                    }

                    @Override
                    public void onIntermediateImageFailed(String id, Throwable throwable) {

                    }

                    @Override
                    public void onFailure(String id, Throwable throwable) {
                        clearFerscoCache(mPath);
                        mImageView.setImageURI(Uri.fromFile(new File(mPath)));
                    }

                    @Override
                    public void onRelease(String id) {

                    }
                })
                .setOldController(mImageView.getController())
                .setImageRequest(request)
                .setAutoPlayAnimations(false)
                .build();
        mImageView.setController(draweeController);
    } catch (OutOfMemoryError | Exception e) {
        e.printStackTrace();
    }
}

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;
}
Arun
  • 510
  • 1
  • 4
  • 21

1 Answers1

0

If you're using ViewHoler pattern in your GridView adapter first condition in your if check in the lines below in your justLoadImage method can cause this kind if situation.

if (TextUtils.isEmpty(mPath) || mImageView == null) {
            return;
}

So you simply can try to remove this lines and let Fresco to handle this situation or manually set an empty image to your SimpleDraweeView in your ViewHolder if imagePath is null.

Edit:

You can check logs. Getting an exception in your justLoadImage method also can cause this kind of situation.

savepopulation
  • 11,736
  • 4
  • 55
  • 80