Skip to content

Commit

Permalink
fix button fade out after maximizing
Browse files Browse the repository at this point in the history
  • Loading branch information
MarcaDian authored and LisoUseInAIKyrios committed Feb 22, 2025
1 parent 893045d commit 48a7347
Show file tree
Hide file tree
Showing 8 changed files with 31 additions and 115 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,6 @@

import app.revanced.extension.youtube.shared.PlayerType;
import app.revanced.extension.youtube.shared.VideoState;
import app.revanced.extension.youtube.sponsorblock.ui.CreateSegmentButton;
import app.revanced.extension.youtube.sponsorblock.ui.VotingButton;
import app.revanced.extension.youtube.videoplayer.CopyVideoUrlButton;
import app.revanced.extension.youtube.videoplayer.CopyVideoUrlTimestampButton;
import app.revanced.extension.youtube.videoplayer.ExternalDownloadButton;
import app.revanced.extension.youtube.videoplayer.PlaybackSpeedDialogButton;

@SuppressWarnings("unused")
public class PlayerTypeHookPatch {
Expand All @@ -20,17 +14,6 @@ public static void setPlayerType(@Nullable Enum<?> youTubePlayerType) {
if (youTubePlayerType == null) return;

PlayerType.setFromString(youTubePlayerType.name());

// Synchronize the visibility of custom player buttons whenever the player type changes.
// This ensures that button animations are cleared and their states are updated correctly
// when switching between states like minimized, maximized, or fullscreen, preventing
// "stuck" animations or incorrect visibility.
CopyVideoUrlButton.onPlayerTypeChanged(PlayerType.getCurrent());
CopyVideoUrlTimestampButton.onPlayerTypeChanged(PlayerType.getCurrent());
ExternalDownloadButton.onPlayerTypeChanged(PlayerType.getCurrent());
PlaybackSpeedDialogButton.onPlayerTypeChanged(PlayerType.getCurrent());
CreateSegmentButton.onPlayerTypeChanged(PlayerType.getCurrent());
VotingButton.onPlayerTypeChanged(PlayerType.getCurrent());
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import app.revanced.extension.shared.Logger;
import app.revanced.extension.youtube.patches.VideoInformation;
import app.revanced.extension.youtube.settings.Settings;
import app.revanced.extension.youtube.shared.PlayerType;
import app.revanced.extension.youtube.videoplayer.PlayerControlButton;

public class CreateSegmentButton {
Expand Down Expand Up @@ -50,18 +49,6 @@ public static void setVisibility(boolean visible, boolean animated) {
if (instance != null) instance.setVisibility(visible, animated);
}

/**
* Injection point
*/
public static void onPlayerTypeChanged(PlayerType newType) {
if (instance != null) {
Logger.printDebug(() -> "Player type changed to: " + newType);
if (newType == PlayerType.WATCH_WHILE_MINIMIZED || newType.isMaximizedOrFullscreen()) {
instance.syncVisibility();
}
}
}

private static boolean shouldBeShown() {
return Settings.SB_ENABLED.get() && Settings.SB_CREATE_NEW_SEGMENT.get()
&& !VideoInformation.isAtEndOfVideo();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import app.revanced.extension.shared.Logger;
import app.revanced.extension.youtube.patches.VideoInformation;
import app.revanced.extension.youtube.settings.Settings;
import app.revanced.extension.youtube.shared.PlayerType;
import app.revanced.extension.youtube.sponsorblock.SegmentPlaybackController;
import app.revanced.extension.youtube.sponsorblock.SponsorBlockUtils;
import app.revanced.extension.youtube.videoplayer.PlayerControlButton;
Expand Down Expand Up @@ -52,18 +51,6 @@ public static void setVisibility(boolean visible, boolean animated) {
if (instance != null) instance.setVisibility(visible, animated);
}

/**
* Injection point
*/
public static void onPlayerTypeChanged(PlayerType newType) {
if (instance != null) {
Logger.printDebug(() -> "Player type changed to: " + newType);
if (newType == PlayerType.WATCH_WHILE_MINIMIZED || newType.isMaximizedOrFullscreen()) {
instance.syncVisibility();
}
}
}

private static boolean shouldBeShown() {
return Settings.SB_ENABLED.get() && Settings.SB_VOTING_BUTTON.get()
&& SegmentPlaybackController.videoHasSegments() && !VideoInformation.isAtEndOfVideo();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package app.revanced.extension.youtube.videoplayer;

import android.view.View;
import android.view.ViewGroup;

import androidx.annotation.Nullable;

Expand Down Expand Up @@ -49,16 +48,4 @@ public static void setVisibilityImmediate(boolean visible) {
public static void setVisibility(boolean visible, boolean animated) {
if (instance != null) instance.setVisibility(visible, animated);
}

/**
* Injection point
*/
public static void onPlayerTypeChanged(PlayerType newType) {
if (instance != null) {
Logger.printDebug(() -> "Player type changed to: " + newType);
if (newType == PlayerType.WATCH_WHILE_MINIMIZED || newType.isMaximizedOrFullscreen()) {
instance.syncVisibility();
}
}
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package app.revanced.extension.youtube.videoplayer;

import android.view.View;
import android.view.ViewGroup;

import androidx.annotation.Nullable;

Expand Down Expand Up @@ -49,16 +48,4 @@ public static void setVisibilityImmediate(boolean visible) {
public static void setVisibility(boolean visible, boolean animated) {
if (instance != null) instance.setVisibility(visible, animated);
}

/**
* Injection point
*/
public static void onPlayerTypeChanged(PlayerType newType) {
if (instance != null) {
Logger.printDebug(() -> "Player type changed to: " + newType);
if (newType == PlayerType.WATCH_WHILE_MINIMIZED || newType.isMaximizedOrFullscreen()) {
instance.syncVisibility();
}
}
}
}
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
package app.revanced.extension.youtube.videoplayer;

import android.view.View;
import android.view.ViewGroup;

import androidx.annotation.Nullable;

import app.revanced.extension.shared.Logger;
import app.revanced.extension.youtube.patches.DownloadsPatch;
import app.revanced.extension.youtube.patches.VideoInformation;
import app.revanced.extension.youtube.settings.Settings;
import app.revanced.extension.youtube.shared.PlayerType;

@SuppressWarnings("unused")
public class ExternalDownloadButton {
Expand Down Expand Up @@ -48,18 +46,6 @@ public static void setVisibility(boolean visible, boolean animated) {
if (instance != null) instance.setVisibility(visible, animated);
}

/**
* Injection point
*/
public static void onPlayerTypeChanged(PlayerType newType) {
if (instance != null) {
Logger.printDebug(() -> "Player type changed to: " + newType);
if (newType == PlayerType.WATCH_WHILE_MINIMIZED || newType.isMaximizedOrFullscreen()) {
instance.syncVisibility();
}
}
}

private static void onDownloadClick(View view) {
DownloadsPatch.launchExternalDownloader(
VideoInformation.getVideoId(),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
package app.revanced.extension.youtube.videoplayer;

import android.view.View;
import android.view.ViewGroup;

import androidx.annotation.Nullable;

import app.revanced.extension.shared.Logger;
import app.revanced.extension.youtube.patches.playback.speed.CustomPlaybackSpeedPatch;
import app.revanced.extension.youtube.settings.Settings;
import app.revanced.extension.youtube.shared.PlayerType;

@SuppressWarnings("unused")
public class PlaybackSpeedDialogButton {
Expand Down Expand Up @@ -46,16 +44,4 @@ public static void setVisibilityImmediate(boolean visible) {
public static void setVisibility(boolean visible, boolean animated) {
if (instance != null) instance.setVisibility(visible, animated);
}

/**
* Injection point
*/
public static void onPlayerTypeChanged(PlayerType newType) {
if (instance != null) {
Logger.printDebug(() -> "Player type changed to: " + newType);
if (newType == PlayerType.WATCH_WHILE_MINIMIZED || newType.isMaximizedOrFullscreen()) {
instance.syncVisibility();
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@

import app.revanced.extension.shared.Logger;
import app.revanced.extension.shared.Utils;
import app.revanced.extension.youtube.shared.PlayerType;
import kotlin.Unit;

public class PlayerControlButton {
public interface PlayerControlButtonVisibility {
Expand Down Expand Up @@ -75,6 +77,16 @@ public PlayerControlButton(View controlsViewGroup,
visibilityCheck = buttonVisibility;
buttonRef = new WeakReference<>(imageView);
isVisible = false;

// Update the visibility after the player type changes.
// This ensures that button animations are cleared and their states are updated correctly
// when switching between states like minimized, maximized, or fullscreen, preventing
// "stuck" animations or incorrect visibility. Without this fix the issue is most noticable
// when maximizing type 3 miniplayer.
PlayerType.getOnChange().addObserver((PlayerType type) -> {
playerTypeChanged(type);
return Unit.INSTANCE;
});
}

public void setVisibilityImmediate(boolean visible) {
Expand Down Expand Up @@ -129,31 +141,19 @@ private void private_setVisibility(boolean visible, boolean animated) {
}
}

public void hide() {
if (!isVisible) return;

Utils.verifyOnMainThread();
View view = buttonRef.get();
if (view == null) return;
view.setVisibility(View.GONE);

view = placeHolderRef.get();
if (view != null) view.setVisibility(View.GONE);
isVisible = false;
}

/**
* Synchronizes the button state after the player state changes.
* Call this method manually when the player is deployed from a miniplayer.
*/
public void syncVisibility() {
Utils.verifyOnMainThread();
private void playerTypeChanged(PlayerType newType) {
if (newType != PlayerType.WATCH_WHILE_MINIMIZED && !newType.isMaximizedOrFullscreen()) {
return;
}

View button = buttonRef.get();
if (button == null) return;

button.clearAnimation();
View placeholder = placeHolderRef.get();
Logger.printDebug(() -> "Syncing visibility: isVisible=" + isVisible + ", shouldBeShown=" + visibilityCheck.shouldBeShown());
button.clearAnimation(); // Очищаємо анімацію

if (visibilityCheck.shouldBeShown()) {
if (isVisible) {
Expand All @@ -168,4 +168,17 @@ public void syncVisibility() {
if (placeholder != null) placeholder.setVisibility(View.GONE);
}
}

public void hide() {
if (!isVisible) return;

Utils.verifyOnMainThread();
View view = buttonRef.get();
if (view == null) return;
view.setVisibility(View.GONE);

view = placeHolderRef.get();
if (view != null) view.setVisibility(View.GONE);
isVisible = false;
}
}

0 comments on commit 48a7347

Please sign in to comment.