From 99053e846778f6f0070a1eb474b3b7e9d6d6fadb Mon Sep 17 00:00:00 2001 From: SpiritCroc Date: Thu, 28 Apr 2022 16:53:19 +0200 Subject: [PATCH] Support inline images in the timeline Change-Id: I4af76058b400e9a0bf7c10e4ad98b7c7fb5015c1 --- FEATURES.md | 1 + dependencies.gradle | 1 + vector/build.gradle | 1 + .../app/features/html/EventHtmlRenderer.kt | 26 ++++++++++++++++++- 4 files changed, 28 insertions(+), 1 deletion(-) diff --git a/FEATURES.md b/FEATURES.md index f70b33738a..f1ffbeed31 100644 --- a/FEATURES.md +++ b/FEATURES.md @@ -29,6 +29,7 @@ Here you can find some extra features and changes compared to Element Android (w - Compose area: emoji button on the left, attachments button on the right (flipped compared to Element, but what most other messengers do, thus more familiar to most users) - Setting to re-alert for new messages even if there's still an old notification for that room - Setting to hide start call buttons from the room's toolbar +- Render inline images / custom emojis in the timeline - Branding (name, app icon, links) - Show a toast instead of a snackbar after copying text, in order to not block the input area right after copying diff --git a/dependencies.gradle b/dependencies.gradle index 81e3b1b4bc..7d22183b1a 100644 --- a/dependencies.gradle +++ b/dependencies.gradle @@ -98,6 +98,7 @@ ext.libs = [ markwon : [ 'core' : "io.noties.markwon:core:$markwon", 'extLatex' : "io.noties.markwon:ext-latex:$markwon", + 'imageGlide' : "io.noties.markwon:image-glide:$markwon", 'inlineParser' : "io.noties.markwon:inline-parser:$markwon", 'html' : "io.noties.markwon:html:$markwon" ], diff --git a/vector/build.gradle b/vector/build.gradle index dd9a692bae..886937e86d 100644 --- a/vector/build.gradle +++ b/vector/build.gradle @@ -412,6 +412,7 @@ dependencies { implementation 'me.gujun.android:span:1.7' implementation libs.markwon.core implementation libs.markwon.extLatex + implementation libs.markwon.imageGlide implementation libs.markwon.inlineParser implementation libs.markwon.html implementation 'com.googlecode.htmlcompressor:htmlcompressor:1.5.2' diff --git a/vector/src/main/java/im/vector/app/features/html/EventHtmlRenderer.kt b/vector/src/main/java/im/vector/app/features/html/EventHtmlRenderer.kt index 85a2187587..d5b95e2b76 100644 --- a/vector/src/main/java/im/vector/app/features/html/EventHtmlRenderer.kt +++ b/vector/src/main/java/im/vector/app/features/html/EventHtmlRenderer.kt @@ -18,9 +18,14 @@ package im.vector.app.features.html import android.content.Context import android.content.res.Resources +import android.graphics.drawable.Drawable import android.text.Spannable import androidx.core.text.toSpannable +import com.bumptech.glide.Glide +import com.bumptech.glide.RequestBuilder +import com.bumptech.glide.request.target.Target import im.vector.app.R +import im.vector.app.core.di.ActiveSessionHolder import im.vector.app.core.resources.ColorProvider import im.vector.app.core.utils.DimensionConverter import im.vector.app.features.settings.VectorPreferences @@ -33,6 +38,8 @@ import io.noties.markwon.PrecomputedFutureTextSetterCompat import io.noties.markwon.ext.latex.JLatexMathPlugin import io.noties.markwon.ext.latex.JLatexMathTheme import io.noties.markwon.html.HtmlPlugin +import io.noties.markwon.image.AsyncDrawable +import io.noties.markwon.image.glide.GlideImagesPlugin import io.noties.markwon.inlineparser.MarkwonInlineParserPlugin import org.commonmark.node.Node import timber.log.Timber @@ -43,6 +50,7 @@ import javax.inject.Singleton class EventHtmlRenderer @Inject constructor( private val htmlConfigure: MatrixHtmlPluginConfigure, private val context: Context, + private val activeSessionHolder: ActiveSessionHolder, private val vectorPreferences: VectorPreferences ) { @@ -68,7 +76,23 @@ class EventHtmlRenderer @Inject constructor( .codeBackgroundColor(codeBlockBackground) .blockQuoteColor(quoteBarColor) } - } + }, + GlideImagesPlugin.create(object: GlideImagesPlugin.GlideStore { + override fun load(drawable: AsyncDrawable): RequestBuilder { + val url = drawable.destination + if (url.startsWith("mxc://")) { + val contentUrlResolver = activeSessionHolder.getActiveSession().contentUrlResolver() + val imageUrl = contentUrlResolver.resolveFullSize(url) + return Glide.with(context).load(imageUrl) + } + // We don't want to support other url schemes here, so just return a request for null + return Glide.with(context).load(null as String?) + } + + override fun cancel(target: Target<*>) { + Glide.with(context).clear(target) + } + }) )) .apply { if (vectorPreferences.latexMathsIsEnabled()) {