fix: support RTL usernames in comment header
The `@` gets added by the youtube API and thus is a fixed member of the username, so we do some simple detection logic to handle that case (otherwise the `@` will be at the right side of a RTL username, which is different of how Youtube displays these usernames in the browser). Fixes https://github.com/TeamNewPipe/NewPipe/issues/12141
This commit is contained in:
parent
48e826e912
commit
8d679626f0
2 changed files with 26 additions and 4 deletions
|
|
@ -11,6 +11,7 @@ import android.icu.text.CompactDecimalFormat;
|
|||
import android.os.Build;
|
||||
import android.text.TextUtils;
|
||||
import android.text.format.DateUtils;
|
||||
import android.text.BidiFormatter;
|
||||
import android.util.DisplayMetrics;
|
||||
import android.util.Log;
|
||||
|
||||
|
|
@ -85,6 +86,25 @@ public final class Localization {
|
|||
.collect(Collectors.joining(delimiter));
|
||||
}
|
||||
|
||||
/**
|
||||
* Localize a user name like <code>@foobar</code>.
|
||||
*
|
||||
* Will correctly handle right-to-left usernames by using a {@link BidiFormatter}.
|
||||
*
|
||||
* @param plainName username, with an optional leading <code>@</code>
|
||||
* @return a usernames that can include RTL-characters
|
||||
*/
|
||||
@NonNull
|
||||
public static String localizeUserName(final String plainName) {
|
||||
final BidiFormatter bidi = BidiFormatter.getInstance();
|
||||
|
||||
if (plainName.startsWith("@")) {
|
||||
return "@" + bidi.unicodeWrap(plainName.substring(1));
|
||||
} else {
|
||||
return bidi.unicodeWrap(plainName);
|
||||
}
|
||||
}
|
||||
|
||||
public static org.schabi.newpipe.extractor.localization.Localization getPreferredLocalization(
|
||||
final Context context) {
|
||||
return org.schabi.newpipe.extractor.localization.Localization
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue