diff --git a/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/messages/QuoteView.kt b/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/messages/QuoteView.kt index 0f6fe2773..d873978ca 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/messages/QuoteView.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/messages/QuoteView.kt @@ -78,11 +78,13 @@ class QuoteView : LinearLayout { } val body = quoteViewBodyTextView.text val bodyTextViewIntrinsicHeight = TextUtilities.getIntrinsicHeight(body, quoteViewBodyTextView.paint, maxContentWidth) + val staticLayout = TextUtilities.getIntrinsicLayout(body, quoteViewBodyTextView.paint, maxContentWidth) result += bodyTextViewIntrinsicHeight if (!quoteViewAuthorTextView.isVisible) { - // We want to at least be as high as the cancel button, and no higher than 56 DP (that's - // approximately the height of 3 lines. - return min(max(result, toPx(32, resources)), toPx(56, resources)) + // We want to at least be as high as the cancel button 36DP, and no higher than 3 lines of text. + // Height from intrinsic layout is the height of the text before truncation so we shorten + // proportionally to our max lines setting. + return max(toPx(32, resources) ,min((result / staticLayout.lineCount) * 3, result)) } else { // Because we're showing the author text view, we should have a height of at least 32 DP // anyway, so there's no need to constrain to that. We constrain to a max height of 56 DP @@ -97,7 +99,7 @@ class QuoteView : LinearLayout { // and then center everything inside vertically. This effectively means we're applying padding. // Applying padding the regular way results in a clipping issue though due to a bug in // RelativeLayout. - return getIntrinsicContentHeight(maxContentWidth) + 2 * vPadding + return getIntrinsicContentHeight(maxContentWidth) + (2 * vPadding ) } // endregion diff --git a/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/utilities/TextUtilities.kt b/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/utilities/TextUtilities.kt index b7ced4abb..800ace54c 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/utilities/TextUtilities.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/utilities/TextUtilities.kt @@ -20,6 +20,14 @@ object TextUtilities { return layout.height } + fun getIntrinsicLayout(text: CharSequence, paint: TextPaint, width: Int): StaticLayout { + val builder = StaticLayout.Builder.obtain(text, 0, text.length, paint, width) + .setAlignment(Layout.Alignment.ALIGN_NORMAL) + .setLineSpacing(0.0f, 1.0f) + .setIncludePad(false) + return builder.build() + } + fun TextView.getIntersectedModalSpans(event: MotionEvent): List { val xInt = event.rawX.toInt() val yInt = event.rawY.toInt() diff --git a/app/src/main/res/layout/view_quote.xml b/app/src/main/res/layout/view_quote.xml index d2835c8fb..32112435a 100644 --- a/app/src/main/res/layout/view_quote.xml +++ b/app/src/main/res/layout/view_quote.xml @@ -67,11 +67,11 @@ android:id="@+id/quoteViewBodyTextView" android:layout_width="wrap_content" android:layout_height="wrap_content" - android:text="Yo, I need your help here!" - android:textSize="@dimen/small_font_size" - android:textColor="@color/text" + android:ellipsize="end" android:maxLines="3" - android:ellipsize="end" /> + android:text="Yo, I need your help here!" + android:textColor="@color/text" + android:textSize="@dimen/small_font_size" />