In MainActivity, I\'m loading some images using glide into recyclerview according to imageview size.
See:
@Override
public void onBindViewHolder(P
Better to preload all the images with .downloadOnly() instead of using any target. Then load images using FileProvider.
private class CacheImage extends AsyncTask {
@Override
protected File doInBackground(String... strings) {
try {
return Glide.with(getContext())
.load(strings[0])
.downloadOnly(Target.SIZE_ORIGINAL,Target.SIZE_ORIGINAL)
.get();
} catch (Exception e) {
Log.e(LOG_TAG,e.getMessage());
return null;
}
}
@Override
protected void onPostExecute(File file) {
if(file!=null){
Uri file_uri = FileProvider.getUriForFile(getContext(),
getContext().getPackageName()+".images",file);
}
}
}
And store the path alongside URL in SQLite.
Now get the image_url using FileProvider from SQLite
Glide.with(imageView.getContext())
.load()
.asBitmap()
.dontAnimate()
.centerCrop()
.override(,)
.priority(Priority.IMMEDIATE)
.diskCacheStrategy(DiskCacheStrategy.SOURCE)
.skipMemoryCache(true)
.into(imageView);
You may also need to add,
In manifest, inside
Inside res/xml, as file_paths.xml,