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

Commit

Permalink
fix(YouTube): Show video chapter titles without clipping when overlay…
Browse files Browse the repository at this point in the history
… buttons are enabled (#699)
  • Loading branch information
LisoUseInAIKyrios authored Sep 23, 2024
1 parent f49d634 commit 325cc17
Show file tree
Hide file tree
Showing 10 changed files with 252 additions and 135 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package app.revanced.integrations.youtube.patches;

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

import app.revanced.integrations.shared.Logger;

@SuppressWarnings("unused")
public class PlayerControlsPatch {
/**
* Injection point.
*/
public static void setFullscreenCloseButton(ImageView imageButton) {
// Add a global listener, since the protected method
// View#onVisibilityChanged() does not have any call backs.
imageButton.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
int lastVisibility = View.VISIBLE;

@Override
public void onGlobalLayout() {
try {
final int visibility = imageButton.getVisibility();
if (lastVisibility != visibility) {
lastVisibility = visibility;

Logger.printDebug(() -> "fullscreen button visibility: "
+ (visibility == View.VISIBLE ? "VISIBLE" :
visibility == View.GONE ? "GONE" : "INVISIBLE"));

fullscreenButtonVisibilityChanged(visibility == View.VISIBLE);
}
} catch (Exception ex) {
Logger.printDebug(() -> "OnGlobalLayoutListener failure", ex);
}
}
});
}

// noinspection EmptyMethod
public static void fullscreenButtonVisibilityChanged(boolean isVisible) {
// Code added during patching.
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -145,10 +145,8 @@ public LayoutComponentsFilter() {
);

// The player audio track button does the exact same function as the audio track flyout menu option.
// But if the copy url button is shown, these button clashes and the the audio button does not work.
// Previously this was a setting to show/hide the player button.
// But it was decided it's simpler to always hide this button because:
// - it doesn't work with copy video url feature
// - the button is rare
// - always hiding makes the ReVanced settings simpler and easier to understand
// - nobody is going to notice the redundant button is always hidden
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,9 @@
import app.revanced.integrations.youtube.settings.Settings;
import app.revanced.integrations.shared.Logger;
import app.revanced.integrations.shared.Utils;
import app.revanced.integrations.youtube.videoplayer.BottomControlButton;
import app.revanced.integrations.youtube.videoplayer.PlayerControlButton;

// Edit: This should be a subclass of PlayerControlButton
public class CreateSegmentButtonController {
private static WeakReference<ImageView> buttonReference = new WeakReference<>(null);
private static boolean isShowing;
Expand All @@ -27,35 +28,38 @@ public static void initialize(View youtubeControlsLayout) {
ImageView imageView = Objects.requireNonNull(youtubeControlsLayout.findViewById(
getResourceIdentifier("revanced_sb_create_segment_button", "id")));
imageView.setVisibility(View.GONE);
imageView.setOnClickListener(v -> {
SponsorBlockViewController.toggleNewSegmentLayoutVisibility();
});
imageView.setOnClickListener(v -> SponsorBlockViewController.toggleNewSegmentLayoutVisibility());

buttonReference = new WeakReference<>(imageView);
} catch (Exception ex) {
Logger.printException(() -> "initialize failure", ex);
}
}

public static void changeVisibilityImmediate(boolean visible) {
changeVisibility(visible, true);
}

/**
* injection point
*/
public static void changeVisibilityNegatedImmediate(boolean visible) {
changeVisibility(!visible, true);
public static void changeVisibilityImmediate(boolean visible) {
if (visible) {
// Fix button flickering, by pushing this call to the back of
// the main thread and letting other layout code run first.
Utils.runOnMainThread(() -> setVisibility(true, false));
} else {
setVisibility(false, false);
}
}

/**
* injection point
*/
public static void changeVisibility(boolean visible) {
changeVisibility(visible, false);
public static void changeVisibility(boolean visible, boolean animated) {
// Ignore this call, otherwise with full screen thumbnails the buttons are visible while seeking.
if (visible && !animated) return;

setVisibility(visible, animated);
}

public static void changeVisibility(boolean visible, boolean immediate) {
private static void setVisibility(boolean visible, boolean animated) {
try {
if (isShowing == visible) return;
isShowing = visible;
Expand All @@ -68,17 +72,17 @@ public static void changeVisibility(boolean visible, boolean immediate) {
if (!shouldBeShown()) {
return;
}
if (!immediate) {
iView.startAnimation(BottomControlButton.getButtonFadeIn());
if (animated) {
iView.startAnimation(PlayerControlButton.getButtonFadeIn());
}
iView.setVisibility(View.VISIBLE);
return;
}

if (iView.getVisibility() == View.VISIBLE) {
iView.clearAnimation();
if (!immediate) {
iView.startAnimation(BottomControlButton.getButtonFadeOut());
if (animated) {
iView.startAnimation(PlayerControlButton.getButtonFadeOut());
}
iView.setVisibility(View.GONE);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,9 @@
import app.revanced.integrations.youtube.sponsorblock.SponsorBlockUtils;
import app.revanced.integrations.shared.Logger;
import app.revanced.integrations.shared.Utils;
import app.revanced.integrations.youtube.videoplayer.BottomControlButton;
import app.revanced.integrations.youtube.videoplayer.PlayerControlButton;

// Edit: This should be a subclass of PlayerControlButton
public class VotingButtonController {
private static WeakReference<ImageView> buttonReference = new WeakReference<>(null);
private static boolean isShowing;
Expand All @@ -29,35 +30,41 @@ public static void initialize(View youtubeControlsLayout) {
ImageView imageView = Objects.requireNonNull(youtubeControlsLayout.findViewById(
getResourceIdentifier("revanced_sb_voting_button", "id")));
imageView.setVisibility(View.GONE);
imageView.setOnClickListener(v -> {
SponsorBlockUtils.onVotingClicked(v.getContext());
});
imageView.setOnClickListener(v -> SponsorBlockUtils.onVotingClicked(v.getContext()));

buttonReference = new WeakReference<>(imageView);
} catch (Exception ex) {
Logger.printException(() -> "Unable to set RelativeLayout", ex);
Logger.printException(() -> "initialize failure", ex);
}
}

/**
* injection point
*/
public static void changeVisibilityImmediate(boolean visible) {
changeVisibility(visible, true);
if (visible) {
// Fix button flickering, by pushing this call to the back of
// the main thread and letting other layout code run first.
Utils.runOnMainThread(() -> setVisibility(true, false));
} else {
setVisibility(false, false);
}
}

/**
* injection point
*/
public static void changeVisibilityNegatedImmediate(boolean visible) {
changeVisibility(!visible, true);
public static void changeVisibility(boolean visible, boolean animated) {
// Ignore this call, otherwise with full screen thumbnails the buttons are visible while seeking.
if (visible && !animated) return;

setVisibility(visible, animated);
}

/**
* injection point
*/
public static void changeVisibility(boolean visible) {
changeVisibility(visible, false);
}

public static void changeVisibility(boolean visible, boolean immediate) {
private static void setVisibility(boolean visible, boolean animated) {
try {
if (isShowing == visible) return;
isShowing = visible;
Expand All @@ -70,17 +77,17 @@ public static void changeVisibility(boolean visible, boolean immediate) {
if (!shouldBeShown()) {
return;
}
if (!immediate) {
iView.startAnimation(BottomControlButton.getButtonFadeIn());
if (animated) {
iView.startAnimation(PlayerControlButton.getButtonFadeIn());
}
iView.setVisibility(View.VISIBLE);
return;
}

if (iView.getVisibility() == View.VISIBLE) {
iView.clearAnimation();
if (!immediate) {
iView.startAnimation(BottomControlButton.getButtonFadeOut());
if (animated) {
iView.startAnimation(PlayerControlButton.getButtonFadeOut());
}
iView.setVisibility(View.GONE);
}
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
import app.revanced.integrations.youtube.settings.Settings;
import app.revanced.integrations.shared.Logger;

public class CopyVideoUrlButton extends BottomControlButton {
@SuppressWarnings("unused")
public class CopyVideoUrlButton extends PlayerControlButton {
@Nullable
private static CopyVideoUrlButton instance;

Expand Down Expand Up @@ -38,9 +39,16 @@ public static void initializeButton(View view) {
}

/**
* Injection point.
* injection point
*/
public static void changeVisibilityImmediate(boolean visible) {
if (instance != null) instance.setVisibilityImmediate(visible);
}

/**
* injection point
*/
public static void changeVisibility(boolean showing) {
if (instance != null) instance.setVisibility(showing);
public static void changeVisibility(boolean visible, boolean animated) {
if (instance != null) instance.setVisibility(visible, animated);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
import app.revanced.integrations.youtube.settings.Settings;
import app.revanced.integrations.shared.Logger;

public class CopyVideoUrlTimestampButton extends BottomControlButton {
@SuppressWarnings("unused")
public class CopyVideoUrlTimestampButton extends PlayerControlButton {
@Nullable
private static CopyVideoUrlTimestampButton instance;

Expand Down Expand Up @@ -38,10 +39,16 @@ public static void initializeButton(View bottomControlsViewGroup) {
}

/**
* Injection point.
* injection point
*/
public static void changeVisibility(boolean showing) {
if (instance != null) instance.setVisibility(showing);
public static void changeVisibilityImmediate(boolean visible) {
if (instance != null) instance.setVisibilityImmediate(visible);
}

/**
* injection point
*/
public static void changeVisibility(boolean visible, boolean animated) {
if (instance != null) instance.setVisibility(visible, animated);
}
}
Loading

0 comments on commit 325cc17

Please sign in to comment.