mirror of
https://github.com/SchildiChat/SchildiChat-android.git
synced 2024-11-29 14:38:45 +03:00
Do not cut italic text, v2
Different implementaion than the one which got lost during a recent upstream merge Change-Id: Ic4b0474bd95a9746cfecc8aff8562c330e296b5a
This commit is contained in:
parent
7bfd3c8dca
commit
b3d9ddbeca
2 changed files with 16 additions and 3 deletions
|
@ -12,6 +12,7 @@ import androidx.core.text.getSpans
|
|||
import androidx.core.text.toSpanned
|
||||
import im.vector.app.R
|
||||
import im.vector.app.features.html.HtmlCodeSpan
|
||||
import io.noties.markwon.core.spans.EmphasisSpan
|
||||
import kotlin.math.ceil
|
||||
import kotlin.math.max
|
||||
|
||||
|
@ -96,14 +97,20 @@ class FooteredTextView @JvmOverloads constructor(
|
|||
) + footerWidth
|
||||
|
||||
// If the last line is a multi-line code block, we have never space in the last line (as the black background always uses full width)
|
||||
val forceNewlineFooter = if (text is Spannable || text is Spanned) {
|
||||
val forceNewlineFooter: Boolean
|
||||
// For italic text, we need some extra space due to a wrap_content bug: https://stackoverflow.com/q/4353836
|
||||
val addItalicPadding: Boolean
|
||||
|
||||
if (text is Spannable || text is Spanned) {
|
||||
val span = text.toSpanned()
|
||||
// If not found, -1+1 = 0
|
||||
val lastLineStart = span.lastIndexOf("\n") + 1
|
||||
val lastLineCodeSpans = span.getSpans<HtmlCodeSpan>(lastLineStart)
|
||||
lastLineCodeSpans.any { it.isBlock }
|
||||
forceNewlineFooter = lastLineCodeSpans.any { it.isBlock }
|
||||
addItalicPadding = span.getSpans<EmphasisSpan>().isNotEmpty()
|
||||
} else {
|
||||
false
|
||||
forceNewlineFooter = false
|
||||
addItalicPadding = false
|
||||
}
|
||||
|
||||
// Is there space for a horizontal footer?
|
||||
|
@ -121,6 +128,10 @@ class FooteredTextView @JvmOverloads constructor(
|
|||
newHeight += footerHeight
|
||||
}
|
||||
|
||||
if (addItalicPadding) {
|
||||
newWidth += resources.getDimensionPixelSize(R.dimen.italic_text_view_extra_padding)
|
||||
}
|
||||
|
||||
setMeasuredDimension(newWidth, newHeight)
|
||||
}
|
||||
|
||||
|
|
|
@ -38,6 +38,8 @@
|
|||
<!-- sc_footer_margin_start + sc_footer_padding_compensation -->
|
||||
<dimen name="sc_footer_reverse_margin_end">8dp</dimen>
|
||||
<dimen name="sc_footer_rtl_mismatch_extra_padding">4dp</dimen>
|
||||
<!-- Android TextView's wrap_content has some bug with italic text: https://stackoverflow.com/q/4353836 -->
|
||||
<dimen name="italic_text_view_extra_padding">2sp</dimen>
|
||||
|
||||
<dimen name="file_icon_size">32dp</dimen>
|
||||
|
||||
|
|
Loading…
Reference in a new issue