Issue 1:
In my app, I have a Recycler view with GridLayoutManager. The code I am using to load images bindImage method of recycler view adapter:

@Override
public void onBindViewHolder(ImageViewHolder holder, int position) {
GSImage dbImage = mLandscapeImagesList.get(position);
File imageFile = new File(mImageDirectoryFile, dbImage.getImageName());

Glide.with(MyImageFragement.this).load(imageFile).centerCrop().into(holder.imageView);

int indexInSelectedImagesSet = mSelectedLandscapeImages.indexOf(dbImage);
if (indexInSelectedImagesSet>-1){
holder.itemView.setSelected(true);
} else {
holder.itemView.setSelected(false);
}

}

The Cell layout I am using is:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/images_background"
android:layout_marginTop="9dp"
android:layout_marginLeft="10dp"
android:layout_marginRight="0dp"
android:layout_marginBottom="0dp"
android:padding="2dp">

<com.gaurav.myProject.commons.AspectRatioImageView
android:id="@+id/image_thumb"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:scaleType="fitXY"
app:viewAspectRatio="1.33"/>

</RelativeLayout>

Here AspectRatioImageView(subclass of ImageView) automatically resizes the height of image view according to the provided aspect ratio.

The above code is working fine on my devices (Xiaomi MiPad, ViewSonic Tablet, Android emaulators and Samsung Galaxy S3) but is not working correctly on my client's device (Samsung 10.1 inch tablet).

In his end, images are being duplicated in the recycler grid. Also the the duplicates mostly occurs in adjacent recycler grid positions. I can't share any code as I even unable to reproduce the issue on my devices.

Do you guys have any idea what could the cause of this? Can you please suggest me any thing that I can try?

Thanks

Issue 2:
I'm trying to cache downloaded image from web using SimpleTarget like so:

Glide.with(getContext())
.load(iurl)
.asBitmap()
.diskCacheStrategy(DiskCacheStrategy.SOURCE)
.skipMemoryCache(true)
.into(target);

where target is initialized by :

SimpleTarget<Bitmap> target = new SimpleTarget<Bitmap>() {

@Override
public void onResourceReady(Bitmap resource,
GlideAnimation<? super Bitmap>
glideAnimation) {
Log.d(LOG_TAG, "image cached");
}

@Override
public void onLoadFailed(Exception e, Drawable errorDrawable) {
e.printStackTrace();

}
};

and in the fragment :

Glide.with(imageView.getContext())
.load(image_url)
.asBitmap()
.dontAnimate()
.centerCrop()
.override(MyApplication.getInstance().width,MyApplication.getInstance().height)
.priority(Priority.IMMEDIATE)
.diskCacheStrategy(DiskCacheStrategy.SOURCE)
.into(imageView);

where width and height is calculated according to the current configuration of the device:

DisplayMetrics displayMetrics = this.getResources().getDisplayMetrics();
float dpWidth = displayMetrics.widthPixels / displayMetrics.density;
if (this.getResources().getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT) {
if (dpWidth < 600) {
application_instance.width = 200;
application_instance.height = 200;
} else if (dpWidth >= 600 && dpWidth < 720) {
application_instance.width = 400;
application_instance.height = 400;
} else {
application_instance.width = 800;
application_instance.height = 800;
}

} else {
if (dpWidth < 600) {
application_instance.width = 300;
application_instance.height = 300;
} else if (dpWidth >= 600 && dpWidth < 720) {
application_instance.width = 600;
application_instance.height = 600;
} else {
application_instance.width = 640;
application_instance.height = 640;
}

}

and the image view in xml layout file :

<ImageView
android:id="@+id/grid_item_image_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
andr(oid:adjustViewBounds="true" />

each time the image is loaded, it's downloaded from web again and cached again and the result is a huge cache size ! ..What I need is How to prevent downloading the same image again if it exists in the Diskcache and remove it from cache when its url is removed from database ? I'm using Glide 3.7.0. Am I missing something or misunderstand it?. Please help. Thanks in advance.