From 79fe69716795067291029d1a8540bb3fff34312c Mon Sep 17 00:00:00 2001 From: Ammar Githam Date: Mon, 10 May 2021 23:03:37 +0900 Subject: [PATCH] Include textview left padding while calculating last line width in text messages. For austinhuang0131/barinsta#1222 --- .../customviews/ChatMessageLayout.java | 17 +++++++++++++++-- app/src/main/res/layout/layout_dm_base.xml | 15 ++++++++++++++- app/src/main/res/layout/layout_dm_text.xml | 2 +- 3 files changed, 30 insertions(+), 4 deletions(-) diff --git a/app/src/main/java/awais/instagrabber/customviews/ChatMessageLayout.java b/app/src/main/java/awais/instagrabber/customviews/ChatMessageLayout.java index 1731dbf3..c0568a70 100644 --- a/app/src/main/java/awais/instagrabber/customviews/ChatMessageLayout.java +++ b/app/src/main/java/awais/instagrabber/customviews/ChatMessageLayout.java @@ -105,12 +105,15 @@ public class ChatMessageLayout extends FrameLayout { viewPartMainLastLineWidth = viewPartMainLineCount > 0 ? ((TextView) firstChild).getLayout().getLineWidth(viewPartMainLineCount - 1) : 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; heightSize += viewPartMainHeight; - } else if (viewPartMainLineCount > 1 && (viewPartMainLastLineWidth + viewPartInfoWidth > availableWidth)) { + } else if (viewPartMainLineCount > 1 && (lastLineWithInfoWidth > availableWidth)) { widthSize += viewPartMainWidth; heightSize += viewPartMainHeight + viewPartInfoHeight; } else if (viewPartMainLineCount == 1 && (viewPartMainWidth + viewPartInfoWidth > availableWidth)) { @@ -120,6 +123,16 @@ public class ChatMessageLayout extends FrameLayout { heightSize += viewPartMainHeight; 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); super.onMeasure(MeasureSpec.makeMeasureSpec(widthSize, MeasureSpec.EXACTLY), MeasureSpec.makeMeasureSpec(heightSize, MeasureSpec.EXACTLY)); diff --git a/app/src/main/res/layout/layout_dm_base.xml b/app/src/main/res/layout/layout_dm_base.xml index fd6c61da..6720f42d 100644 --- a/app/src/main/res/layout/layout_dm_base.xml +++ b/app/src/main/res/layout/layout_dm_base.xml @@ -139,7 +139,9 @@ android:layout_width="wrap_content" android:layout_height="wrap_content" tools:layout_height="200dp" - tools:layout_width="100dp" /> + tools:layout_width="100dp"> + + + + + + + + + + + + + \ No newline at end of file + tools:text="So here you can see the timestamp overlaps lol tt tt tt tt tt tt tt tt tt tt t" /> \ No newline at end of file