feat(YouTube): Add an option to disable toasts when changing default playback speed or quality (#5230)

This commit is contained in:
MarcaD
2025-06-23 11:20:37 +03:00
committed by GitHub
parent ccd169121a
commit 6b719dfcd7
8 changed files with 24 additions and 12 deletions

View File

@@ -64,6 +64,7 @@ public class RememberVideoQualityPatch {
else videoQualityWifi.save(defaultQuality);
networkTypeMessage = str("revanced_remember_video_quality_wifi");
}
if (Settings.REMEMBER_VIDEO_QUALITY_LAST_SELECTED_TOAST.get())
Utils.showToastShort(str(
useShortsPreference ? "revanced_remember_video_quality_toast_shorts" : "revanced_remember_video_quality_toast",
networkTypeMessage, (defaultQuality + "p")

View File

@@ -617,9 +617,9 @@ public class CustomPlaybackSpeedPatch {
* @return The rounded speed, constrained to the specified bounds.
*/
private static float roundSpeedToNearestIncrement(float speed) {
// Round to nearest 0.05 speed.
final float roundedSpeed = Math.round(speed / 0.05f) * 0.05f;
return Utils.clamp(roundedSpeed, 0.05f, PLAYBACK_SPEED_MAXIMUM);
// Round to nearest 0.05 speed. Must use double precision otherwise rounding error can occur.
final double roundedSpeed = Math.round(speed / 0.05) * 0.05;
return Utils.clamp((float) roundedSpeed, 0.05f, PLAYBACK_SPEED_MAXIMUM);
}
/**

View File

@@ -57,6 +57,7 @@ public final class RememberPlaybackSpeedPatch {
}
Settings.PLAYBACK_SPEED_DEFAULT.save(finalPlaybackSpeed);
if (Settings.REMEMBER_PLAYBACK_SPEED_LAST_SELECTED_TOAST.get())
Utils.showToastShort(str("revanced_remember_playback_speed_toast", (finalPlaybackSpeed + "x")));
}, TOAST_DELAY_MILLISECONDS);
}

View File

@@ -52,6 +52,8 @@ public class Settings extends BaseSettings {
public static final IntegerSetting VIDEO_QUALITY_DEFAULT_WIFI = new IntegerSetting("revanced_video_quality_default_wifi", -2);
public static final IntegerSetting VIDEO_QUALITY_DEFAULT_MOBILE = new IntegerSetting("revanced_video_quality_default_mobile", -2);
public static final BooleanSetting REMEMBER_VIDEO_QUALITY_LAST_SELECTED = new BooleanSetting("revanced_remember_video_quality_last_selected", FALSE);
public static final BooleanSetting REMEMBER_VIDEO_QUALITY_LAST_SELECTED_TOAST = new BooleanSetting("revanced_remember_video_quality_last_selected_toast", TRUE, false,
parent(REMEMBER_VIDEO_QUALITY_LAST_SELECTED));
public static final IntegerSetting SHORTS_QUALITY_DEFAULT_WIFI = new IntegerSetting("revanced_shorts_quality_default_wifi", -2, true);
public static final IntegerSetting SHORTS_QUALITY_DEFAULT_MOBILE = new IntegerSetting("revanced_shorts_quality_default_mobile", -2, true);
public static final BooleanSetting REMEMBER_SHORTS_QUALITY_LAST_SELECTED = new BooleanSetting("revanced_remember_shorts_quality_last_selected", FALSE);
@@ -60,6 +62,8 @@ public class Settings extends BaseSettings {
// Speed
public static final FloatSetting SPEED_TAP_AND_HOLD = new FloatSetting("revanced_speed_tap_and_hold", 2.0f, true);
public static final BooleanSetting REMEMBER_PLAYBACK_SPEED_LAST_SELECTED = new BooleanSetting("revanced_remember_playback_speed_last_selected", FALSE);
public static final BooleanSetting REMEMBER_PLAYBACK_SPEED_LAST_SELECTED_TOAST = new BooleanSetting("revanced_remember_playback_speed_last_selected_toast", TRUE, false,
parent(REMEMBER_PLAYBACK_SPEED_LAST_SELECTED));
public static final BooleanSetting CUSTOM_SPEED_MENU = new BooleanSetting("revanced_custom_speed_menu", TRUE);
public static final FloatSetting PLAYBACK_SPEED_DEFAULT = new FloatSetting("revanced_playback_speed_default", -2.0f);
public static final StringSetting CUSTOM_PLAYBACK_SPEEDS = new StringSetting("revanced_custom_playback_speeds",

View File

@@ -42,7 +42,6 @@ public class PlaybackSpeedDialogButton {
: Settings.PLAYBACK_SPEED_DEFAULT.get();
VideoInformation.overridePlaybackSpeed(speed);
showToastShort(str("revanced_custom_playback_speeds_reset_toast", (speed + "x")));
} catch (Exception ex) {
Logger.printException(() -> "speed button reset failure", ex);
}

View File

@@ -57,7 +57,8 @@ val rememberVideoQualityPatch = bytecodePatch {
entriesKey = "revanced_shorts_quality_default_entries",
entryValuesKey = "revanced_shorts_quality_default_entry_values"
),
SwitchPreference("revanced_remember_shorts_quality_last_selected")
SwitchPreference("revanced_remember_shorts_quality_last_selected"),
SwitchPreference("revanced_remember_video_quality_last_selected_toast")
))
/*

View File

@@ -39,7 +39,8 @@ internal val rememberPlaybackSpeedPatch = bytecodePatch {
entryValuesKey = null,
tag = "app.revanced.extension.youtube.settings.preference.CustomVideoSpeedListPreference"
),
SwitchPreference("revanced_remember_playback_speed_last_selected")
SwitchPreference("revanced_remember_playback_speed_last_selected"),
SwitchPreference("revanced_remember_playback_speed_last_selected_toast")
)
)

View File

@@ -1465,6 +1465,9 @@ Enabling this can unlock higher video qualities"</string>
<string name="revanced_remember_video_quality_last_selected_title">Remember video quality changes</string>
<string name="revanced_remember_video_quality_last_selected_summary_on">Quality changes apply to all videos</string>
<string name="revanced_remember_video_quality_last_selected_summary_off">Quality changes only apply to the current video</string>
<string name="revanced_remember_video_quality_last_selected_toast_title">Show toast on video quality changes</string>
<string name="revanced_remember_video_quality_last_selected_toast_summary_on">A toast is shown when the default video quality is changed</string>
<string name="revanced_remember_video_quality_last_selected_toast_summary_off">A toast is not shown when the default video quality is changed</string>
<string name="revanced_video_quality_default_wifi_title">Default video quality on Wi-Fi network</string>
<string name="revanced_video_quality_default_mobile_title">Default video quality on mobile network</string>
<string name="revanced_remember_shorts_quality_last_selected_title">Remember Shorts quality changes</string>
@@ -1491,7 +1494,6 @@ Enabling this can unlock higher video qualities"</string>
<string name="revanced_custom_playback_speeds_invalid">Custom speeds must be less than %s</string>
<string name="revanced_custom_playback_speeds_parse_exception">Invalid custom playback speeds</string>
<string name="revanced_custom_playback_speeds_auto">Auto</string>
<string name="revanced_custom_playback_speeds_reset_toast">Playback speed reset to: %s</string>
<string name="revanced_speed_tap_and_hold_title">Custom tap and hold speed</string>
<string name="revanced_speed_tap_and_hold_summary">Playback speed between 0-8</string>
</patch>
@@ -1499,6 +1501,9 @@ Enabling this can unlock higher video qualities"</string>
<string name="revanced_remember_playback_speed_last_selected_title">Remember playback speed changes</string>
<string name="revanced_remember_playback_speed_last_selected_summary_on">Playback speed changes apply to all videos</string>
<string name="revanced_remember_playback_speed_last_selected_summary_off">Playback speed changes only apply to the current video</string>
<string name="revanced_remember_playback_speed_last_selected_toast_title">Show toast on playback speed changes</string>
<string name="revanced_remember_playback_speed_last_selected_toast_summary_on">A toast is shown when the default playback speed is changed</string>
<string name="revanced_remember_playback_speed_last_selected_toast_summary_off">A toast is not shown when the default playback speed is changed</string>
<string name="revanced_playback_speed_default_title">Default playback speed</string>
<string name="revanced_remember_playback_speed_toast">Changed default speed to: %s</string>
</patch>