feat(Return YouTube Dislike): add Show estimated likes setting (#4443)

This commit is contained in:
LisoUseInAIKyrios 2025-02-11 12:12:24 +02:00 committed by GitHub
parent 9a6f5ef6b5
commit 9a88b4239f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 40 additions and 0 deletions

View File

@ -234,6 +234,12 @@ public class ReturnYouTubeDislike {
// example video: https://www.youtube.com/watch?v=UnrU5vxCHxw
// RYD data: https://returnyoutubedislikeapi.com/votes?videoId=UnrU5vxCHxw
//
if (!Settings.RYD_ESTIMATED_LIKE.get()) {
// Change the "Likes" string to show that likes and dislikes are hidden.
String hiddenMessageString = str("revanced_ryd_video_likes_hidden_by_video_owner");
return newSpanUsingStylingOfAnotherSpan(oldSpannable, hiddenMessageString);
}
Logger.printDebug(() -> "Using estimated likes");
oldLikes = formatDislikeCount(voteData.getLikeCount());
}
@ -542,6 +548,15 @@ public class ReturnYouTubeDislike {
}
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,
// so there is no need to cache the likes for this situations.
Logger.printDebug(() -> "Creating likes span for: " + votingData.videoId);

View File

@ -333,6 +333,7 @@ public class Settings extends BaseSettings {
public static final BooleanSetting RYD_SHORTS = new BooleanSetting("ryd_shorts", TRUE, parent(RYD_ENABLED));
public static final BooleanSetting RYD_DISLIKE_PERCENTAGE = new BooleanSetting("ryd_dislike_percentage", FALSE, parent(RYD_ENABLED));
public static final BooleanSetting RYD_COMPACT_LAYOUT = new BooleanSetting("ryd_compact_layout", FALSE, parent(RYD_ENABLED));
public static final BooleanSetting RYD_ESTIMATED_LIKE = new BooleanSetting("ryd_estimated_like", TRUE, parent(RYD_ENABLED));
public static final BooleanSetting RYD_TOAST_ON_CONNECTION_ERROR = new BooleanSetting("ryd_toast_on_connection_error", TRUE, parent(RYD_ENABLED));
// SponsorBlock

View File

@ -39,6 +39,11 @@ public class ReturnYouTubeDislikePreferenceFragment extends PreferenceFragment {
*/
private SwitchPreference compactLayoutPreference;
/**
* If hidden likes are replaced with an estimated value.
*/
private SwitchPreference estimatedLikesPreference;
/**
* If segmented like/dislike button uses smaller compact layout.
*/
@ -48,6 +53,7 @@ public class ReturnYouTubeDislikePreferenceFragment extends PreferenceFragment {
shortsPreference.setEnabled(Settings.RYD_SHORTS.isAvailable());
percentagePreference.setEnabled(Settings.RYD_DISLIKE_PERCENTAGE.isAvailable());
compactLayoutPreference.setEnabled(Settings.RYD_COMPACT_LAYOUT.isAvailable());
estimatedLikesPreference.setEnabled(Settings.RYD_ESTIMATED_LIKE.isAvailable());
toastOnRYDNotAvailable.setEnabled(Settings.RYD_TOAST_ON_CONNECTION_ERROR.isAvailable());
}
@ -117,6 +123,19 @@ public class ReturnYouTubeDislikePreferenceFragment extends PreferenceFragment {
});
preferenceScreen.addPreference(compactLayoutPreference);
estimatedLikesPreference = new SwitchPreference(context);
estimatedLikesPreference.setChecked(Settings.RYD_ESTIMATED_LIKE.get());
estimatedLikesPreference.setTitle(str("revanced_ryd_estimated_like_title"));
estimatedLikesPreference.setSummaryOn(str("revanced_ryd_estimated_like_summary_on"));
estimatedLikesPreference.setSummaryOff(str("revanced_ryd_estimated_like_summary_off"));
estimatedLikesPreference.setOnPreferenceChangeListener((pref, newValue) -> {
Settings.RYD_ESTIMATED_LIKE.save((Boolean) newValue);
ReturnYouTubeDislike.clearAllUICaches();
updateUIState();
return true;
});
preferenceScreen.addPreference(estimatedLikesPreference);
toastOnRYDNotAvailable = new SwitchPreference(context);
toastOnRYDNotAvailable.setChecked(Settings.RYD_TOAST_ON_CONNECTION_ERROR.get());
toastOnRYDNotAvailable.setTitle(str("revanced_ryd_toast_on_connection_error_title"));

View File

@ -841,6 +841,8 @@ Note: Enabling this also forcibly hides video ads"</string>
<string name="revanced_ryd_failure_generic">Dislikes not available (%s)</string>
<!-- Toast shown if the user enables RYD while a video is opened, and then tries to vote for the video. -->
<string name="revanced_ryd_failure_ryd_enabled_while_playing_video_then_user_voted">Reload video to vote using Return YouTube Dislike</string>
<!-- Video likes have been set to hidden by the video uploader. -->
<string name="revanced_ryd_video_likes_hidden_by_video_owner">Hidden by owner</string>
<string name="revanced_ryd_enable_title" translatable="false">Return YouTube Dislike</string>
<string name="revanced_ryd_enable_summary_on">Dislikes are shown</string>
<string name="revanced_ryd_enable_summary_off">Dislikes are not shown</string>
@ -857,6 +859,9 @@ Limitation: Dislikes may not appear in incognito mode"</string>
<string name="revanced_ryd_compact_layout_title">Compact Like button</string>
<string name="revanced_ryd_compact_layout_summary_on">Like button styled for minimum width</string>
<string name="revanced_ryd_compact_layout_summary_off">Like button styled for best appearance</string>
<string name="revanced_ryd_estimated_like_title">Show estimated likes</string>
<string name="revanced_ryd_estimated_like_summary_on">Estimated likes are shown</string>
<string name="revanced_ryd_estimated_like_summary_off">Estimated likes are hidden</string>
<string name="revanced_ryd_toast_on_connection_error_title">Show a toast if API is not available</string>
<string name="revanced_ryd_toast_on_connection_error_summary_on">Toast is shown if Return YouTube Dislike is not available</string>
<string name="revanced_ryd_toast_on_connection_error_summary_off">Toast is not shown if Return YouTube Dislike is not available</string>