From 978de65124b16961c57d3a08b415f8d2a4b8726e Mon Sep 17 00:00:00 2001 From: ericdecanini Date: Mon, 13 Jun 2022 12:01:21 +0200 Subject: [PATCH 1/3] Fixes large images crashing when opened --- .../features/media/ImageContentRenderer.kt | 73 +------------------ 1 file changed, 1 insertion(+), 72 deletions(-) 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 3406e8f7c4..637179cb27 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,9 @@ class ImageContentRenderer @Inject constructor( .load(resolvedUrl) } - req.override(Target.SIZE_ORIGINAL, Target.SIZE_ORIGINAL) - .fitCenter() - .into(target) + 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 +210,6 @@ class ImageContentRenderer @Inject constructor( return false } }) - .onlyRetrieveFromCache(true) .fitCenter() .into(imageView) } @@ -292,32 +247,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 }) From 2f70c1bd4dae88c85ffca391ae818b81c69a4ce0 Mon Sep 17 00:00:00 2001 From: ericdecanini Date: Mon, 13 Jun 2022 12:10:38 +0200 Subject: [PATCH 2/3] Adds changelog file --- changelog.d/6290.bugfix | 1 + 1 file changed, 1 insertion(+) create mode 100644 changelog.d/6290.bugfix 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 From c10d4a7382946df7eb470263441019635db8df0c Mon Sep 17 00:00:00 2001 From: ericdecanini Date: Tue, 14 Jun 2022 10:21:45 +0200 Subject: [PATCH 3/3] Slight formatting improvement --- .../java/im/vector/app/features/media/ImageContentRenderer.kt | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) 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 637179cb27..8ce172b829 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 @@ -167,7 +167,9 @@ class ImageContentRenderer @Inject constructor( .load(resolvedUrl) } - req.fitCenter().into(target) + req + .fitCenter() + .into(target) } fun renderForSharedElementTransition(data: Data, imageView: ImageView, callback: ((Boolean) -> Unit)? = null) {