Skip to content

Commit

Permalink
chore: merge branch dev to main (#437)
Browse files Browse the repository at this point in the history
  • Loading branch information
oSumAtrIX authored Jul 20, 2023
2 parents 9bfdff3 + 0582d7b commit 3990b45
Show file tree
Hide file tree
Showing 13 changed files with 169 additions and 98 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,13 @@ private static void clearRemovedShortsTextViews() {
*/
public static boolean setShortsDislikes(@NonNull View likeDislikeView) {
try {
if (!SettingsEnum.RYD_ENABLED.getBoolean() || !SettingsEnum.RYD_SHORTS.getBoolean()) {
if (!SettingsEnum.RYD_ENABLED.getBoolean()) {
return false;
}
if (!SettingsEnum.RYD_SHORTS.getBoolean()) {
// Must clear the data here, in case a new video was loaded while PlayerType
// suggested the video was not a short (can happen when spoofing to an old app version).
ReturnYouTubeDislike.setCurrentVideoId(null);
return false;
}
LogHelper.printDebug(() -> "setShortsDislikes");
Expand Down Expand Up @@ -302,7 +308,7 @@ public static void newVideoLoaded(@NonNull String videoId) {
if (!videoId.equals(currentVideoId)) {
currentVideoId = videoId;

final boolean noneHiddenOrMinimized = PlayerType.getCurrent().isNoneHiddenOrMinimized();
final boolean noneHiddenOrMinimized = PlayerType.getCurrent().isNoneOrHidden();
if (noneHiddenOrMinimized && !SettingsEnum.RYD_SHORTS.getBoolean()) {
ReturnYouTubeDislike.setCurrentVideoId(null);
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

import static app.revanced.integrations.utils.ReVancedUtils.containsAny;

import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;

import app.revanced.integrations.settings.SettingsEnum;
import app.revanced.integrations.shared.PlayerType;
import app.revanced.integrations.utils.LogHelper;
Expand Down Expand Up @@ -67,4 +71,25 @@ public static String overrideProtobufParameter(String originalValue) {
return originalValue;
}

/**
* Injection point.
*/
public static boolean getSeekbarThumbnailOverrideValue() {
return SettingsEnum.SPOOF_SIGNATURE_VERIFICATION.getBoolean();
}

/**
* Injection point.
*
* @param view seekbar thumbnail view. Includes both shorts and regular videos.
*/
public static void seekbarImageViewCreated(ImageView view) {
if (SettingsEnum.SPOOF_SIGNATURE_VERIFICATION.getBoolean()) {
view.setVisibility(View.GONE);
// Also hide the border around the thumbnail (otherwise a 1 pixel wide bordered frame is visible).
ViewGroup parentLayout = (ViewGroup) view.getParent();
parentLayout.setPadding(0, 0, 0, 0);
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public final class VideoInformation {
@NonNull
private static String videoId = "";
private static long videoLength = 0;
private static volatile long videoTime = -1; // must be volatile. Value is set off main thread from high precision patch hook
private static long videoTime = -1;
/**
* The current playback speed
*/
Expand Down Expand Up @@ -98,17 +98,17 @@ public static void setVideoLength(final long length) {

/**
* Injection point.
* Called off the main thread approximately every 50ms to 100ms
* Called on the main thread every 1000ms.
*
* @param currentPlaybackTime The current playback time of the video in milliseconds.
*/
public static void setVideoTimeHighPrecision(final long currentPlaybackTime) {
public static void setVideoTime(final long currentPlaybackTime) {
videoTime = currentPlaybackTime;
}

/**
* Seek on the current video.
* Does not function for playback of Shorts or Stories.
* Does not function for playback of Shorts.
*
* Caution: If called from a videoTimeHook() callback,
* this will cause a recursive call into the same videoTimeHook() callback.
Expand All @@ -118,11 +118,6 @@ public static void setVideoTimeHighPrecision(final long currentPlaybackTime) {
*/
public static boolean seekTo(final long millisecond) {
ReVancedUtils.verifyOnMainThread();
if (seekMethod == null) {
LogHelper.printException(() -> "seekMethod was null");
return false;
}

try {
LogHelper.printDebug(() -> "Seeking to " + millisecond);
return (Boolean) seekMethod.invoke(playerControllerRef.get(), millisecond);
Expand All @@ -137,7 +132,7 @@ public static boolean seekToRelative(long millisecondsRelative) {
}

/**
* Id of the current video playing. Includes Shorts and YouTube Stories.
* Id of the current video playing. Includes Shorts.
*
* @return The id of the video. Empty string if not set yet.
*/
Expand All @@ -154,7 +149,7 @@ public static float getPlaybackSpeed() {
}

/**
* Length of the current video playing. Includes Shorts and YouTube Stories.
* Length of the current video playing. Includes Shorts.
*
* @return The length of the video in milliseconds.
* If the video is not yet loaded, or if the video is playing in the background with no video visible,
Expand All @@ -165,14 +160,14 @@ public static long getVideoLength() {
}

/**
* Playback time of the current video playing.
* Value can lag up to approximately 100ms behind the actual current video playback time.
* Playback time of the current video playing. Includes Shorts.
*
* Note: Code inside a videoTimeHook patch callback
* should use the callback video time and avoid using this method
* (in situations of recursive hook callbacks, the value returned here may be outdated).
* Value will lag behind the actual playback time by a variable amount based on the playback speed.
*
* Includes Shorts and YouTube Stories.
* If playback speed is 2.0x, this value may be up to 2000ms behind the actual playback time.
* If playback speed is 1.0x, this value may be up to 1000ms behind the actual playback time.
* If playback speed is 0.5x, this value may be up to 500ms behind the actual playback time.
* Etc.
*
* @return The time of the video in milliseconds. -1 if not set yet.
*/
Expand All @@ -192,7 +187,7 @@ public static long getVideoTime() {
* @see VideoState
*/
public static boolean isAtEndOfVideo() {
return videoTime > 0 && videoLength > 0 && videoTime >= videoLength;
return videoTime >= videoLength && videoLength > 0;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ public AdsFilter() {
"_buttoned_layout",
"full_width_square_image_layout",
"_ad_with",
"text_image_button_group_layout",
"video_display_button_group_layout",
"landscape_image_wide_button_layout"
);
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -1,33 +1,22 @@
package app.revanced.integrations.patches.components;

import static app.revanced.integrations.utils.ReVancedUtils.hideViewBy1dpUnderCondition;
import static app.revanced.integrations.utils.ReVancedUtils.hideViewUnderCondition;

import android.annotation.SuppressLint;
import android.os.Build;
import android.view.View;

import app.revanced.integrations.settings.SettingsEnum;
import com.google.android.libraries.youtube.rendering.ui.pivotbar.PivotBar;

import app.revanced.integrations.settings.SettingsEnum;
import static app.revanced.integrations.utils.ReVancedUtils.hideViewBy1dpUnderCondition;
import static app.revanced.integrations.utils.ReVancedUtils.hideViewUnderCondition;

public final class ShortsFilter extends Filter {
// Set by patch.
public static PivotBar pivotBar;
@SuppressLint("StaticFieldLeak")

final StringFilterGroupList shortsFilterGroup = new StringFilterGroupList();
private final StringFilterGroup reelChannelBar = new StringFilterGroup(
null,
"reel_channel_bar"
);

private final StringFilterGroup infoPanel = new StringFilterGroup(
SettingsEnum.HIDE_SHORTS_INFO_PANEL,
"shorts_info_panel_overview"
);

public ShortsFilter() {
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.N) return;

final var thanksButton = new StringFilterGroup(
SettingsEnum.HIDE_SHORTS_THANKS_BUTTON,
"suggested_action"
Expand All @@ -48,6 +37,11 @@ public ShortsFilter() {
"reel_pivot_button"
);

final var infoPanel = new StringFilterGroup(
SettingsEnum.HIDE_SHORTS_INFO_PANEL,
"shorts_info_panel_overview"
);

final var channelBar = new StringFilterGroup(
SettingsEnum.HIDE_SHORTS_CHANNEL_BAR,
"reel_channel_bar"
Expand All @@ -61,19 +55,20 @@ public ShortsFilter() {
"shorts_video_cell"
);

this.pathFilterGroups.addAll(joinButton, subscribeButton, soundButton, channelBar);
this.identifierFilterGroups.addAll(shorts, thanksButton);
shortsFilterGroup.addAll(soundButton, infoPanel);
pathFilterGroups.addAll(joinButton, subscribeButton, channelBar);
identifierFilterGroups.addAll(shorts, thanksButton);
}

@Override
boolean isFiltered(final String path, final String identifier,
final byte[] protobufBufferArray) {

// Filter the path only when reelChannelBar is visible.
if (reelChannelBar.check(path).isFiltered())
if (this.pathFilterGroups.contains(path)) return true;

// Shorts info panel path appears outside of reelChannelBar path.
if (infoPanel.isEnabled() && infoPanel.check(path).isFiltered()) return true;
if (shortsFilterGroup.contains(path)) return true;

return this.identifierFilterGroups.contains(identifier);
}
Expand Down
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ public static void newVideoLoaded(@NonNull String videoId) {
// If a Short is opened while a regular video is on screen, this will incorrectly set this as false.
// But this check is needed to fix unusual situations of opening/closing the app
// while both a regular video and a short are on screen.
dislikeDataIsShort = currentPlayerType.isNoneHiddenOrMinimized();
dislikeDataIsShort = currentPlayerType.isNoneOrHidden();

RYDCachedFetch entry = futureCache.get(videoId);
if (entry != null && entry.futureInProgressOrFinishedSuccessfully()) {
Expand Down Expand Up @@ -371,7 +371,7 @@ public static void sendVote(@NonNull Vote vote) {
// Must make a local copy of videoId, since it may change between now and when the vote thread runs.
String videoIdToVoteFor = getCurrentVideoId();
if (videoIdToVoteFor == null ||
(SettingsEnum.RYD_SHORTS.getBoolean() && dislikeDataIsShort != PlayerType.getCurrent().isNoneHiddenOrMinimized())) {
(SettingsEnum.RYD_SHORTS.getBoolean() && dislikeDataIsShort != PlayerType.getCurrent().isNoneOrHidden())) {
// User enabled RYD after starting playback of a video.
// Or shorts was loaded with regular video present, then shorts was closed,
// and then user voted on the now visible original video.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,8 @@ public enum SettingsEnum {
EXTERNAL_BROWSER("revanced_external_browser", BOOLEAN, TRUE, true),
AUTO_REPEAT("revanced_auto_repeat", BOOLEAN, FALSE),
SEEKBAR_TAPPING("revanced_seekbar_tapping", BOOLEAN, TRUE),
SPOOF_SIGNATURE_VERIFICATION("revanced_spoof_signature_verification", BOOLEAN, TRUE, "revanced_spoof_signature_verification_user_dialog_message"),
SPOOF_SIGNATURE_VERIFICATION("revanced_spoof_signature_verification", BOOLEAN, TRUE, true,
"revanced_spoof_signature_verification_user_dialog_message"),

// Swipe controls
SWIPE_BRIGHTNESS("revanced_swipe_brightness", BOOLEAN, TRUE),
Expand Down
Loading

0 comments on commit 3990b45

Please sign in to comment.