Properly adjust image view bounds when size not available before loading

Change-Id: I8283354afebb7cd427b96953fe9f90b1063d23b9
This commit is contained in:
SpiritCroc 2021-05-07 09:30:48 +02:00
parent 1afce468da
commit 0c6e02b76d
1 changed files with 20 additions and 0 deletions

View File

@ -16,6 +16,7 @@
package im.vector.app.features.media package im.vector.app.features.media
import android.graphics.drawable.BitmapDrawable
import android.graphics.drawable.Drawable import android.graphics.drawable.Drawable
import android.net.Uri import android.net.Uri
import android.os.Parcelable import android.os.Parcelable
@ -119,6 +120,25 @@ class ImageContentRenderer @Inject constructor(private val localFilesHelper: Loc
imageView.contentDescription = data.filename imageView.contentDescription = data.filename
createGlideRequest(data, mode, imageView, size) createGlideRequest(data, mode, imageView, size)
.listener(object : RequestListener<Drawable> {
override fun onLoadFailed(e: GlideException?, model: Any?, target: Target<Drawable>?, isFirstResource: Boolean): Boolean {
return false
}
override fun onResourceReady(resource: Drawable?, model: Any?, target: Target<Drawable>?, dataSource: DataSource?, isFirstResource: Boolean): Boolean {
if (data.width == null || data.height == null || data.width == 0 || data.height == 0) {
if (resource is BitmapDrawable) {
val updatedData = data.copy(width = resource.intrinsicWidth, height = resource.intrinsicHeight)
val newSize = processSize(updatedData, mode)
imageView.updateLayoutParams {
width = newSize.width
height = newSize.height
}
}
}
return false
}
})
.dontAnimate() .dontAnimate()
.transform(RoundedCorners(dimensionConverter.dpToPx(3))) .transform(RoundedCorners(dimensionConverter.dpToPx(3)))
// .thumbnail(0.3f) // .thumbnail(0.3f)