mirror of
https://github.com/revanced/revanced-integrations.git
synced 2025-01-08 11:05:49 +01:00
fix(youtube/remember-playback-speed): allow to not remember playback speed (#338)
Co-authored-by: oSumAtrIX <johan.melkonyan1@web.de>
This commit is contained in:
parent
0810f84c4c
commit
7627e5d057
@ -1,32 +0,0 @@
|
|||||||
package app.revanced.integrations.patches.playback.speed;
|
|
||||||
|
|
||||||
import static app.revanced.integrations.utils.SharedPrefHelper.SharedPrefNames.REVANCED_PREFS;
|
|
||||||
import static app.revanced.integrations.utils.SharedPrefHelper.getFloat;
|
|
||||||
import static app.revanced.integrations.utils.SharedPrefHelper.saveFloat;
|
|
||||||
|
|
||||||
import android.widget.Toast;
|
|
||||||
|
|
||||||
import app.revanced.integrations.settings.SettingsEnum;
|
|
||||||
import app.revanced.integrations.utils.LogHelper;
|
|
||||||
import app.revanced.integrations.utils.ReVancedUtils;
|
|
||||||
|
|
||||||
|
|
||||||
public final class RememberPlaybackRatePatch {
|
|
||||||
private static final String REMEMBERED_PLAYBACK_RATE_PREFERENCE_KEY = "revanced_remember_playback_rate_last_value";
|
|
||||||
|
|
||||||
public static void rememberPlaybackRate(final float selectedPlaybackRate) {
|
|
||||||
if (!SettingsEnum.REMEMBER_PLAYBACK_RATE_SELECTED.getBoolean()) return;
|
|
||||||
|
|
||||||
Toast.makeText(ReVancedUtils.getContext(), "Playback rate will be remembered", Toast.LENGTH_SHORT).show();
|
|
||||||
|
|
||||||
LogHelper.printDebug(() -> "Remembering playback rate: " + selectedPlaybackRate);
|
|
||||||
saveFloat(REVANCED_PREFS, REMEMBERED_PLAYBACK_RATE_PREFERENCE_KEY, selectedPlaybackRate);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static float getRememberedPlaybackRate() {
|
|
||||||
final var playbackRateOverride = getFloat(REVANCED_PREFS, REMEMBERED_PLAYBACK_RATE_PREFERENCE_KEY, -2f);
|
|
||||||
|
|
||||||
LogHelper.printDebug(() -> "Overriding playback rate: " + playbackRateOverride);
|
|
||||||
return playbackRateOverride;
|
|
||||||
}
|
|
||||||
}
|
|
@ -0,0 +1,83 @@
|
|||||||
|
package app.revanced.integrations.patches.playback.speed;
|
||||||
|
|
||||||
|
import android.widget.Toast;
|
||||||
|
import androidx.annotation.NonNull;
|
||||||
|
import androidx.annotation.Nullable;
|
||||||
|
import app.revanced.integrations.settings.SettingsEnum;
|
||||||
|
import app.revanced.integrations.utils.LogHelper;
|
||||||
|
import app.revanced.integrations.utils.ReVancedUtils;
|
||||||
|
|
||||||
|
public final class RememberPlaybackSpeedPatch {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The current playback speed
|
||||||
|
*/
|
||||||
|
private static float currentPlaybackSpeed = getLastRememberedPlaybackSpeed();
|
||||||
|
|
||||||
|
private final static float DEFAULT_PLAYBACK_SPEED = (float) SettingsEnum.REMEMBER_PLAYBACK_SPEED_LAST_SELECTED_VALUE.getDefaultValue();
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
private static String currentVideoId;
|
||||||
|
|
||||||
|
private static void showToast(final String message) {
|
||||||
|
Toast.makeText(ReVancedUtils.getContext(), message, Toast.LENGTH_LONG).show();
|
||||||
|
}
|
||||||
|
|
||||||
|
private static float getLastRememberedPlaybackSpeed() {
|
||||||
|
return SettingsEnum.REMEMBER_PLAYBACK_SPEED_LAST_SELECTED_VALUE.getFloat();
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void rememberPlaybackSpeed() {
|
||||||
|
SettingsEnum.REMEMBER_PLAYBACK_SPEED_LAST_SELECTED_VALUE.saveValue(currentPlaybackSpeed);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static boolean rememberLastSelectedPlaybackSpeed() {
|
||||||
|
return SettingsEnum.REMEMBER_PLAYBACK_SPEED_LAST_SELECTED.getBoolean();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Injection point.
|
||||||
|
* Called when a new video loads.
|
||||||
|
*/
|
||||||
|
public static void newVideoLoaded(@NonNull String videoId) {
|
||||||
|
if (videoId.equals(currentVideoId)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
currentVideoId = videoId;
|
||||||
|
currentPlaybackSpeed = getLastRememberedPlaybackSpeed();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Injection point.
|
||||||
|
* Called when a playback speed is selected.
|
||||||
|
*
|
||||||
|
* @param playbackSpeed The playback speed to set.
|
||||||
|
*/
|
||||||
|
public static void setPlaybackSpeed(final float playbackSpeed) {
|
||||||
|
LogHelper.printDebug(() -> "Playback speed changed to: " + playbackSpeed);
|
||||||
|
|
||||||
|
currentPlaybackSpeed = playbackSpeed;
|
||||||
|
|
||||||
|
if (rememberLastSelectedPlaybackSpeed()) {
|
||||||
|
rememberPlaybackSpeed();
|
||||||
|
|
||||||
|
showToast("Remembering playback speed: " + playbackSpeed + "x");
|
||||||
|
} else {
|
||||||
|
if (getLastRememberedPlaybackSpeed() == DEFAULT_PLAYBACK_SPEED) return;
|
||||||
|
|
||||||
|
showToast("Applying playback speed: " + playbackSpeed + "x");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Injection point.
|
||||||
|
* Called when playback first starts,
|
||||||
|
* and also called immediately after the user selects a new video speed.
|
||||||
|
*
|
||||||
|
* @return The currently set playback speed.
|
||||||
|
*/
|
||||||
|
public static float getCurrentPlaybackSpeed() {
|
||||||
|
return currentPlaybackSpeed;
|
||||||
|
}
|
||||||
|
}
|
@ -18,11 +18,11 @@ public enum SettingsEnum {
|
|||||||
// Video settings
|
// Video settings
|
||||||
OLD_STYLE_VIDEO_QUALITY_PLAYER_SETTINGS("revanced_use_old_style_quality_settings", true, ReturnType.BOOLEAN),
|
OLD_STYLE_VIDEO_QUALITY_PLAYER_SETTINGS("revanced_use_old_style_quality_settings", true, ReturnType.BOOLEAN),
|
||||||
REMEMBER_VIDEO_QUALITY_LAST_SELECTED("revanced_remember_video_quality_last_selected", true, ReturnType.BOOLEAN),
|
REMEMBER_VIDEO_QUALITY_LAST_SELECTED("revanced_remember_video_quality_last_selected", true, ReturnType.BOOLEAN),
|
||||||
REMEMBER_PLAYBACK_RATE_SELECTED("revanced_remember_playback_rate_selected", true, ReturnType.BOOLEAN),
|
REMEMBER_PLAYBACK_SPEED_LAST_SELECTED("revanced_remember_playback_speed_last_selected", true, ReturnType.BOOLEAN),
|
||||||
|
REMEMBER_PLAYBACK_SPEED_LAST_SELECTED_VALUE("revanced_remember_playback_speed_last_selected_value", 1.0f, ReturnType.FLOAT),
|
||||||
|
|
||||||
|
// TODO: Unused currently
|
||||||
// Whitelist settings
|
// Whitelist settings
|
||||||
//ToDo: Not used atm, Patch missing
|
|
||||||
ENABLE_WHITELIST("revanced_whitelist_ads_enabled", false, ReturnType.BOOLEAN),
|
ENABLE_WHITELIST("revanced_whitelist_ads_enabled", false, ReturnType.BOOLEAN),
|
||||||
|
|
||||||
// Ad settings
|
// Ad settings
|
||||||
|
Loading…
Reference in New Issue
Block a user