I am using Glide to display an image from internet in a notification, not in an image view. In order to do this I extended SimpleTarget like this :
Glide
.with(context.getApplicationContext())
.load(imageUrl)
.asBitmap()
.into(new SimpleTarget<Bitmap>() {
@Override
public void onResourceReady(Bitmap largeIcon, GlideAnimation glideAnimation) {
createNotif(largeIcon);
nmc.notify(notificationId, notification);
}
});
It works fine.
In order to speed up things, I would like to check the Glide cache on a specific Image URL first and do the asynchronous query only if the bitmap is not in the cache. Something like this (glideCache and getOnlyIfinCache is what I am looking for) :
bitmap=null;
bitmap = glideCache.getOnlyIfinCache(ImageURL);
if (bitmap!=null) { // the bitmap is available
createNotif(bitmap);
nmc.notify(notificationId, notification);
} else { // the bitmap is not available. Need to get it on internet
Glide
.with(context.getApplicationContext())
.load(imageUrl)
.asBitmap()
.into(new SimpleTarget<Bitmap>() {
@Override
public void onResourceReady(Bitmap largeIcon, GlideAnimation glideAnimation) {
createNotif(largeIcon);
nmc.notify(notificationId, notification);
}
});
}