Browse Source

Include textview left padding while calculating last line width in text messages. For austinhuang0131/barinsta#1222

renovate/org.robolectric-robolectric-4.x
Ammar Githam 4 years ago
parent
commit
79fe697167
  1. 17
      app/src/main/java/awais/instagrabber/customviews/ChatMessageLayout.java
  2. 15
      app/src/main/res/layout/layout_dm_base.xml
  3. 2
      app/src/main/res/layout/layout_dm_text.xml

17
app/src/main/java/awais/instagrabber/customviews/ChatMessageLayout.java

@ -105,12 +105,15 @@ public class ChatMessageLayout extends FrameLayout {
viewPartMainLastLineWidth = viewPartMainLineCount > 0 viewPartMainLastLineWidth = viewPartMainLineCount > 0
? ((TextView) firstChild).getLayout().getLineWidth(viewPartMainLineCount - 1) ? ((TextView) firstChild).getLayout().getLineWidth(viewPartMainLineCount - 1)
: 0; : 0;
// also include start left padding
viewPartMainLastLineWidth += firstChild.getPaddingLeft();
} }
if (viewPartMainLineCount > 1 && !(viewPartMainLastLineWidth + viewPartInfoWidth > viewPartMain.getMeasuredWidth())) {
final float lastLineWithInfoWidth = viewPartMainLastLineWidth + viewPartInfoWidth;
if (viewPartMainLineCount > 1 && lastLineWithInfoWidth <= viewPartMain.getMeasuredWidth()) {
widthSize += viewPartMainWidth; widthSize += viewPartMainWidth;
heightSize += viewPartMainHeight; heightSize += viewPartMainHeight;
} else if (viewPartMainLineCount > 1 && (viewPartMainLastLineWidth + viewPartInfoWidth > availableWidth)) {
} else if (viewPartMainLineCount > 1 && (lastLineWithInfoWidth > availableWidth)) {
widthSize += viewPartMainWidth; widthSize += viewPartMainWidth;
heightSize += viewPartMainHeight + viewPartInfoHeight; heightSize += viewPartMainHeight + viewPartInfoHeight;
} else if (viewPartMainLineCount == 1 && (viewPartMainWidth + viewPartInfoWidth > availableWidth)) { } else if (viewPartMainLineCount == 1 && (viewPartMainWidth + viewPartInfoWidth > availableWidth)) {
@ -120,6 +123,16 @@ public class ChatMessageLayout extends FrameLayout {
heightSize += viewPartMainHeight; heightSize += viewPartMainHeight;
widthSize += viewPartMainWidth + viewPartInfoWidth; widthSize += viewPartMainWidth + viewPartInfoWidth;
} }
// if (isInEditMode()) {
// TextView wDebugView = (TextView) ((ViewGroup) this.getParent()).findViewWithTag("debug");
// wDebugView.setText(lastLineWithInfoWidth
// + "\n" + availableWidth
// + "\n" + viewPartMain.getMeasuredWidth()
// + "\n" + (lastLineWithInfoWidth <= viewPartMain.getMeasuredWidth())
// + "\n" + (lastLineWithInfoWidth > availableWidth)
// + "\n" + (viewPartMainWidth + viewPartInfoWidth > availableWidth));
// }
} }
setMeasuredDimension(widthSize, heightSize); setMeasuredDimension(widthSize, heightSize);
super.onMeasure(MeasureSpec.makeMeasureSpec(widthSize, MeasureSpec.EXACTLY), MeasureSpec.makeMeasureSpec(heightSize, MeasureSpec.EXACTLY)); super.onMeasure(MeasureSpec.makeMeasureSpec(widthSize, MeasureSpec.EXACTLY), MeasureSpec.makeMeasureSpec(heightSize, MeasureSpec.EXACTLY));

15
app/src/main/res/layout/layout_dm_base.xml

@ -139,7 +139,9 @@
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
tools:layout_height="200dp" tools:layout_height="200dp"
tools:layout_width="100dp" />
tools:layout_width="100dp">
<!--<include layout="@layout/layout_dm_text" />-->
</FrameLayout>
<LinearLayout <LinearLayout
android:id="@+id/message_info" android:id="@+id/message_info"
@ -176,6 +178,17 @@
</awais.instagrabber.customviews.ChatMessageLayout> </awais.instagrabber.customviews.ChatMessageLayout>
<!--<TextView-->
<!-- android:tag="debug"-->
<!-- android:textColor="@color/white"-->
<!-- android:layout_width="0dp"-->
<!-- android:visibility="visible"-->
<!-- android:layout_height="wrap_content"-->
<!-- android:background="@color/black"-->
<!-- app:layout_constraintTop_toTopOf="parent"-->
<!-- app:layout_constraintStart_toStartOf="parent"-->
<!-- app:layout_constraintEnd_toEndOf="parent"/>-->
<FrameLayout <FrameLayout
android:id="@+id/reactions_wrapper" android:id="@+id/reactions_wrapper"
android:layout_width="0dp" android:layout_width="0dp"

2
app/src/main/res/layout/layout_dm_text.xml

@ -10,4 +10,4 @@
android:paddingBottom="@dimen/dm_message_card_radius_small" android:paddingBottom="@dimen/dm_message_card_radius_small"
android:textAppearance="@style/TextAppearance.MaterialComponents.Body1" android:textAppearance="@style/TextAppearance.MaterialComponents.Body1"
android:textColor="@color/white" android:textColor="@color/white"
tools:text="Text message" />
tools:text="So here you can see the timestamp overlaps lol tt tt tt tt tt tt tt tt tt tt t" />
Loading…
Cancel
Save