Skip to content

Commit 8d67962

Browse files
VougJo23Profpatsch
authored andcommitted
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 #12141
1 parent 48e826e commit 8d67962

File tree

2 files changed

+26
-4
lines changed

2 files changed

+26
-4
lines changed

app/src/main/java/org/schabi/newpipe/info_list/holder/CommentInfoItemHolder.java

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -101,14 +101,16 @@ public void updateFromItem(final InfoItem infoItem,
101101
}
102102
itemThumbnailView.setOnClickListener(view -> openCommentAuthor(item));
103103

104-
105104
// setup the top row, with pinned icon, author name and comment date
106105
itemPinnedView.setVisibility(item.isPinned() ? View.VISIBLE : View.GONE);
107-
itemTitleView.setText(Localization.concatenateStrings(item.getUploaderName(),
108-
Localization.relativeTimeOrTextual(itemBuilder.getContext(), item.getUploadDate(),
106+
final String uploaderName = Localization.localizeUserName(item.getUploaderName());
107+
itemTitleView.setText(Localization.concatenateStrings(
108+
uploaderName,
109+
Localization.relativeTimeOrTextual(
110+
itemBuilder.getContext(),
111+
item.getUploadDate(),
109112
item.getTextualUploadDate())));
110113

111-
112114
// setup bottom row, with likes, heart and replies button
113115
itemLikesCountView.setText(
114116
Localization.likeCount(itemBuilder.getContext(), item.getLikeCount()));

app/src/main/java/org/schabi/newpipe/util/Localization.java

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
import android.os.Build;
1212
import android.text.TextUtils;
1313
import android.text.format.DateUtils;
14+
import android.text.BidiFormatter;
1415
import android.util.DisplayMetrics;
1516
import android.util.Log;
1617

@@ -85,6 +86,25 @@ public static String concatenateStrings(final String delimiter, final List<Strin
8586
.collect(Collectors.joining(delimiter));
8687
}
8788

89+
/**
90+
* Localize a user name like <code>@foobar</code>.
91+
*
92+
* Will correctly handle right-to-left usernames by using a {@link BidiFormatter}.
93+
*
94+
* @param plainName username, with an optional leading <code>@</code>
95+
* @return a usernames that can include RTL-characters
96+
*/
97+
@NonNull
98+
public static String localizeUserName(final String plainName) {
99+
final BidiFormatter bidi = BidiFormatter.getInstance();
100+
101+
if (plainName.startsWith("@")) {
102+
return "@" + bidi.unicodeWrap(plainName.substring(1));
103+
} else {
104+
return bidi.unicodeWrap(plainName);
105+
}
106+
}
107+
88108
public static org.schabi.newpipe.extractor.localization.Localization getPreferredLocalization(
89109
final Context context) {
90110
return org.schabi.newpipe.extractor.localization.Localization

0 commit comments

Comments
 (0)