Merge pull request #6290 from vector-im/bugfix/eric/fix-large-image-crash

Fixes large images crashing when opened in timeline
This commit is contained in:
Eric Decanini 2022-06-16 11:04:00 +02:00 committed by GitHub
commit 2f2dae89f7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 2 additions and 70 deletions

1
changelog.d/6290.bugfix Normal file
View File

@ -0,0 +1 @@
Fixed crash when opening large images in the timeline

View File

@ -18,7 +18,6 @@ package im.vector.app.features.media
import android.graphics.Bitmap import android.graphics.Bitmap
import android.graphics.drawable.Drawable import android.graphics.drawable.Drawable
import android.net.Uri
import android.os.Parcelable import android.os.Parcelable
import android.view.View import android.view.View
import android.widget.ImageView 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.RequestListener
import com.bumptech.glide.request.target.CustomViewTarget import com.bumptech.glide.request.target.CustomViewTarget
import com.bumptech.glide.request.target.Target 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.R
import im.vector.app.core.di.ActiveSessionHolder import im.vector.app.core.di.ActiveSessionHolder
import im.vector.app.core.files.LocalFilesHelper 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.content.ContentUrlResolver
import org.matrix.android.sdk.api.session.crypto.attachments.ElementToDecrypt import org.matrix.android.sdk.api.session.crypto.attachments.ElementToDecrypt
import org.matrix.android.sdk.api.session.media.PreviewUrlData import org.matrix.android.sdk.api.session.media.PreviewUrlData
import timber.log.Timber
import java.io.File
import javax.inject.Inject import javax.inject.Inject
import kotlin.math.min import kotlin.math.min
@ -142,7 +137,6 @@ class ImageContentRenderer @Inject constructor(
else it.dontAnimate() else it.dontAnimate()
} }
.transform(cornerTransformation) .transform(cornerTransformation)
// .thumbnail(0.3f)
.into(imageView) .into(imageView)
} }
@ -173,47 +167,11 @@ class ImageContentRenderer @Inject constructor(
.load(resolvedUrl) .load(resolvedUrl)
} }
req.override(Target.SIZE_ORIGINAL, Target.SIZE_ORIGINAL) req
.fitCenter() .fitCenter()
.into(target) .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<Drawable> {
override fun onLoadFailed(
e: GlideException?,
model: Any?,
target: Target<Drawable>?,
isFirstResource: Boolean
): Boolean {
callback?.invoke(false)
return false
}
override fun onResourceReady(
resource: Drawable?,
model: Any?,
target: Target<Drawable>?,
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) { fun renderForSharedElementTransition(data: Data, imageView: ImageView, callback: ((Boolean) -> Unit)? = null) {
// a11y // a11y
imageView.contentDescription = data.filename imageView.contentDescription = data.filename
@ -254,7 +212,6 @@ class ImageContentRenderer @Inject constructor(
return false return false
} }
}) })
.onlyRetrieveFromCache(true)
.fitCenter() .fitCenter()
.into(imageView) .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) = private fun resolveUrl(data: Data) =
(activeSessionHolder.getActiveSession().contentUrlResolver().resolveFullSize(data.url) (activeSessionHolder.getActiveSession().contentUrlResolver().resolveFullSize(data.url)
?: data.url?.takeIf { localFilesHelper.isLocalFile(data.url) && data.allowNonMxcUrls }) ?: data.url?.takeIf { localFilesHelper.isLocalFile(data.url) && data.allowNonMxcUrls })