Reputation: 637
I am using Glide along with FirebaseStorage to fetch the photos stored in FirebaseStorage and show in the app. The problem is when photos were updated in the storage, The updated photos are not fetched, instead the old photos are being shown in the app. The device is online and its never updating the latest photos.
thirdPhotoStorageReference = FirebaseStorage.getInstance().reference.child("photos/${key}/3.jpg")
GlideApp.with(this)
.load(thirdPhotoStorageReference)
.override(screenWidth, screenHeight)
.listener(object : RequestListener<Drawable> {
override fun onResourceReady(resource: Drawable?, model: Any?, target: Target<Drawable>?, dataSource: DataSource?, isFirstResource: Boolean): Boolean {
showPhotoImageView(thirdPhotoImageView)
return false
}
override fun onLoadFailed(e: GlideException?, model: Any?, target: com.bumptech.glide.request.target.Target<Drawable>?, isFirstResource: Boolean): Boolean {
hidePhotoImageView(thirdPhotoImageView)
return false
}
})
.placeholder(circularProgressDrawable3)
.centerCrop()
.into(thirdPhotoImageView)
@GlideModule
class MyAppGlideModule : AppGlideModule() {
override fun registerComponents(context: Context, glide: Glide, registry: Registry) {
// Register FirebaseImageLoader to handle StorageReference
registry.append(StorageReference::class.java, InputStream::class.java,
FirebaseImageLoader.Factory())
}
}
Any help is appreciated. Note: When I update the photo, It replaces the existing photo 3.jpg with latest.
Upvotes: 0
Views: 66
Reputation: 637
Found an approach to solve the issue and posting it if someone has the same problem.
I was able to get the updated photos using the signature functionality of Glide. Please see the code below
thirdPhotoStorageReference.metadata.addOnSuccessListener {
GlideApp.with(this)
.load(thirdPhotoStorageReference)
.signature(ObjectKey(it.updatedTimeMillis))
.override(screenWidth, screenHeight)
.listener(object : RequestListener<Drawable> {
override fun onResourceReady(resource: Drawable?, model: Any?, target: Target<Drawable>?, dataSource: DataSource?, isFirstResource: Boolean): Boolean {
showPhotoImageView(thirdPhotoImageView)
return false
}
override fun onLoadFailed(e: GlideException?, model: Any?, target: com.bumptech.glide.request.target.Target<Drawable>?, isFirstResource: Boolean): Boolean {
hidePhotoImageView(thirdPhotoImageView)
return false
}
})
.placeholder(circularProgressDrawable3)
.centerCrop()
.into(thirdPhotoImageView)
}
The key here is the signature(ObjectKey(it.updatedTimeMillis))
which gets the update time of storage object and lets glide to refresh it.
Upvotes: 1