fix(YouTube - Return YouTube Dislike): Use correct number formatting if using a different RVX language

This commit is contained in:
inotia00 2025-02-28 09:28:49 +09:00
parent 442a22a282
commit 63c69ea752
2 changed files with 21 additions and 10 deletions

View File

@ -295,11 +295,10 @@ public class ReturnYouTubeDislike {
private static String formatDislikeCount(long dislikeCount) { private static String formatDislikeCount(long dislikeCount) {
if (isSDKAbove(24)) { if (isSDKAbove(24)) {
if (dislikeCountFormatter == null) { if (dislikeCountFormatter == null) {
// Note: Java number formatters will use the locale specific number characters. // Must use default locale and not Utils context locale,
// such as Arabic which formats "1.234" into "۱,۲۳٤" // otherwise if using a different settings language then the
// But YouTube disregards locale specific number characters // formatting will use that of the different language.
// and instead shows english number characters everywhere. Locale locale = Locale.getDefault();
Locale locale = Objects.requireNonNull(Utils.getContext()).getResources().getConfiguration().getLocales().get(0);
Logger.printDebug(() -> "Locale: " + locale); Logger.printDebug(() -> "Locale: " + locale);
dislikeCountFormatter = CompactDecimalFormat.getInstance(locale, CompactDecimalFormat.CompactStyle.SHORT); dislikeCountFormatter = CompactDecimalFormat.getInstance(locale, CompactDecimalFormat.CompactStyle.SHORT);
} }
@ -313,7 +312,7 @@ public class ReturnYouTubeDislike {
if (isSDKAbove(24)) { if (isSDKAbove(24)) {
synchronized (ReturnYouTubeDislike.class) { // number formatter is not thread safe, must synchronize synchronized (ReturnYouTubeDislike.class) { // number formatter is not thread safe, must synchronize
if (dislikePercentageFormatter == null) { if (dislikePercentageFormatter == null) {
Locale locale = Objects.requireNonNull(Utils.getContext()).getResources().getConfiguration().getLocales().get(0); Locale locale = Locale.getDefault();
Logger.printDebug(() -> "Locale: " + locale); Logger.printDebug(() -> "Locale: " + locale);
dislikePercentageFormatter = NumberFormat.getPercentInstance(locale); dislikePercentageFormatter = NumberFormat.getPercentInstance(locale);
} }

View File

@ -352,13 +352,16 @@ public class ReturnYouTubeDislike {
private static String formatDislikeCount(long dislikeCount) { private static String formatDislikeCount(long dislikeCount) {
if (isSDKAbove(24)) { if (isSDKAbove(24)) {
synchronized (ReturnYouTubeDislike.class) { // number formatter is not thread safe, must synchronize synchronized (ReturnYouTubeDislike.class) { // Number formatter is not thread safe.
if (dislikeCountFormatter == null) { if (dislikeCountFormatter == null) {
Locale locale = Objects.requireNonNull(Utils.getContext()).getResources().getConfiguration().getLocales().get(0); // Must use default locale and not Utils context locale,
// otherwise if using a different settings language then the
// formatting will use that of the different language.
Locale locale = Locale.getDefault();
dislikeCountFormatter = CompactDecimalFormat.getInstance(locale, CompactDecimalFormat.CompactStyle.SHORT); dislikeCountFormatter = CompactDecimalFormat.getInstance(locale, CompactDecimalFormat.CompactStyle.SHORT);
// YouTube disregards locale specific number characters // YouTube disregards locale specific number characters
// and instead shows english number characters everywhere. // and instead shows English number characters everywhere.
// To use the same behavior, override the digit characters to use English // To use the same behavior, override the digit characters to use English
// so languages such as Arabic will show "1.234" instead of the native "۱,۲۳٤" // so languages such as Arabic will show "1.234" instead of the native "۱,۲۳٤"
if (isSDKAbove(28)) { if (isSDKAbove(28)) {
@ -379,7 +382,7 @@ public class ReturnYouTubeDislike {
if (isSDKAbove(24)) { if (isSDKAbove(24)) {
synchronized (ReturnYouTubeDislike.class) { // number formatter is not thread safe, must synchronize synchronized (ReturnYouTubeDislike.class) { // number formatter is not thread safe, must synchronize
if (dislikePercentageFormatter == null) { if (dislikePercentageFormatter == null) {
Locale locale = Objects.requireNonNull(Utils.getContext()).getResources().getConfiguration().getLocales().get(0); Locale locale = Locale.getDefault();
dislikePercentageFormatter = NumberFormat.getPercentInstance(locale); dislikePercentageFormatter = NumberFormat.getPercentInstance(locale);
// Want to set the digit strings, and the simplest way is to cast to the implementation NumberFormat returns. // Want to set the digit strings, and the simplest way is to cast to the implementation NumberFormat returns.
@ -597,6 +600,15 @@ public class ReturnYouTubeDislike {
} }
if (spanIsForLikes) { if (spanIsForLikes) {
if (!Utils.containsNumber(original)) {
if (!Settings.RYD_ESTIMATED_LIKE.get()) {
Logger.printDebug(() -> "Likes are hidden");
return original;
} else {
Logger.printDebug(() -> "Using estimated likes");
}
}
// Scrolling Shorts does not cause the Spans to be reloaded, // Scrolling Shorts does not cause the Spans to be reloaded,
// so there is no need to cache the likes for this situations. // so there is no need to cache the likes for this situations.
Logger.printDebug(() -> "Creating likes span for: " + votingData.videoId); Logger.printDebug(() -> "Creating likes span for: " + votingData.videoId);