Fixes large images crashing when opened

This commit is contained in:
ericdecanini 2022-06-13 12:01:21 +02:00
parent 3f491018b4
commit 978de65124
1 changed files with 1 additions and 72 deletions

View File

@ -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<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 +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 })