Fixed padding issue in multi line text view in chat

This commit is contained in:
Sylvain Berfini 2023-06-26 15:10:00 +02:00
parent 226095bec7
commit c4eb94a9bf
2 changed files with 11 additions and 8 deletions

View file

@ -25,6 +25,8 @@ import android.text.method.LinkMovementMethod
import android.util.AttributeSet import android.util.AttributeSet
import androidx.appcompat.widget.AppCompatTextView import androidx.appcompat.widget.AppCompatTextView
import kotlin.math.ceil import kotlin.math.ceil
import kotlin.math.max
import kotlin.math.round
/** /**
* The purpose of this class is to have a TextView declared with wrap_content as width that won't * The purpose of this class is to have a TextView declared with wrap_content as width that won't
@ -52,10 +54,12 @@ class MultiLineWrapContentWidthTextView : AppCompatTextView {
if (layout != null && layout.lineCount >= 2) { if (layout != null && layout.lineCount >= 2) {
val maxLineWidth = ceil(getMaxLineWidth(layout)).toInt() val maxLineWidth = ceil(getMaxLineWidth(layout)).toInt()
val uselessPaddingWidth = layout.width - maxLineWidth if (maxLineWidth < measuredWidth) {
val width = measuredWidth - uselessPaddingWidth super.onMeasure(
val height = measuredHeight MeasureSpec.makeMeasureSpec(maxLineWidth, MeasureSpec.getMode(widthSpec)),
setMeasuredDimension(width, height) heightSpec
)
}
} }
} }
@ -63,10 +67,8 @@ class MultiLineWrapContentWidthTextView : AppCompatTextView {
var maxWidth = 0.0f var maxWidth = 0.0f
val lines = layout.lineCount val lines = layout.lineCount
for (i in 0 until lines) { for (i in 0 until lines) {
if (layout.getLineWidth(i) > maxWidth) { maxWidth = max(maxWidth, layout.getLineWidth(i))
maxWidth = layout.getLineWidth(i)
} }
} return round(maxWidth)
return maxWidth
} }
} }

View file

@ -53,6 +53,7 @@ class CorePreferences constructor(private val context: Context) {
context, context,
MasterKey.DEFAULT_MASTER_KEY_ALIAS MasterKey.DEFAULT_MASTER_KEY_ALIAS
).setKeyScheme(MasterKey.KeyScheme.AES256_GCM).build() ).setKeyScheme(MasterKey.KeyScheme.AES256_GCM).build()
try { try {
EncryptedSharedPreferences.create( EncryptedSharedPreferences.create(
context, context,