Skip to content

Commit

Permalink
feat(youtube): rename video-speed to playback-speed (#438)
Browse files Browse the repository at this point in the history
  • Loading branch information
kazimmt committed Jul 15, 2023
1 parent 0e18f20 commit 630776f
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 27 deletions.
@@ -1,11 +1,11 @@
package app.revanced.integrations.patches.components;

// Abuse LithoFilter for CustomVideoSpeedPatch.
public final class VideoSpeedMenuFilterPatch extends Filter {
// Abuse LithoFilter for CustomPlaybackSpeedPatch.
public final class PlaybackSpeedMenuFilterPatch extends Filter {
// Must be volatile or synchronized, as litho filtering runs off main thread and this field is then access from the main thread.
public static volatile boolean isVideoSpeedMenuVisible;
public static volatile boolean isPlaybackSpeedMenuVisible;

public VideoSpeedMenuFilterPatch() {
public PlaybackSpeedMenuFilterPatch() {
pathFilterGroups.addAll(new StringFilterGroup(
null,
"playback_speed_sheet_content.eml-js"
Expand All @@ -14,7 +14,7 @@ public VideoSpeedMenuFilterPatch() {

@Override
boolean isFiltered(final String path, final String identifier, final byte[] protobufBufferArray) {
isVideoSpeedMenuVisible = super.isFiltered(path, identifier, protobufBufferArray);
isPlaybackSpeedMenuVisible = super.isFiltered(path, identifier, protobufBufferArray);

return false;
}
Expand Down
Expand Up @@ -13,12 +13,12 @@

import java.util.Arrays;

import app.revanced.integrations.patches.components.VideoSpeedMenuFilterPatch;
import app.revanced.integrations.patches.components.PlaybackSpeedMenuFilterPatch;
import app.revanced.integrations.settings.SettingsEnum;
import app.revanced.integrations.utils.LogHelper;
import app.revanced.integrations.utils.ReVancedUtils;

public class CustomVideoSpeedPatch {
public class CustomPlaybackSpeedPatch {
/**
* Maximum playback speed, exclusive value. Custom speeds must be less than this value.
*/
Expand All @@ -27,17 +27,17 @@ public class CustomVideoSpeedPatch {
/**
* Custom playback speeds.
*/
public static float[] customVideoSpeeds;
public static float[] customPlaybackSpeeds;

/**
* Minimum value of {@link #customVideoSpeeds}
* Minimum value of {@link #customPlaybackSpeeds}
*/
public static float minVideoSpeed;
public static float minPlaybackSpeed;

/**
* Maxium value of {@link #customVideoSpeeds}
* Maxium value of {@link #customPlaybackSpeeds}
*/
public static float maxVideoSpeed;
public static float maxPlaybackSpeed;

/**
* PreferenceList entries and values, of all available playback speeds.
Expand All @@ -60,10 +60,10 @@ private static void loadCustomSpeeds() {
if (speedStrings.length == 0) {
throw new IllegalArgumentException();
}
customVideoSpeeds = new float[speedStrings.length];
customPlaybackSpeeds = new float[speedStrings.length];
for (int i = 0, length = speedStrings.length; i < length; i++) {
final float speed = Float.parseFloat(speedStrings[i]);
if (speed <= 0 || arrayContains(customVideoSpeeds, speed)) {
if (speed <= 0 || arrayContains(customPlaybackSpeeds, speed)) {
throw new IllegalArgumentException();
}
if (speed >= MAXIMUM_PLAYBACK_SPEED) {
Expand All @@ -72,13 +72,13 @@ private static void loadCustomSpeeds() {
loadCustomSpeeds();
return;
}
minVideoSpeed = Math.min(minVideoSpeed, speed);
maxVideoSpeed = Math.max(maxVideoSpeed, speed);
customVideoSpeeds[i] = speed;
minPlaybackSpeed = Math.min(minPlaybackSpeed, speed);
maxPlaybackSpeed = Math.max(maxPlaybackSpeed, speed);
customPlaybackSpeeds[i] = speed;
}
} catch (Exception ex) {
LogHelper.printInfo(() -> "parse error", ex);
resetCustomSpeeds("Invalid custom video speeds. Using default values.");
resetCustomSpeeds("Invalid custom playback speeds. Using default values.");
loadCustomSpeeds();
}
}
Expand All @@ -95,10 +95,10 @@ private static boolean arrayContains(float[] array, float value) {
*/
public static void initializeListPreference(ListPreference preference) {
if (preferenceListEntries == null) {
preferenceListEntries = new String[customVideoSpeeds.length];
preferenceListEntryValues = new String[customVideoSpeeds.length];
preferenceListEntries = new String[customPlaybackSpeeds.length];
preferenceListEntryValues = new String[customPlaybackSpeeds.length];
int i = 0;
for (float speed : customVideoSpeeds) {
for (float speed : customPlaybackSpeeds) {
String speedString = String.valueOf(speed);
preferenceListEntries[i] = speedString + "x";
preferenceListEntryValues[i] = speedString;
Expand All @@ -115,14 +115,14 @@ public static void initializeListPreference(ListPreference preference) {
public static void onFlyoutMenuCreate(final LinearLayout linearLayout) {
// The playback rate menu is a RecyclerView with 2 children. The third child is the "Advanced" quality menu.
addRecyclerListener(linearLayout, 2, 1, recyclerView -> {
if (VideoSpeedMenuFilterPatch.isVideoSpeedMenuVisible &&
if (PlaybackSpeedMenuFilterPatch.isPlaybackSpeedMenuVisible &&
recyclerView.getChildCount() == 1 &&
recyclerView.getChildAt(0) instanceof ComponentHost
) {
linearLayout.setVisibility(View.GONE);

// Close the new video speed menu and instead show the old one.
showOldVideoSpeedMenu();
// Close the new Playback speed menu and instead show the old one.
showOldPlaybackSpeedMenu();

// DismissView [R.id.touch_outside] is the 1st ChildView of the 3rd ParentView.
((ViewGroup) linearLayout.getParent().getParent().getParent())
Expand All @@ -131,7 +131,7 @@ public static void onFlyoutMenuCreate(final LinearLayout linearLayout) {
});
}

public static void showOldVideoSpeedMenu() {
public static void showOldPlaybackSpeedMenu() {
LogHelper.printDebug(() -> "Old video quality menu shown");

// Rest of the implementation added by patch.
Expand Down
Expand Up @@ -24,7 +24,7 @@

import com.google.android.apps.youtube.app.application.Shell_HomeActivity;

import app.revanced.integrations.patches.playback.speed.CustomVideoSpeedPatch;
import app.revanced.integrations.patches.playback.speed.CustomPlaybackSpeedPatch;
import app.revanced.integrations.settings.SettingsEnum;
import app.revanced.integrations.settings.SharedPrefCategory;
import app.revanced.integrations.utils.LogHelper;
Expand Down Expand Up @@ -135,7 +135,7 @@ public void onActivityCreated(@Nullable Bundle savedInstanceState) {
// if the preference was included, then initialize it based on the available playback speed
Preference defaultSpeedPreference = findPreference(SettingsEnum.PLAYBACK_SPEED_DEFAULT.path);
if (defaultSpeedPreference instanceof ListPreference) {
CustomVideoSpeedPatch.initializeListPreference((ListPreference) defaultSpeedPreference);
CustomPlaybackSpeedPatch.initializeListPreference((ListPreference) defaultSpeedPreference);
}

// Set current value from SettingsEnum
Expand Down

0 comments on commit 630776f

Please sign in to comment.