Don't shorten message footers for mixed-direction text.

This commit is contained in:
Greyson Parrelli
2022-02-09 16:08:21 -05:00
committed by GitHub
parent 14db5ce349
commit 9802724baa
3 changed files with 76 additions and 0 deletions

View File

@@ -457,6 +457,7 @@ public final class ConversationItem extends RelativeLayout implements BindableCo
isFooterVisible(messageRecord, nextMessageRecord, groupThread) &&
!bodyText.isJumbomoji() &&
conversationMessage.getBottomButton() == null &&
!StringUtil.hasMixedTextDirection(bodyText.getText()) &&
bodyText.getLastLineWidth() > 0)
{
TextView dateView = footer.getDateView();

View File

@@ -168,6 +168,32 @@ public final class StringUtil {
return new String(Character.toChars(codePoint));
}
/**
* @return True if the provided text contains a mix of LTR and RTL characters, otherwise false.
*/
public static boolean hasMixedTextDirection(@Nullable CharSequence text) {
if (text == null) {
return false;
}
Boolean isLtr = null;
for (int i = 0, len = Character.codePointCount(text, 0, text.length()); i < len; i++) {
int codePoint = Character.codePointAt(text, i);
byte direction = Character.getDirectionality(codePoint);
if (isLtr != null && isLtr && direction != Character.DIRECTIONALITY_LEFT_TO_RIGHT) {
return true;
} else if (isLtr != null && !isLtr && direction != Character.DIRECTIONALITY_RIGHT_TO_LEFT) {
return true;
} else {
isLtr = direction == Character.DIRECTIONALITY_LEFT_TO_RIGHT;
}
}
return false;
}
/**
* Isolates bi-directional text from influencing surrounding text. You should use this whenever
* you're injecting user-generated text into a larger string.