Open ericntd opened 3 years ago
I found a solution for my needs:
.listener(RequestListener<Bitmap>)
and .into(imageView)
When ImageView is not available, use .into(CustomTarget<Bitmap>)
imageView?.let {
Glide.with(this)
.asBitmap()
.load("https://www.lomsnesvet.ca/wp-content/uploads/sites/21/2019/08/Kitten-Blog-1600x2400.jpg")
.centerCrop()
.listener(object : RequestListener<Bitmap> {
override fun onLoadFailed(e: GlideException?, model: Any?, target: com.bumptech.glide.request.target.Target<Bitmap>?, isFirstResource: Boolean): Boolean {
// FAILURE CALLBACK here
return false
}
override fun onResourceReady(resource: Bitmap?, model: Any?, target: com.bumptech.glide.request.target.Target<Bitmap>?, dataSource: DataSource?, isFirstResource: Boolean): Boolean {
// SUCCESS CALLBACK here
return false
}
})
.into(it)
} ?: kotlin.run {
Glide.with(this)
.asBitmap()
.load("https://www.lomsnesvet.ca/wp-content/uploads/sites/21/2019/08/Kitten-Blog-1600x2400.jpg")
.centerCrop()
.into(object : CustomTarget<Bitmap>() {
override fun onResourceReady(resource: Bitmap, transition: Transition<in Bitmap>?) {
// Do what's necessary with bitmap e.g. notificationBuilder.setBitmap()
// SUCCESS CALLBACK here
}
override fun onLoadCleared(placeholder: Drawable?) {
TODO("Not yet implemented")
}
override fun onLoadFailed(errorDrawable: Drawable?) {
// FAILURE CALLBACK here
}
})
}
Can we please update the documentations to something like below though?
val imageView: ImageView? = ...
Glide.with(this)
.load(imageSourceUrl)
.centerCrop()
.into(object: CustomTarget<Drawable>() {
override fun onResourceReady(resource: Drawable, transition: Transition<in Drawable>?) {
imageView?.setImageDrawable(resource) // above centerCrop() will not work! use imageView.setScaleType instead
// SUCCESS CALLBACK here
}
override fun onLoadCleared(placeholder: Drawable?) {
TODO("Not yet implemented")
}
override fun onLoadFailed(errorDrawable: Drawable?) {
// FAILURE CALLBACK here
}
})
Glide Version: 4.12.0
Integration libraries: N/A
Device/Android Version: All
Issue details / Repro steps / Use case background: Run the following code Observe that the result is actually centerInside not centerCrop Actual behaviour
Expected behaviour
Glide load line /
GlideModule
(if any) / list Adapter code (if any):My requirements:
Layout XML: