mirror of
https://github.com/inotia00/revanced-patches.git
synced 2025-06-13 13:47:42 +02:00
chore(YouTube Music): Use accurate keys and method names
This commit is contained in:
@ -3,121 +3,137 @@ package app.revanced.extension.music.patches.player;
|
||||
import static app.revanced.extension.shared.utils.Utils.hideViewByRemovingFromParentUnderCondition;
|
||||
import static app.revanced.extension.shared.utils.Utils.hideViewUnderCondition;
|
||||
import static app.revanced.extension.shared.utils.Utils.isSDKAbove;
|
||||
import static app.revanced.extension.shared.utils.Utils.runOnMainThreadDelayed;
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.graphics.Color;
|
||||
import android.view.View;
|
||||
|
||||
import java.util.Arrays;
|
||||
import org.apache.commons.lang3.ArrayUtils;
|
||||
|
||||
import java.lang.ref.WeakReference;
|
||||
|
||||
import app.revanced.extension.music.settings.Settings;
|
||||
import app.revanced.extension.music.shared.VideoType;
|
||||
import app.revanced.extension.music.utils.VideoUtils;
|
||||
import app.revanced.extension.shared.utils.Utils;
|
||||
import app.revanced.extension.shared.utils.Logger;
|
||||
|
||||
@SuppressWarnings({"unused"})
|
||||
@SuppressWarnings({"unused", "SpellCheckingInspection"})
|
||||
public class PlayerPatch {
|
||||
private static final int MUSIC_VIDEO_GREY_BACKGROUND_COLOR = -12566464;
|
||||
private static final int MUSIC_VIDEO_ORIGINAL_BACKGROUND_COLOR = -16579837;
|
||||
private static final boolean ADD_MINIPLAYER_NEXT_BUTTON =
|
||||
Settings.ADD_MINIPLAYER_NEXT_BUTTON.get();
|
||||
private static final boolean ADD_MINIPLAYER_PREVIOUS_BUTTON =
|
||||
Settings.ADD_MINIPLAYER_PREVIOUS_BUTTON.get();
|
||||
private static final boolean CHANGE_PLAYER_BACKGROUND_COLOR =
|
||||
Settings.CHANGE_PLAYER_BACKGROUND_COLOR.get();
|
||||
private static final boolean DISABLE_PLAYER_GESTURE =
|
||||
Settings.DISABLE_PLAYER_GESTURE.get();
|
||||
private static final boolean ENABLE_SWIPE_TO_DISMISS_MINIPLAYER =
|
||||
Settings.ENABLE_SWIPE_TO_DISMISS_MINIPLAYER.get();
|
||||
private static final boolean HIDE_DOUBLE_TAP_OVERLAY_FILTER =
|
||||
Settings.HIDE_DOUBLE_TAP_OVERLAY_FILTER.get();
|
||||
private static final boolean HIDE_FULLSCREEN_SHARE_BUTTON =
|
||||
Settings.HIDE_FULLSCREEN_SHARE_BUTTON.get();
|
||||
private static final boolean HIDE_SONG_VIDEO_TOGGLE =
|
||||
Settings.HIDE_SONG_VIDEO_TOGGLE.get();
|
||||
private static final boolean RESTORE_OLD_COMMENTS_POPUP_PANELS =
|
||||
Settings.RESTORE_OLD_COMMENTS_POPUP_PANELS.get();
|
||||
|
||||
@SuppressLint("StaticFieldLeak")
|
||||
public static View previousButton;
|
||||
@SuppressLint("StaticFieldLeak")
|
||||
public static View nextButton;
|
||||
private static final int MUSIC_VIDEO_GREY_BACKGROUND_COLOR = 0xFF404040;
|
||||
private static final int MUSIC_VIDEO_ORIGINAL_BACKGROUND_COLOR = 0xFF030303;
|
||||
|
||||
public static boolean disableMiniPlayerGesture() {
|
||||
return Settings.DISABLE_MINI_PLAYER_GESTURE.get();
|
||||
private static WeakReference<View> previousButtonViewRef = new WeakReference<>(null);
|
||||
private static WeakReference<View> nextButtonViewRef = new WeakReference<>(null);
|
||||
|
||||
public static boolean addMiniPlayerNextButton(boolean original) {
|
||||
return !ADD_MINIPLAYER_NEXT_BUTTON && original;
|
||||
}
|
||||
|
||||
public static boolean disablePlayerGesture() {
|
||||
return Settings.DISABLE_PLAYER_GESTURE.get();
|
||||
public static boolean changeMiniPlayerColor() {
|
||||
return Settings.CHANGE_MINIPLAYER_COLOR.get();
|
||||
}
|
||||
|
||||
public static boolean enableColorMatchPlayer() {
|
||||
return Settings.ENABLE_COLOR_MATCH_PLAYER.get();
|
||||
}
|
||||
|
||||
public static int enableBlackPlayerBackground(int originalColor) {
|
||||
return Settings.ENABLE_BLACK_PLAYER_BACKGROUND.get()
|
||||
&& originalColor != MUSIC_VIDEO_GREY_BACKGROUND_COLOR
|
||||
public static int changePlayerBackgroundColor(int originalColor) {
|
||||
return CHANGE_PLAYER_BACKGROUND_COLOR && originalColor != MUSIC_VIDEO_GREY_BACKGROUND_COLOR
|
||||
? Color.BLACK
|
||||
: originalColor;
|
||||
}
|
||||
|
||||
public static boolean enableForceMinimizedPlayer(boolean original) {
|
||||
return Settings.ENABLE_FORCE_MINIMIZED_PLAYER.get() || original;
|
||||
public static boolean disableMiniPlayerGesture() {
|
||||
return Settings.DISABLE_MINIPLAYER_GESTURE.get();
|
||||
}
|
||||
|
||||
public static boolean enableMiniPlayerNextButton(boolean original) {
|
||||
return !Settings.ENABLE_MINI_PLAYER_NEXT_BUTTON.get() && original;
|
||||
public static boolean disablePlayerGesture() {
|
||||
return DISABLE_PLAYER_GESTURE;
|
||||
}
|
||||
|
||||
public static boolean enableForcedMiniPlayer(boolean original) {
|
||||
return Settings.ENABLE_FORCED_MINIPLAYER.get() || original;
|
||||
}
|
||||
|
||||
public static View[] getViewArray(View[] oldViewArray) {
|
||||
if (previousButton != null) {
|
||||
if (nextButton != null) {
|
||||
return getViewArray(getViewArray(oldViewArray, previousButton), nextButton);
|
||||
} else {
|
||||
return getViewArray(oldViewArray, previousButton);
|
||||
View previousButtonView = previousButtonViewRef.get();
|
||||
if (previousButtonView != null) {
|
||||
oldViewArray = ArrayUtils.add(oldViewArray, previousButtonView);
|
||||
View nextButtonView = nextButtonViewRef.get();
|
||||
if (nextButtonView != null) {
|
||||
oldViewArray = ArrayUtils.add(oldViewArray, nextButtonView);
|
||||
}
|
||||
} else {
|
||||
return oldViewArray;
|
||||
}
|
||||
return oldViewArray;
|
||||
}
|
||||
|
||||
public static void setNextButtonView(View nextButtonView) {
|
||||
nextButtonViewRef = new WeakReference<>(nextButtonView);
|
||||
}
|
||||
|
||||
public static void setNextButtonOnClickListener(View nextButtonView) {
|
||||
if (nextButtonView != null) {
|
||||
hideViewUnderCondition(
|
||||
!ADD_MINIPLAYER_NEXT_BUTTON,
|
||||
nextButtonView
|
||||
);
|
||||
|
||||
nextButtonView.setOnClickListener(v -> nextButtonClicked(nextButtonView));
|
||||
}
|
||||
}
|
||||
|
||||
private static View[] getViewArray(View[] oldViewArray, View newView) {
|
||||
final int oldViewArrayLength = oldViewArray.length;
|
||||
|
||||
View[] newViewArray = Arrays.copyOf(oldViewArray, oldViewArrayLength + 1);
|
||||
newViewArray[oldViewArrayLength] = newView;
|
||||
return newViewArray;
|
||||
// rest of the implementation added by patch.
|
||||
private static void nextButtonClicked(View view) {
|
||||
// These instructions are ignored by patch.
|
||||
Logger.printDebug(() -> "next button clicked: " + view);
|
||||
}
|
||||
|
||||
public static void setNextButton(View nextButtonView) {
|
||||
if (nextButtonView == null)
|
||||
return;
|
||||
public static void setPreviousButtonView(View previousButtonView) {
|
||||
previousButtonViewRef = new WeakReference<>(previousButtonView);
|
||||
}
|
||||
|
||||
hideViewUnderCondition(
|
||||
!Settings.ENABLE_MINI_PLAYER_NEXT_BUTTON.get(),
|
||||
nextButtonView
|
||||
);
|
||||
public static void setPreviousButtonOnClickListener(View previousButtonView) {
|
||||
if (previousButtonView != null) {
|
||||
hideViewUnderCondition(
|
||||
!ADD_MINIPLAYER_PREVIOUS_BUTTON,
|
||||
previousButtonView
|
||||
);
|
||||
|
||||
nextButtonView.setOnClickListener(PlayerPatch::setNextButtonOnClickListener);
|
||||
previousButtonView.setOnClickListener(v -> previousButtonClicked(previousButtonView));
|
||||
}
|
||||
}
|
||||
|
||||
// rest of the implementation added by patch.
|
||||
private static void setNextButtonOnClickListener(View view) {
|
||||
if (Settings.ENABLE_MINI_PLAYER_NEXT_BUTTON.get())
|
||||
view.getClass();
|
||||
}
|
||||
|
||||
public static void setPreviousButton(View previousButtonView) {
|
||||
if (previousButtonView == null)
|
||||
return;
|
||||
|
||||
hideViewUnderCondition(
|
||||
!Settings.ENABLE_MINI_PLAYER_PREVIOUS_BUTTON.get(),
|
||||
previousButtonView
|
||||
);
|
||||
|
||||
previousButtonView.setOnClickListener(PlayerPatch::setPreviousButtonOnClickListener);
|
||||
}
|
||||
|
||||
// rest of the implementation added by patch.
|
||||
private static void setPreviousButtonOnClickListener(View view) {
|
||||
if (Settings.ENABLE_MINI_PLAYER_PREVIOUS_BUTTON.get())
|
||||
view.getClass();
|
||||
private static void previousButtonClicked(View view) {
|
||||
// These instructions are ignored by patch.
|
||||
Logger.printDebug(() -> "previous button clicked: " + view);
|
||||
}
|
||||
|
||||
public static boolean enableSwipeToDismissMiniPlayer() {
|
||||
return Settings.ENABLE_SWIPE_TO_DISMISS_MINI_PLAYER.get();
|
||||
return ENABLE_SWIPE_TO_DISMISS_MINIPLAYER;
|
||||
}
|
||||
|
||||
public static boolean enableSwipeToDismissMiniPlayer(boolean original) {
|
||||
return !Settings.ENABLE_SWIPE_TO_DISMISS_MINI_PLAYER.get() && original;
|
||||
return !ENABLE_SWIPE_TO_DISMISS_MINIPLAYER && original;
|
||||
}
|
||||
|
||||
public static Object enableSwipeToDismissMiniPlayer(Object object) {
|
||||
return Settings.ENABLE_SWIPE_TO_DISMISS_MINI_PLAYER.get() ? null : object;
|
||||
return ENABLE_SWIPE_TO_DISMISS_MINIPLAYER ? null : object;
|
||||
}
|
||||
|
||||
public static int enableZenMode(int originalColor) {
|
||||
@ -129,19 +145,20 @@ public class PlayerPatch {
|
||||
return originalColor;
|
||||
}
|
||||
|
||||
public static void hideAudioVideoSwitchToggle(View view, int originalVisibility) {
|
||||
if (Settings.HIDE_AUDIO_VIDEO_SWITCH_TOGGLE.get()) {
|
||||
originalVisibility = View.GONE;
|
||||
}
|
||||
view.setVisibility(originalVisibility);
|
||||
public static void hideSongVideoToggle(View view, int originalVisibility) {
|
||||
view.setVisibility(
|
||||
HIDE_SONG_VIDEO_TOGGLE
|
||||
? View.GONE
|
||||
: originalVisibility
|
||||
);
|
||||
}
|
||||
|
||||
public static void hideDoubleTapOverlayFilter(View view) {
|
||||
hideViewByRemovingFromParentUnderCondition(Settings.HIDE_DOUBLE_TAP_OVERLAY_FILTER, view);
|
||||
hideViewByRemovingFromParentUnderCondition(HIDE_DOUBLE_TAP_OVERLAY_FILTER, view);
|
||||
}
|
||||
|
||||
public static int hideFullscreenShareButton(int original) {
|
||||
return Settings.HIDE_FULLSCREEN_SHARE_BUTTON.get() ? 0 : original;
|
||||
return HIDE_FULLSCREEN_SHARE_BUTTON ? 0 : original;
|
||||
}
|
||||
|
||||
public static void setShuffleState(Enum<?> shuffleState) {
|
||||
@ -163,7 +180,7 @@ public class PlayerPatch {
|
||||
return;
|
||||
|
||||
if (needDelay) {
|
||||
Utils.runOnMainThreadDelayed(VideoUtils::shuffleTracks, 1000);
|
||||
runOnMainThreadDelayed(VideoUtils::shuffleTracks, 1000);
|
||||
} else {
|
||||
VideoUtils.shuffleTracks();
|
||||
}
|
||||
@ -185,7 +202,7 @@ public class PlayerPatch {
|
||||
if (!Settings.SETTINGS_INITIALIZED.get()) {
|
||||
return original;
|
||||
}
|
||||
return !Settings.RESTORE_OLD_COMMENTS_POPUP_PANELS.get() && original;
|
||||
return !RESTORE_OLD_COMMENTS_POPUP_PANELS && original;
|
||||
}
|
||||
|
||||
public static boolean restoreOldPlayerBackground(boolean original) {
|
||||
|
@ -130,21 +130,21 @@ public class Settings extends BaseSettings {
|
||||
|
||||
|
||||
// PreferenceScreen: Player
|
||||
public static final BooleanSetting ENABLE_MINI_PLAYER_NEXT_BUTTON = new BooleanSetting("revanced_enable_mini_player_next_button", TRUE, true);
|
||||
public static final BooleanSetting ENABLE_MINI_PLAYER_PREVIOUS_BUTTON = new BooleanSetting("revanced_enable_mini_player_previous_button", TRUE, true);
|
||||
public static final BooleanSetting ENABLE_COLOR_MATCH_PLAYER = new BooleanSetting("revanced_enable_color_match_player", TRUE);
|
||||
public static final BooleanSetting ENABLE_BLACK_PLAYER_BACKGROUND = new BooleanSetting("revanced_enable_black_player_background", FALSE, true);
|
||||
public static final BooleanSetting DISABLE_MINI_PLAYER_GESTURE = new BooleanSetting("revanced_disable_mini_player_gesture", FALSE, true);
|
||||
public static final BooleanSetting ADD_MINIPLAYER_NEXT_BUTTON = new BooleanSetting("revanced_add_miniplayer_next_button", TRUE, true);
|
||||
public static final BooleanSetting ADD_MINIPLAYER_PREVIOUS_BUTTON = new BooleanSetting("revanced_add_miniplayer_previous_button", TRUE, true);
|
||||
public static final BooleanSetting CHANGE_MINIPLAYER_COLOR = new BooleanSetting("revanced_change_miniplayer_color", TRUE);
|
||||
public static final BooleanSetting CHANGE_PLAYER_BACKGROUND_COLOR = new BooleanSetting("revanced_change_player_background_color", FALSE, true);
|
||||
public static final BooleanSetting DISABLE_MINIPLAYER_GESTURE = new BooleanSetting("revanced_disable_miniplayer_gesture", FALSE, true);
|
||||
public static final BooleanSetting DISABLE_PLAYER_GESTURE = new BooleanSetting("revanced_disable_player_gesture", FALSE, true);
|
||||
public static final BooleanSetting ENABLE_FORCE_MINIMIZED_PLAYER = new BooleanSetting("revanced_enable_force_minimized_player", TRUE);
|
||||
public static final BooleanSetting ENABLE_SWIPE_TO_DISMISS_MINI_PLAYER = new BooleanSetting("revanced_enable_swipe_to_dismiss_mini_player", TRUE, true);
|
||||
public static final BooleanSetting ENABLE_FORCED_MINIPLAYER = new BooleanSetting("revanced_enable_forced_miniplayer", TRUE);
|
||||
public static final BooleanSetting ENABLE_SWIPE_TO_DISMISS_MINIPLAYER = new BooleanSetting("revanced_enable_swipe_to_dismiss_miniplayer", TRUE, true);
|
||||
public static final BooleanSetting ENABLE_ZEN_MODE = new BooleanSetting("revanced_enable_zen_mode", FALSE);
|
||||
public static final BooleanSetting ENABLE_ZEN_MODE_PODCAST = new BooleanSetting("revanced_enable_zen_mode_podcast", FALSE);
|
||||
public static final BooleanSetting HIDE_COMMENT_CHANNEL_GUIDELINES = new BooleanSetting("revanced_hide_comment_channel_guidelines", TRUE);
|
||||
public static final BooleanSetting HIDE_DOUBLE_TAP_OVERLAY_FILTER = new BooleanSetting("revanced_hide_double_tap_overlay_filter", FALSE, true);
|
||||
public static final BooleanSetting HIDE_COMMENT_TIMESTAMP_AND_EMOJI_BUTTONS = new BooleanSetting("revanced_hide_comment_timestamp_and_emoji_buttons", FALSE);
|
||||
public static final BooleanSetting HIDE_FULLSCREEN_SHARE_BUTTON = new BooleanSetting("revanced_hide_fullscreen_share_button", FALSE, true);
|
||||
public static final BooleanSetting HIDE_AUDIO_VIDEO_SWITCH_TOGGLE = new BooleanSetting("revanced_hide_audio_video_switch_toggle", FALSE, true);
|
||||
public static final BooleanSetting HIDE_SONG_VIDEO_TOGGLE = new BooleanSetting("revanced_hide_song_video_toggle", FALSE, true);
|
||||
public static final BooleanSetting REMEMBER_REPEAT_SATE = new BooleanSetting("revanced_remember_repeat_state", TRUE);
|
||||
public static final BooleanSetting REMEMBER_SHUFFLE_SATE = new BooleanSetting("revanced_remember_shuffle_state", TRUE);
|
||||
public static final BooleanSetting ALWAYS_SHUFFLE = new BooleanSetting("revanced_always_shuffle", FALSE);
|
||||
|
Reference in New Issue
Block a user