mirror of
https://github.com/element-hq/element-android
synced 2024-11-24 10:25:35 +03:00
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:
commit
2f2dae89f7
2 changed files with 2 additions and 70 deletions
1
changelog.d/6290.bugfix
Normal file
1
changelog.d/6290.bugfix
Normal file
|
@ -0,0 +1 @@
|
|||
Fixed crash when opening large images in the timeline
|
|
@ -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<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) {
|
||||
// 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 })
|
||||
|
|
Loading…
Reference in a new issue