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

fork-5.53.8
Greyson Parrelli 2022-02-09 16:08:21 -05:00 zatwierdzone przez GitHub
rodzic 14db5ce349
commit 9802724baa
Nie znaleziono w bazie danych klucza dla tego podpisu
ID klucza GPG: 4AEE18F83AFDEB23
3 zmienionych plików z 76 dodań i 0 usunięć

Wyświetl plik

@ -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();

Wyświetl plik

@ -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.

Wyświetl plik

@ -0,0 +1,49 @@
package org.thoughtcrime.securesms.util;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import java.util.Arrays;
import java.util.Collection;
import static org.junit.Assert.assertEquals;
@RunWith(Parameterized.class)
public final class StringUtilTest_hasMixedTextDirection {
private final CharSequence input;
private final boolean expected;
@Parameterized.Parameters
public static Collection<Object[]> data() {
return Arrays.asList(new Object[][]{
{ "", false },
{ null, false },
{ "A", false},
{ "ة", false}, // Arabic
{ "ی", false}, // Kurdish
{ "ی", false }, // Farsi
{ "و", false }, // Urdu
{ "ת", false }, // Hebrew
{ "ש", false }, // Yiddish
{ "Aة", true }, // Arabic-ASCII
{ "یA", true }, // Kurdish-ASCII
{ "Aی", true }, // Farsi-ASCII
{ "وA", true }, // Urdu-ASCII
{ "Aת", true }, // Hebrew-ASCII
{ "שA", true }, // Yiddish-ASCII
});
}
public StringUtilTest_hasMixedTextDirection(CharSequence input, boolean expected) {
this.input = input;
this.expected = expected;
}
@Test
public void trim() {
boolean output = StringUtil.hasMixedTextDirection(input);
assertEquals(expected, output);
}
}