Timeline html rendering: better reply and pill

This commit is contained in:
ganfra 2022-01-27 18:17:56 +01:00
parent a9fe21e583
commit 4de421d663
2 changed files with 15 additions and 19 deletions

View File

@ -17,28 +17,17 @@
package im.vector.app.features.html package im.vector.app.features.html
import io.noties.markwon.MarkwonVisitor import io.noties.markwon.MarkwonVisitor
import io.noties.markwon.SpannableBuilder
import io.noties.markwon.html.HtmlTag import io.noties.markwon.html.HtmlTag
import io.noties.markwon.html.MarkwonHtmlRenderer import io.noties.markwon.html.MarkwonHtmlRenderer
import io.noties.markwon.html.TagHandler import io.noties.markwon.html.TagHandler
import org.commonmark.node.BlockQuote
class MxReplyTagHandler : TagHandler() { class MxReplyTagHandler : TagHandler() {
override fun supportedTags() = listOf("mx-reply") override fun supportedTags() = listOf("mx-reply")
override fun handle(visitor: MarkwonVisitor, renderer: MarkwonHtmlRenderer, tag: HtmlTag) { override fun handle(visitor: MarkwonVisitor, renderer: MarkwonHtmlRenderer, tag: HtmlTag) {
val configuration = visitor.configuration() visitChildren(visitor, renderer, tag.asBlock)
val factory = configuration.spansFactory().get(BlockQuote::class.java) val replyText = visitor.builder().removeFromEnd(tag.end())
if (factory != null) { visitor.builder().append("\n\n").append(replyText)
SpannableBuilder.setSpans(
visitor.builder(),
factory.getSpans(configuration, visitor.renderProps()),
tag.start(),
tag.end()
)
val replyText = visitor.builder().removeFromEnd(tag.end())
visitor.builder().append("\n\n").append(replyText)
}
} }
} }

View File

@ -65,10 +65,15 @@ class PillImageSpan(private val glideRequests: GlideRequests,
fm: Paint.FontMetricsInt?): Int { fm: Paint.FontMetricsInt?): Int {
val rect = pillDrawable.bounds val rect = pillDrawable.bounds
if (fm != null) { if (fm != null) {
fm.ascent = -rect.bottom val fmPaint = paint.fontMetricsInt
fm.descent = 0 val fontHeight = fmPaint.bottom - fmPaint.top
fm.top = fm.ascent val drHeight = rect.bottom - rect.top
fm.bottom = 0 val top = drHeight / 2 - fontHeight / 4
val bottom = drHeight / 2 + fontHeight / 4
fm.ascent = -bottom
fm.top = -bottom
fm.bottom = top
fm.descent = top
} }
return rect.right return rect.right
} }
@ -82,7 +87,9 @@ class PillImageSpan(private val glideRequests: GlideRequests,
bottom: Int, bottom: Int,
paint: Paint) { paint: Paint) {
canvas.save() canvas.save()
val transY = bottom - pillDrawable.bounds.bottom val fm = paint.fontMetricsInt
val transY: Int = y + (fm.descent + fm.ascent - pillDrawable.bounds.bottom) / 2
canvas.save()
canvas.translate(x, transY.toFloat()) canvas.translate(x, transY.toFloat())
pillDrawable.draw(canvas) pillDrawable.draw(canvas)
canvas.restore() canvas.restore()