mirror of
				https://github.com/TeamNewPipe/NewPipe
				synced 2025-10-30 23:03:00 +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:
		| @@ -101,14 +101,16 @@ public class CommentInfoItemHolder extends InfoItemHolder { | ||||
|         } | ||||
|         itemThumbnailView.setOnClickListener(view -> openCommentAuthor(item)); | ||||
|  | ||||
|  | ||||
|         // setup the top row, with pinned icon, author name and comment date | ||||
|         itemPinnedView.setVisibility(item.isPinned() ? View.VISIBLE : View.GONE); | ||||
|         itemTitleView.setText(Localization.concatenateStrings(item.getUploaderName(), | ||||
|                 Localization.relativeTimeOrTextual(itemBuilder.getContext(), item.getUploadDate(), | ||||
|         final String uploaderName = Localization.localizeUserName(item.getUploaderName()); | ||||
|         itemTitleView.setText(Localization.concatenateStrings( | ||||
|                 uploaderName, | ||||
|                 Localization.relativeTimeOrTextual( | ||||
|                         itemBuilder.getContext(), | ||||
|                         item.getUploadDate(), | ||||
|                         item.getTextualUploadDate()))); | ||||
|  | ||||
|  | ||||
|         // setup bottom row, with likes, heart and replies button | ||||
|         itemLikesCountView.setText( | ||||
|                 Localization.likeCount(itemBuilder.getContext(), item.getLikeCount())); | ||||
|   | ||||
| @@ -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 | ||||
|   | ||||
		Reference in New Issue
	
	Block a user
	 VougJo23
					VougJo23