Skip to content
This repository has been archived by the owner on Dec 9, 2024. It is now read-only.

Commit

Permalink
refactor(Hide Suggested Video Overlay): Match with Revanced code
Browse files Browse the repository at this point in the history
  • Loading branch information
YT-Advanced committed Feb 27, 2024
1 parent 2c84b54 commit 37dd8e6
Showing 1 changed file with 9 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
public class PlayerPatch {
private static boolean isAutoplayOn = false;

private static ImageView lastView;

public static void changePlayerOpacity(ImageView imageView) {
int opacity = SettingsEnum.CUSTOM_PLAYER_OVERLAY_OPACITY.getInt();

Expand Down Expand Up @@ -116,20 +118,16 @@ public static void hideSuggestedVideoOverlay(View view) {
}
}

public static void hideSuggestedVideoOverlay(ViewGroup viewGroup) {
public static void hideSuggestedVideoOverlay(ImageView imageView) {
if (!SettingsEnum.HIDE_SUGGESTED_VIDEO_OVERLAY.getBoolean() || isAutoplayOn)
return;

viewGroup.addOnLayoutChangeListener((v, left, top, right, bottom, oldLeft, oldTop, oldRight, oldBottom) -> {
try {
final View closeButton = ((LinearLayout) viewGroup.getChildAt(0)).getChildAt(1);
if (closeButton != null) {
closeButton.setSoundEffectsEnabled(false);
closeButton.performClick();
}
} catch (Exception ex) {
LogHelper.printException(() -> "hideSuggestedVideoOverlay failure", ex);
}
// Prevent adding the listener multiple times.
if (lastView == imageView) return;
lastView = imageView;

imageView.getViewTreeObserver().addOnGlobalLayoutListener(() -> {
if (imageView.isShown()) imageView.callOnClick();
});
}

Expand Down

1 comment on commit 37dd8e6

@rufusin
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hideSuggestedVideoOverlay(final ImageView imageView)

Please sign in to comment.