Autoscale story text so all content fits in viewer.

This commit is contained in:
Alex Hart
2022-10-13 15:47:33 -03:00
committed by Greyson Parrelli
parent b6db7e7af6
commit a0172ddb2f
3 changed files with 9 additions and 10 deletions

View File

@@ -9,6 +9,7 @@ import android.widget.TextView
import org.signal.core.util.BreakIteratorCompat
import org.signal.core.util.DimensionUnit
import org.signal.core.util.EditTextUtil
import org.thoughtcrime.securesms.util.doOnEachLayout
class TextStoryTextWatcher private constructor(private val textView: TextView) : TextWatcher {
@@ -45,6 +46,14 @@ class TextStoryTextWatcher private constructor(private val textView: TextView) :
if (textView is EditText) {
EditTextUtil.addGraphemeClusterLimitFilter(textView, 700)
} else {
textView.doOnEachLayout {
val contentHeight = textView.height - textView.paddingTop - textView.paddingBottom
if (textView.layout != null && textView.layout.height > contentHeight) {
val percentShown = contentHeight / textView.layout.height.toFloat()
textView.setTextSize(TypedValue.COMPLEX_UNIT_PX, DimensionUnit.DP.toPixels(18f * percentShown))
}
}
}
textView.addTextChangedListener(watcher)