feat(youtube): rename video-speed to playback-speed (#438)

This commit is contained in:
KAZI MMT 2023-07-15 18:32:21 +06:00 committed by GitHub
parent 0e18f209dc
commit 630776fd35
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 27 additions and 27 deletions

View File

@ -1,11 +1,11 @@
package app.revanced.integrations.patches.components; package app.revanced.integrations.patches.components;
// Abuse LithoFilter for CustomVideoSpeedPatch. // Abuse LithoFilter for CustomPlaybackSpeedPatch.
public final class VideoSpeedMenuFilterPatch extends Filter { 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. // 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( pathFilterGroups.addAll(new StringFilterGroup(
null, null,
"playback_speed_sheet_content.eml-js" "playback_speed_sheet_content.eml-js"
@ -14,7 +14,7 @@ public final class VideoSpeedMenuFilterPatch extends Filter {
@Override @Override
boolean isFiltered(final String path, final String identifier, final byte[] protobufBufferArray) { 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; return false;
} }

View File

@ -13,12 +13,12 @@ import com.facebook.litho.ComponentHost;
import java.util.Arrays; 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.settings.SettingsEnum;
import app.revanced.integrations.utils.LogHelper; import app.revanced.integrations.utils.LogHelper;
import app.revanced.integrations.utils.ReVancedUtils; 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. * Maximum playback speed, exclusive value. Custom speeds must be less than this value.
*/ */
@ -27,17 +27,17 @@ public class CustomVideoSpeedPatch {
/** /**
* Custom playback speeds. * 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. * PreferenceList entries and values, of all available playback speeds.
@ -60,10 +60,10 @@ public class CustomVideoSpeedPatch {
if (speedStrings.length == 0) { if (speedStrings.length == 0) {
throw new IllegalArgumentException(); throw new IllegalArgumentException();
} }
customVideoSpeeds = new float[speedStrings.length]; customPlaybackSpeeds = new float[speedStrings.length];
for (int i = 0, length = speedStrings.length; i < length; i++) { for (int i = 0, length = speedStrings.length; i < length; i++) {
final float speed = Float.parseFloat(speedStrings[i]); final float speed = Float.parseFloat(speedStrings[i]);
if (speed <= 0 || arrayContains(customVideoSpeeds, speed)) { if (speed <= 0 || arrayContains(customPlaybackSpeeds, speed)) {
throw new IllegalArgumentException(); throw new IllegalArgumentException();
} }
if (speed >= MAXIMUM_PLAYBACK_SPEED) { if (speed >= MAXIMUM_PLAYBACK_SPEED) {
@ -72,13 +72,13 @@ public class CustomVideoSpeedPatch {
loadCustomSpeeds(); loadCustomSpeeds();
return; return;
} }
minVideoSpeed = Math.min(minVideoSpeed, speed); minPlaybackSpeed = Math.min(minPlaybackSpeed, speed);
maxVideoSpeed = Math.max(maxVideoSpeed, speed); maxPlaybackSpeed = Math.max(maxPlaybackSpeed, speed);
customVideoSpeeds[i] = speed; customPlaybackSpeeds[i] = speed;
} }
} catch (Exception ex) { } catch (Exception ex) {
LogHelper.printInfo(() -> "parse error", ex); LogHelper.printInfo(() -> "parse error", ex);
resetCustomSpeeds("Invalid custom video speeds. Using default values."); resetCustomSpeeds("Invalid custom playback speeds. Using default values.");
loadCustomSpeeds(); loadCustomSpeeds();
} }
} }
@ -95,10 +95,10 @@ public class CustomVideoSpeedPatch {
*/ */
public static void initializeListPreference(ListPreference preference) { public static void initializeListPreference(ListPreference preference) {
if (preferenceListEntries == null) { if (preferenceListEntries == null) {
preferenceListEntries = new String[customVideoSpeeds.length]; preferenceListEntries = new String[customPlaybackSpeeds.length];
preferenceListEntryValues = new String[customVideoSpeeds.length]; preferenceListEntryValues = new String[customPlaybackSpeeds.length];
int i = 0; int i = 0;
for (float speed : customVideoSpeeds) { for (float speed : customPlaybackSpeeds) {
String speedString = String.valueOf(speed); String speedString = String.valueOf(speed);
preferenceListEntries[i] = speedString + "x"; preferenceListEntries[i] = speedString + "x";
preferenceListEntryValues[i] = speedString; preferenceListEntryValues[i] = speedString;
@ -115,14 +115,14 @@ public class CustomVideoSpeedPatch {
public static void onFlyoutMenuCreate(final LinearLayout linearLayout) { 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. // The playback rate menu is a RecyclerView with 2 children. The third child is the "Advanced" quality menu.
addRecyclerListener(linearLayout, 2, 1, recyclerView -> { addRecyclerListener(linearLayout, 2, 1, recyclerView -> {
if (VideoSpeedMenuFilterPatch.isVideoSpeedMenuVisible && if (PlaybackSpeedMenuFilterPatch.isPlaybackSpeedMenuVisible &&
recyclerView.getChildCount() == 1 && recyclerView.getChildCount() == 1 &&
recyclerView.getChildAt(0) instanceof ComponentHost recyclerView.getChildAt(0) instanceof ComponentHost
) { ) {
linearLayout.setVisibility(View.GONE); linearLayout.setVisibility(View.GONE);
// Close the new video speed menu and instead show the old one. // Close the new Playback speed menu and instead show the old one.
showOldVideoSpeedMenu(); showOldPlaybackSpeedMenu();
// DismissView [R.id.touch_outside] is the 1st ChildView of the 3rd ParentView. // DismissView [R.id.touch_outside] is the 1st ChildView of the 3rd ParentView.
((ViewGroup) linearLayout.getParent().getParent().getParent()) ((ViewGroup) linearLayout.getParent().getParent().getParent())
@ -131,7 +131,7 @@ public class CustomVideoSpeedPatch {
}); });
} }
public static void showOldVideoSpeedMenu() { public static void showOldPlaybackSpeedMenu() {
LogHelper.printDebug(() -> "Old video quality menu shown"); LogHelper.printDebug(() -> "Old video quality menu shown");
// Rest of the implementation added by patch. // Rest of the implementation added by patch.

View File

@ -24,7 +24,7 @@ import androidx.annotation.Nullable;
import com.google.android.apps.youtube.app.application.Shell_HomeActivity; 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.SettingsEnum;
import app.revanced.integrations.settings.SharedPrefCategory; import app.revanced.integrations.settings.SharedPrefCategory;
import app.revanced.integrations.utils.LogHelper; import app.revanced.integrations.utils.LogHelper;
@ -135,7 +135,7 @@ public class ReVancedSettingsFragment extends PreferenceFragment {
// if the preference was included, then initialize it based on the available playback speed // if the preference was included, then initialize it based on the available playback speed
Preference defaultSpeedPreference = findPreference(SettingsEnum.PLAYBACK_SPEED_DEFAULT.path); Preference defaultSpeedPreference = findPreference(SettingsEnum.PLAYBACK_SPEED_DEFAULT.path);
if (defaultSpeedPreference instanceof ListPreference) { if (defaultSpeedPreference instanceof ListPreference) {
CustomVideoSpeedPatch.initializeListPreference((ListPreference) defaultSpeedPreference); CustomPlaybackSpeedPatch.initializeListPreference((ListPreference) defaultSpeedPreference);
} }
// Set current value from SettingsEnum // Set current value from SettingsEnum