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

Commit fd9ffa5

Browse files
fix(YouTube - Playback speed): Remember playback speed with new speed menu (#725)
1 parent c1bde72 commit fd9ffa5

File tree

1 file changed

+17
-3
lines changed

1 file changed

+17
-3
lines changed

app/src/main/java/app/revanced/integrations/youtube/patches/playback/speed/RememberPlaybackSpeedPatch.java

+17-3
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,18 @@
22

33
import static app.revanced.integrations.shared.StringRef.str;
44

5-
import app.revanced.integrations.youtube.patches.VideoInformation;
6-
import app.revanced.integrations.youtube.settings.Settings;
75
import app.revanced.integrations.shared.Logger;
86
import app.revanced.integrations.shared.Utils;
7+
import app.revanced.integrations.youtube.patches.VideoInformation;
8+
import app.revanced.integrations.youtube.settings.Settings;
99

1010
@SuppressWarnings("unused")
1111
public final class RememberPlaybackSpeedPatch {
1212

13+
private static final long TOAST_DELAY_MILLISECONDS = 750;
14+
15+
private static long lastTimeSpeedChanged;
16+
1317
/**
1418
* Injection point.
1519
*/
@@ -27,7 +31,17 @@ public static void newVideoStarted(VideoInformation.PlaybackController ignoredPl
2731
public static void userSelectedPlaybackSpeed(float playbackSpeed) {
2832
if (Settings.REMEMBER_PLAYBACK_SPEED_LAST_SELECTED.get()) {
2933
Settings.PLAYBACK_SPEED_DEFAULT.save(playbackSpeed);
30-
Utils.showToastLong(str("revanced_remember_playback_speed_toast", (playbackSpeed + "x")));
34+
35+
// Prevent toast spamming if using the 0.05x adjustments.
36+
// Show exactly one toast after the user stops interacting with the speed menu.
37+
final long now = System.currentTimeMillis();
38+
lastTimeSpeedChanged = now;
39+
40+
Utils.runOnMainThreadDelayed(() -> {
41+
if (lastTimeSpeedChanged == now) {
42+
Utils.showToastLong(str("revanced_remember_playback_speed_toast", (playbackSpeed + "x")));
43+
} // else, the user made additional speed adjustments and this call is outdated.
44+
}, TOAST_DELAY_MILLISECONDS);
3145
}
3246
}
3347

0 commit comments

Comments
 (0)