Skip to content
This repository has been archived by the owner on Oct 26, 2024. It is now read-only.

Commit

Permalink
fix(YouTube - Playback speed): Remember playback speed with new speed…
Browse files Browse the repository at this point in the history
… menu (#725)
  • Loading branch information
LisoUseInAIKyrios authored Oct 24, 2024
1 parent c1bde72 commit fd9ffa5
Showing 1 changed file with 17 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,18 @@

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.
*/
Expand All @@ -27,7 +31,17 @@ public static void newVideoStarted(VideoInformation.PlaybackController ignoredPl
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);
}
}

Expand Down

0 comments on commit fd9ffa5

Please sign in to comment.