mirror of
https://github.com/element-hq/element-android
synced 2024-11-25 02:45:37 +03:00
Timeline html rendering: better reply and pill
This commit is contained in:
parent
a9fe21e583
commit
4de421d663
2 changed files with 15 additions and 19 deletions
|
@ -17,28 +17,17 @@
|
|||
package im.vector.app.features.html
|
||||
|
||||
import io.noties.markwon.MarkwonVisitor
|
||||
import io.noties.markwon.SpannableBuilder
|
||||
import io.noties.markwon.html.HtmlTag
|
||||
import io.noties.markwon.html.MarkwonHtmlRenderer
|
||||
import io.noties.markwon.html.TagHandler
|
||||
import org.commonmark.node.BlockQuote
|
||||
|
||||
class MxReplyTagHandler : TagHandler() {
|
||||
|
||||
override fun supportedTags() = listOf("mx-reply")
|
||||
|
||||
override fun handle(visitor: MarkwonVisitor, renderer: MarkwonHtmlRenderer, tag: HtmlTag) {
|
||||
val configuration = visitor.configuration()
|
||||
val factory = configuration.spansFactory().get(BlockQuote::class.java)
|
||||
if (factory != null) {
|
||||
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)
|
||||
}
|
||||
visitChildren(visitor, renderer, tag.asBlock)
|
||||
val replyText = visitor.builder().removeFromEnd(tag.end())
|
||||
visitor.builder().append("\n\n").append(replyText)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -65,10 +65,15 @@ class PillImageSpan(private val glideRequests: GlideRequests,
|
|||
fm: Paint.FontMetricsInt?): Int {
|
||||
val rect = pillDrawable.bounds
|
||||
if (fm != null) {
|
||||
fm.ascent = -rect.bottom
|
||||
fm.descent = 0
|
||||
fm.top = fm.ascent
|
||||
fm.bottom = 0
|
||||
val fmPaint = paint.fontMetricsInt
|
||||
val fontHeight = fmPaint.bottom - fmPaint.top
|
||||
val drHeight = rect.bottom - rect.top
|
||||
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
|
||||
}
|
||||
|
@ -82,7 +87,9 @@ class PillImageSpan(private val glideRequests: GlideRequests,
|
|||
bottom: Int,
|
||||
paint: Paint) {
|
||||
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())
|
||||
pillDrawable.draw(canvas)
|
||||
canvas.restore()
|
||||
|
|
Loading…
Reference in a new issue