diff --git a/app/src/main/java/app/revanced/integrations/youtube/patches/playback/speed/RememberPlaybackSpeedPatch.java b/app/src/main/java/app/revanced/integrations/youtube/patches/playback/speed/RememberPlaybackSpeedPatch.java index 2bb3f9cb11..8e72e33d59 100644 --- a/app/src/main/java/app/revanced/integrations/youtube/patches/playback/speed/RememberPlaybackSpeedPatch.java +++ b/app/src/main/java/app/revanced/integrations/youtube/patches/playback/speed/RememberPlaybackSpeedPatch.java @@ -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. */ @@ -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); } }