Support webp rendering in the timeline

Change-Id: I701cc96bdc466e1de961222e30d25289a159557e
This commit is contained in:
SpiritCroc 2023-02-19 09:49:19 +01:00
parent 6887589b9e
commit 9521814f32
6 changed files with 21 additions and 8 deletions

View file

@ -149,6 +149,7 @@ ext.libs = [
'glideImageLoader' : "com.github.piasy:GlideImageLoader:$bigImageViewer", 'glideImageLoader' : "com.github.piasy:GlideImageLoader:$bigImageViewer",
'progressPieIndicator' : "com.github.piasy:ProgressPieIndicator:$bigImageViewer", 'progressPieIndicator' : "com.github.piasy:ProgressPieIndicator:$bigImageViewer",
'glideImageViewFactory' : "com.github.piasy:GlideImageViewFactory:$bigImageViewer", 'glideImageViewFactory' : "com.github.piasy:GlideImageViewFactory:$bigImageViewer",
'glideWebpDecoder' : "com.github.zjupure:webpdecoder:2.3.$glide",
'flowBinding' : "io.github.reactivecircus.flowbinding:flowbinding-android:$flowBinding", 'flowBinding' : "io.github.reactivecircus.flowbinding:flowbinding-android:$flowBinding",
'flowBindingAppcompat' : "io.github.reactivecircus.flowbinding:flowbinding-appcompat:$flowBinding", 'flowBindingAppcompat' : "io.github.reactivecircus.flowbinding:flowbinding-appcompat:$flowBinding",
'flowBindingMaterial' : "io.github.reactivecircus.flowbinding:flowbinding-material:$flowBinding" 'flowBindingMaterial' : "io.github.reactivecircus.flowbinding:flowbinding-material:$flowBinding"

View file

@ -82,6 +82,7 @@ ext.groups = [
'com.github.piasy', 'com.github.piasy',
'com.github.shyiko.klob', 'com.github.shyiko.klob',
'com.github.rubensousa', 'com.github.rubensousa',
'com.github.zjupure',
'com.google', 'com.google',
'com.google.android', 'com.google.android',
'com.google.api.grpc', 'com.google.api.grpc',

View file

@ -30,6 +30,7 @@ object MimeTypes {
const val BadJpg = "image/jpg" const val BadJpg = "image/jpg"
const val Jpeg = "image/jpeg" const val Jpeg = "image/jpeg"
const val Gif = "image/gif" const val Gif = "image/gif"
const val Webp = "image/webp"
const val Ogg = "audio/ogg" const val Ogg = "audio/ogg"

View file

@ -218,6 +218,7 @@ dependencies {
implementation libs.github.bigImageViewer implementation libs.github.bigImageViewer
implementation libs.github.glideImageLoader implementation libs.github.glideImageLoader
implementation libs.github.glideImageViewFactory implementation libs.github.glideImageViewFactory
implementation libs.github.glideWebpDecoder
// implementation 'com.github.MikeOrtiz:TouchImageView:3.0.2' // implementation 'com.github.MikeOrtiz:TouchImageView:3.0.2'
implementation 'com.github.chrisbanes:PhotoView:2.3.0' implementation 'com.github.chrisbanes:PhotoView:2.3.0'

View file

@ -538,10 +538,13 @@ class MessageItemFactory @Inject constructor(
allowNonMxcUrls = informationData.sendState.isSending() allowNonMxcUrls = informationData.sendState.isSending()
) )
val playable = messageContent.mimeType == MimeTypes.Gif // The webp library doesn't allow us to not animate images.
// Furthermore, its corner transformations are wrong when not using the animated case for rendering.
val forcePlay = messageContent.mimeType == MimeTypes.Webp
val playable = messageContent.mimeType == MimeTypes.Gif || forcePlay
return MessageImageVideoItem_() return MessageImageVideoItem_()
.attributes(attributes) .attributes(attributes.takeUnless { forcePlay && !it.autoplayAnimatedImages } ?: attributes.copy(autoplayAnimatedImages = true))
.leftGuideline(avatarSizeProvider.leftGuideline) .leftGuideline(avatarSizeProvider.leftGuideline)
.imageContentRenderer(imageContentRenderer) .imageContentRenderer(imageContentRenderer)
.contentUploadStateTrackerBinder(contentUploadStateTrackerBinder) .contentUploadStateTrackerBinder(contentUploadStateTrackerBinder)
@ -552,14 +555,16 @@ class MessageItemFactory @Inject constructor(
.inReplyToClickCallback(callback) .inReplyToClickCallback(callback)
.mediaData(data) .mediaData(data)
.apply { .apply {
if (messageContent.msgType == MessageType.MSGTYPE_STICKER_LOCAL) { val inMemory = if (messageContent.msgType == MessageType.MSGTYPE_STICKER_LOCAL) {
mode(ImageContentRenderer.Mode.STICKER) mode(ImageContentRenderer.Mode.STICKER)
clickListener { view -> listOf(data)
callback?.onImageMessageClicked(messageContent, data, view, listOf(data))
}
} else { } else {
emptyList()
}
// Big image viewer doesn't support webp
if (messageContent.mimeType != MimeTypes.Webp) {
clickListener { view -> clickListener { view ->
callback?.onImageMessageClicked(messageContent, data, view, emptyList()) callback?.onImageMessageClicked(messageContent, data, view, inMemory)
} }
} }
}.apply { }.apply {

View file

@ -24,6 +24,8 @@ import android.widget.ImageView
import androidx.core.view.isGone import androidx.core.view.isGone
import androidx.core.view.isVisible import androidx.core.view.isVisible
import androidx.core.view.updateLayoutParams import androidx.core.view.updateLayoutParams
import com.bumptech.glide.integration.webp.decoder.WebpDrawable
import com.bumptech.glide.integration.webp.decoder.WebpDrawableTransformation
import com.bumptech.glide.load.DataSource import com.bumptech.glide.load.DataSource
import com.bumptech.glide.load.Transformation import com.bumptech.glide.load.Transformation
import com.bumptech.glide.load.engine.DiskCacheStrategy import com.bumptech.glide.load.engine.DiskCacheStrategy
@ -180,7 +182,9 @@ class ImageContentRenderer @Inject constructor(
}) })
request = if (animate && mode == Mode.ANIMATED_THUMBNAIL) { request = if (animate && mode == Mode.ANIMATED_THUMBNAIL) {
// Glide seems to already do some dp to px calculation for animated gifs? // Glide seems to already do some dp to px calculation for animated gifs?
request.transform(RoundedCorners(cornerRoundnessDp)) val animatedCornerTransformation = RoundedCorners(cornerRoundnessDp)
request.transform(animatedCornerTransformation)
.transform(WebpDrawable::class.java, WebpDrawableTransformation(animatedCornerTransformation))
//request.apply(RequestOptions.bitmapTransform(RoundedCorners(3))) //request.apply(RequestOptions.bitmapTransform(RoundedCorners(3)))
} else { } else {
request.dontAnimate() request.dontAnimate()