mirror of
https://github.com/TeamNewPipe/NewPipe
synced 2025-05-13 21:04:05 +00:00
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
@ -101,14 +101,16 @@ public class CommentInfoItemHolder extends InfoItemHolder {
|
|||||||
}
|
}
|
||||||
itemThumbnailView.setOnClickListener(view -> openCommentAuthor(item));
|
itemThumbnailView.setOnClickListener(view -> openCommentAuthor(item));
|
||||||
|
|
||||||
|
|
||||||
// setup the top row, with pinned icon, author name and comment date
|
// setup the top row, with pinned icon, author name and comment date
|
||||||
itemPinnedView.setVisibility(item.isPinned() ? View.VISIBLE : View.GONE);
|
itemPinnedView.setVisibility(item.isPinned() ? View.VISIBLE : View.GONE);
|
||||||
itemTitleView.setText(Localization.concatenateStrings(item.getUploaderName(),
|
final String uploaderName = Localization.localizeUserName(item.getUploaderName());
|
||||||
Localization.relativeTimeOrTextual(itemBuilder.getContext(), item.getUploadDate(),
|
itemTitleView.setText(Localization.concatenateStrings(
|
||||||
|
uploaderName,
|
||||||
|
Localization.relativeTimeOrTextual(
|
||||||
|
itemBuilder.getContext(),
|
||||||
|
item.getUploadDate(),
|
||||||
item.getTextualUploadDate())));
|
item.getTextualUploadDate())));
|
||||||
|
|
||||||
|
|
||||||
// setup bottom row, with likes, heart and replies button
|
// setup bottom row, with likes, heart and replies button
|
||||||
itemLikesCountView.setText(
|
itemLikesCountView.setText(
|
||||||
Localization.likeCount(itemBuilder.getContext(), item.getLikeCount()));
|
Localization.likeCount(itemBuilder.getContext(), item.getLikeCount()));
|
||||||
|
@ -11,6 +11,7 @@ import android.icu.text.CompactDecimalFormat;
|
|||||||
import android.os.Build;
|
import android.os.Build;
|
||||||
import android.text.TextUtils;
|
import android.text.TextUtils;
|
||||||
import android.text.format.DateUtils;
|
import android.text.format.DateUtils;
|
||||||
|
import android.text.BidiFormatter;
|
||||||
import android.util.DisplayMetrics;
|
import android.util.DisplayMetrics;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
|
||||||
@ -85,6 +86,25 @@ public final class Localization {
|
|||||||
.collect(Collectors.joining(delimiter));
|
.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(
|
public static org.schabi.newpipe.extractor.localization.Localization getPreferredLocalization(
|
||||||
final Context context) {
|
final Context context) {
|
||||||
return org.schabi.newpipe.extractor.localization.Localization
|
return org.schabi.newpipe.extractor.localization.Localization
|
||||||
|
Loading…
x
Reference in New Issue
Block a user