diff --git a/changelog.d/6290.bugfix b/changelog.d/6290.bugfix new file mode 100644 index 0000000000..e5ee3e02a6 --- /dev/null +++ b/changelog.d/6290.bugfix @@ -0,0 +1 @@ +Fixed crash when opening large images in the timeline diff --git a/vector/src/main/java/im/vector/app/features/media/ImageContentRenderer.kt b/vector/src/main/java/im/vector/app/features/media/ImageContentRenderer.kt index 2f88337be2..74c9b5c6b8 100644 --- a/vector/src/main/java/im/vector/app/features/media/ImageContentRenderer.kt +++ b/vector/src/main/java/im/vector/app/features/media/ImageContentRenderer.kt @@ -18,7 +18,6 @@ package im.vector.app.features.media import android.graphics.Bitmap import android.graphics.drawable.Drawable -import android.net.Uri import android.os.Parcelable import android.view.View import android.widget.ImageView @@ -31,8 +30,6 @@ import com.bumptech.glide.load.resource.bitmap.RoundedCorners import com.bumptech.glide.request.RequestListener import com.bumptech.glide.request.target.CustomViewTarget import com.bumptech.glide.request.target.Target -import com.davemorrissey.labs.subscaleview.SubsamplingScaleImageView.ORIENTATION_USE_EXIF -import com.github.piasy.biv.view.BigImageView import im.vector.app.R import im.vector.app.core.di.ActiveSessionHolder import im.vector.app.core.files.LocalFilesHelper @@ -47,8 +44,6 @@ import org.matrix.android.sdk.api.extensions.tryOrNull import org.matrix.android.sdk.api.session.content.ContentUrlResolver import org.matrix.android.sdk.api.session.crypto.attachments.ElementToDecrypt import org.matrix.android.sdk.api.session.media.PreviewUrlData -import timber.log.Timber -import java.io.File import javax.inject.Inject import kotlin.math.min @@ -142,7 +137,6 @@ class ImageContentRenderer @Inject constructor( else it.dontAnimate() } .transform(cornerTransformation) - // .thumbnail(0.3f) .into(imageView) } @@ -173,47 +167,11 @@ class ImageContentRenderer @Inject constructor( .load(resolvedUrl) } - req.override(Target.SIZE_ORIGINAL, Target.SIZE_ORIGINAL) + req .fitCenter() .into(target) } - fun renderFitTarget(data: Data, mode: Mode, imageView: ImageView, callback: ((Boolean) -> Unit)? = null) { - val size = processSize(data, mode) - - // a11y - imageView.contentDescription = data.filename - - createGlideRequest(data, mode, imageView, size) - .listener(object : RequestListener { - override fun onLoadFailed( - e: GlideException?, - model: Any?, - target: Target?, - isFirstResource: Boolean - ): Boolean { - callback?.invoke(false) - return false - } - - override fun onResourceReady( - resource: Drawable?, - model: Any?, - target: Target?, - dataSource: DataSource?, - isFirstResource: Boolean - ): Boolean { - callback?.invoke(true) - return false - } - }) - .fitCenter() - .into(imageView) - } - - /** - * onlyRetrieveFromCache is true! - */ fun renderForSharedElementTransition(data: Data, imageView: ImageView, callback: ((Boolean) -> Unit)? = null) { // a11y imageView.contentDescription = data.filename @@ -254,7 +212,6 @@ class ImageContentRenderer @Inject constructor( return false } }) - .onlyRetrieveFromCache(true) .fitCenter() .into(imageView) } @@ -292,32 +249,6 @@ class ImageContentRenderer @Inject constructor( } } - fun render(data: Data, imageView: BigImageView) { - // a11y - imageView.contentDescription = data.filename - - val (width, height) = processSize(data, Mode.THUMBNAIL) - val contentUrlResolver = activeSessionHolder.getActiveSession().contentUrlResolver() - val fullSize = resolveUrl(data) - val thumbnail = contentUrlResolver.resolveThumbnail(data.url, width, height, ContentUrlResolver.ThumbnailMethod.SCALE) - - if (fullSize.isNullOrBlank() || thumbnail.isNullOrBlank()) { - Timber.w("Invalid urls") - return - } - - imageView.setImageLoaderCallback(object : DefaultImageLoaderCallback { - override fun onSuccess(image: File?) { - imageView.ssiv?.orientation = ORIENTATION_USE_EXIF - } - }) - - imageView.showImage( - Uri.parse(thumbnail), - Uri.parse(fullSize) - ) - } - private fun resolveUrl(data: Data) = (activeSessionHolder.getActiveSession().contentUrlResolver().resolveFullSize(data.url) ?: data.url?.takeIf { localFilesHelper.isLocalFile(data.url) && data.allowNonMxcUrls })