Im using Glide from the Firebase UI to link an ImageView to my Firebase Storage. Now it works fine but Im currently implementing an update where users can change their Profileimage, the imagename and path stays the same. Either my english is to weak to understand the documentation from Glide or there simply isnt a way to recognize updates by Glide. I read something about Requests here http://bumptech.github.io/glide/doc/options.html but I cant figure it out.
Set the ref right:
this.profileRef = this.mStorageRef.child("images").child(FirebaseAuth.getInstance()
.getCurrentUser().getUid()).child("Profile");
Calling the function onCreate:
Glide.with(getContext())
.using(new FirebaseImageLoader())
.load(profileRef)
.into(this.imgProfile);
But dont know how to tell Glide to update the Image, in the Code below I just get frustrated and tried to set the Glide again, but as awaited it didnt do anything, the ImageView is still loading the Cache Picture. Also nothing happens when I tried Glide.clear(view). Maybe somebody faced this Problem already can help me.
profileRef.putFile(file).addOnSuccessListener(new OnSuccessListener<UploadTask.TaskSnapshot>() {
@Override
public void onSuccess(UploadTask.TaskSnapshot taskSnapshot) {
Glide.with(getContext())
.using(new FirebaseImageLoader())
.load(profileRef)
.into(imgProfile);
}
});
Solved it after a while. Glide cant recognize changes, if the name stays the same or the URL stays the same. So you must invalidate the Cache by putting a signature on to your Picture. Read here more about it: https://github.com/bumptech/glide/wiki/Caching-and-Cache-Invalidation
Glide.with(getContext() /* context */)
.using(new FirebaseImageLoader())
.load(profileRef)
.signature(new StringSignature(getCurrentTimeStamp()))
.into(this.imgHeader);
public static String getCurrentTimeStamp(){
try {
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
String currentDateTime = dateFormat.format(new Date()); // Find todays date
return currentDateTime;
} catch (Exception e) {
e.printStackTrace();
return null;
}