fix(YouTube - Playback speed): Remember playback speed with new speed menu (#725)

This commit is contained in:
LisoUseInAIKyrios 2024-10-24 07:45:17 -04:00 committed by GitHub
parent c1bde72525
commit fd9ffa53b7
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -2,14 +2,18 @@ package app.revanced.integrations.youtube.patches.playback.speed;
import static app.revanced.integrations.shared.StringRef.str;
import app.revanced.integrations.youtube.patches.VideoInformation;
import app.revanced.integrations.youtube.settings.Settings;
import app.revanced.integrations.shared.Logger;
import app.revanced.integrations.shared.Utils;
import app.revanced.integrations.youtube.patches.VideoInformation;
import app.revanced.integrations.youtube.settings.Settings;
@SuppressWarnings("unused")
public final class RememberPlaybackSpeedPatch {
private static final long TOAST_DELAY_MILLISECONDS = 750;
private static long lastTimeSpeedChanged;
/**
* Injection point.
*/
@ -27,7 +31,17 @@ public final class RememberPlaybackSpeedPatch {
public static void userSelectedPlaybackSpeed(float playbackSpeed) {
if (Settings.REMEMBER_PLAYBACK_SPEED_LAST_SELECTED.get()) {
Settings.PLAYBACK_SPEED_DEFAULT.save(playbackSpeed);
Utils.showToastLong(str("revanced_remember_playback_speed_toast", (playbackSpeed + "x")));
// Prevent toast spamming if using the 0.05x adjustments.
// Show exactly one toast after the user stops interacting with the speed menu.
final long now = System.currentTimeMillis();
lastTimeSpeedChanged = now;
Utils.runOnMainThreadDelayed(() -> {
if (lastTimeSpeedChanged == now) {
Utils.showToastLong(str("revanced_remember_playback_speed_toast", (playbackSpeed + "x")));
} // else, the user made additional speed adjustments and this call is outdated.
}, TOAST_DELAY_MILLISECONDS);
}
}