From e565cdb583aacfc0052d12c430f56fd9abd5bf00 Mon Sep 17 00:00:00 2001 From: LisoUseInAIKyrios <118716522+LisoUseInAIKyrios@users.noreply.github.com> Date: Fri, 22 Nov 2024 20:37:35 +0400 Subject: [PATCH] feat(YouTube - Miniplayer): Add option to disable miniplayer (#3961) Co-authored-by: oSumAtrIX --- .../youtube/patches/MiniplayerPatch.java | 23 ++++ .../extension/youtube/settings/Settings.java | 11 +- .../youtube/layout/miniplayer/Fingerprints.kt | 7 ++ .../layout/miniplayer/MiniplayerPatch.kt | 115 +++++++++--------- .../resources/addresources/values/arrays.xml | 13 +- .../resources/addresources/values/strings.xml | 3 +- 6 files changed, 109 insertions(+), 63 deletions(-) diff --git a/extensions/shared/src/main/java/app/revanced/extension/youtube/patches/MiniplayerPatch.java b/extensions/shared/src/main/java/app/revanced/extension/youtube/patches/MiniplayerPatch.java index 33bdf26b2..068aa4d2e 100644 --- a/extensions/shared/src/main/java/app/revanced/extension/youtube/patches/MiniplayerPatch.java +++ b/extensions/shared/src/main/java/app/revanced/extension/youtube/patches/MiniplayerPatch.java @@ -24,9 +24,20 @@ public final class MiniplayerPatch { * Mini player type. Null fields indicates to use the original un-patched value. */ public enum MiniplayerType { + /** + * Disabled. When swiped down the miniplayer is immediately closed. + * Only available with 19.43+ + */ + DISABLED(false, null), /** Unmodified type, and same as un-patched. */ ORIGINAL(null, null), + /** + * Exactly the same as MINIMAL, and only here for migration of user settings. + * Eventually this should be deleted. + */ + @Deprecated PHONE(false, null), + MINIMAL(false, null), TABLET(true, null), MODERN_1(null, 1), MODERN_2(null, 2), @@ -164,6 +175,18 @@ public final class MiniplayerPatch { OPACITY_LEVEL = (opacity * 255) / 100; } + /** + * Injection point. + * + * Enables a handler that immediately closes the miniplayer when the video is minimized, + * effectively disabling the miniplayer. + */ + public static boolean getMiniplayerOnCloseHandler(boolean original) { + return CURRENT_TYPE == ORIGINAL + ? original + : CURRENT_TYPE == DISABLED; + } + /** * Injection point. */ diff --git a/extensions/shared/src/main/java/app/revanced/extension/youtube/settings/Settings.java b/extensions/shared/src/main/java/app/revanced/extension/youtube/settings/Settings.java index 48b4d9903..9b7232368 100644 --- a/extensions/shared/src/main/java/app/revanced/extension/youtube/settings/Settings.java +++ b/extensions/shared/src/main/java/app/revanced/extension/youtube/settings/Settings.java @@ -375,15 +375,20 @@ public class Settings extends BaseSettings { migrateOldSettingToNew(DEPRECATED_SB_UUID_OLD_MIGRATION_SETTING, SB_PRIVATE_USER_ID); + migrateOldSettingToNew(DEPRECATED_HIDE_PLAYER_BUTTONS, HIDE_PLAYER_PREVIOUS_NEXT_BUTTONS); + + migrateOldSettingToNew(DEPRECATED_HIDE_PLAYER_FLYOUT_VIDEO_QUALITY_FOOTER, HIDE_PLAYER_FLYOUT_VIDEO_QUALITY_FOOTER); + // Old spoof versions that no longer work reliably. if (SpoofAppVersionPatch.isSpoofingToLessThan(SPOOF_APP_VERSION_TARGET.defaultValue)) { Logger.printInfo(() -> "Resetting spoof app version target"); SPOOF_APP_VERSION_TARGET.resetToDefault(); } - migrateOldSettingToNew(DEPRECATED_HIDE_PLAYER_BUTTONS, HIDE_PLAYER_PREVIOUS_NEXT_BUTTONS); - - migrateOldSettingToNew(DEPRECATED_HIDE_PLAYER_FLYOUT_VIDEO_QUALITY_FOOTER, HIDE_PLAYER_FLYOUT_VIDEO_QUALITY_FOOTER); + // Migrate renamed enum type. + if (MINIPLAYER_TYPE.get() == PHONE) { + MINIPLAYER_TYPE.save(MINIMAL); + } // endregion } diff --git a/patches/src/main/kotlin/app/revanced/patches/youtube/layout/miniplayer/Fingerprints.kt b/patches/src/main/kotlin/app/revanced/patches/youtube/layout/miniplayer/Fingerprints.kt index 125f043a3..5a2f47239 100644 --- a/patches/src/main/kotlin/app/revanced/patches/youtube/layout/miniplayer/Fingerprints.kt +++ b/patches/src/main/kotlin/app/revanced/patches/youtube/layout/miniplayer/Fingerprints.kt @@ -43,6 +43,7 @@ internal const val MINIPLAYER_DRAG_DROP_FEATURE_KEY = 45628752L internal const val MINIPLAYER_HORIZONTAL_DRAG_FEATURE_KEY = 45658112L internal const val MINIPLAYER_ROUNDED_CORNERS_FEATURE_KEY = 45652224L internal const val MINIPLAYER_INITIAL_SIZE_FEATURE_KEY = 45640023L +internal const val MINIPLAYER_DISABLED_FEATURE_KEY = 45657015L internal val miniplayerModernConstructorFingerprint = fingerprint { accessFlags(AccessFlags.PUBLIC, AccessFlags.CONSTRUCTOR) @@ -50,6 +51,12 @@ internal val miniplayerModernConstructorFingerprint = fingerprint { literal { 45623000L } } +internal val miniplayerOnCloseHandlerFingerprint = fingerprint { + accessFlags(AccessFlags.PUBLIC, AccessFlags.FINAL) + returns("Z") + literal { MINIPLAYER_DISABLED_FEATURE_KEY } +} + /** * Matches using the class found in [miniplayerModernViewParentFingerprint]. */ diff --git a/patches/src/main/kotlin/app/revanced/patches/youtube/layout/miniplayer/MiniplayerPatch.kt b/patches/src/main/kotlin/app/revanced/patches/youtube/layout/miniplayer/MiniplayerPatch.kt index 61d5fcc06..cd5610096 100644 --- a/patches/src/main/kotlin/app/revanced/patches/youtube/layout/miniplayer/MiniplayerPatch.kt +++ b/patches/src/main/kotlin/app/revanced/patches/youtube/layout/miniplayer/MiniplayerPatch.kt @@ -147,8 +147,7 @@ val miniplayerPatch = bytecodePatch( compatibleWith( "com.google.android.youtube"( - "18.38.44", - "18.49.37", + // 18.49.37 // Could be supported, but no reason when 19.16 exists and has modern types. // 19.14.43 // Incomplete code for modern miniplayers. // 19.15.36 // Different code for handling subtitle texts and not worth supporting. "19.16.39", // First with modern miniplayers. @@ -179,58 +178,60 @@ val miniplayerPatch = bytecodePatch( val preferences = mutableSetOf() - if (!is_19_16_or_greater) { - preferences += ListPreference( - "revanced_miniplayer_type", - summaryKey = null, - entriesKey = "revanced_miniplayer_type_legacy_entries", - entryValuesKey = "revanced_miniplayer_type_legacy_entry_values", - ) - } else { - preferences += ListPreference( - "revanced_miniplayer_type", - summaryKey = null, - ) - - if (is_19_25_or_greater) { - if (!is_19_29_or_greater) { - preferences += SwitchPreference("revanced_miniplayer_double_tap_action") - } - preferences += SwitchPreference("revanced_miniplayer_drag_and_drop") - } + preferences += if (is_19_43_or_greater) { - preferences += SwitchPreference("revanced_miniplayer_horizontal_drag") - } - - if (is_19_36_or_greater) { - preferences += SwitchPreference("revanced_miniplayer_rounded_corners") - } - - preferences += SwitchPreference("revanced_miniplayer_hide_subtext") - - preferences += if (is_19_26_or_greater) { - SwitchPreference("revanced_miniplayer_hide_expand_close") + ListPreference( + "revanced_miniplayer_type", + summaryKey = null, + ) } else { - SwitchPreference( - key = "revanced_miniplayer_hide_expand_close", - titleKey = "revanced_miniplayer_hide_expand_close_legacy_title", - summaryOnKey = "revanced_miniplayer_hide_expand_close_legacy_summary_on", - summaryOffKey = "revanced_miniplayer_hide_expand_close_legacy_summary_off", + ListPreference( + "revanced_miniplayer_type", + summaryKey = null, + entriesKey = "revanced_miniplayer_type_legacy_entries", + entryValuesKey = "revanced_miniplayer_type_legacy_entry_values", ) } - if (!is_19_26_or_greater) { - preferences += SwitchPreference("revanced_miniplayer_hide_rewind_forward") + if (is_19_25_or_greater) { + if (!is_19_29_or_greater) { + preferences += SwitchPreference("revanced_miniplayer_double_tap_action") } - - if (is_19_26_or_greater) { - preferences += TextPreference("revanced_miniplayer_width_dip", inputType = InputType.NUMBER) - } - - preferences += TextPreference("revanced_miniplayer_opacity", inputType = InputType.NUMBER) + preferences += SwitchPreference("revanced_miniplayer_drag_and_drop") } + if (is_19_43_or_greater) { + preferences += SwitchPreference("revanced_miniplayer_horizontal_drag") + } + + if (is_19_36_or_greater) { + preferences += SwitchPreference("revanced_miniplayer_rounded_corners") + } + + preferences += SwitchPreference("revanced_miniplayer_hide_subtext") + + preferences += if (is_19_26_or_greater) { + SwitchPreference("revanced_miniplayer_hide_expand_close") + } else { + SwitchPreference( + key = "revanced_miniplayer_hide_expand_close", + titleKey = "revanced_miniplayer_hide_expand_close_legacy_title", + summaryOnKey = "revanced_miniplayer_hide_expand_close_legacy_summary_on", + summaryOffKey = "revanced_miniplayer_hide_expand_close_legacy_summary_off", + ) + } + + if (!is_19_26_or_greater) { + preferences += SwitchPreference("revanced_miniplayer_hide_rewind_forward") + } + + if (is_19_26_or_greater) { + preferences += TextPreference("revanced_miniplayer_width_dip", inputType = InputType.NUMBER) + } + + preferences += TextPreference("revanced_miniplayer_opacity", inputType = InputType.NUMBER) + PreferenceScreen.PLAYER.addPreferences( PreferenceScreenPreference( key = "revanced_miniplayer_screen", @@ -350,11 +351,6 @@ val miniplayerPatch = bytecodePatch( it.method.insertLegacyTabletMiniplayerOverride(it.patternMatch!!.endIndex) } - if (!is_19_16_or_greater) { - // Return here, as patch below is only for the current versions of the app. - return@execute - } - // endregion // region Enable modern miniplayer. @@ -380,13 +376,6 @@ val miniplayerPatch = bytecodePatch( ) } - if (is_19_43_or_greater) { - miniplayerModernConstructorFingerprint.insertLiteralValueBooleanOverride( - MINIPLAYER_HORIZONTAL_DRAG_FEATURE_KEY, - "setHorizontalDrag", - ) - } - if (is_19_25_or_greater) { miniplayerModernConstructorFingerprint.insertLiteralValueBooleanOverride( MINIPLAYER_MODERN_FEATURE_LEGACY_KEY, @@ -443,6 +432,18 @@ val miniplayerPatch = bytecodePatch( ) } + if (is_19_43_or_greater) { + miniplayerOnCloseHandlerFingerprint.insertLiteralValueBooleanOverride( + MINIPLAYER_DISABLED_FEATURE_KEY, + "getMiniplayerOnCloseHandler" + ) + + miniplayerModernConstructorFingerprint.insertLiteralValueBooleanOverride( + MINIPLAYER_HORIZONTAL_DRAG_FEATURE_KEY, + "setHorizontalDrag", + ) + } + // endregion // region Fix 19.16 using mixed up drawables for tablet modern. diff --git a/patches/src/main/resources/addresources/values/arrays.xml b/patches/src/main/resources/addresources/values/arrays.xml index 6df8ea926..7dbc76b2c 100644 --- a/patches/src/main/resources/addresources/values/arrays.xml +++ b/patches/src/main/resources/addresources/values/arrays.xml @@ -34,6 +34,7 @@ + @string/revanced_miniplayer_type_entry_0 @string/revanced_miniplayer_type_entry_1 @string/revanced_miniplayer_type_entry_2 @string/revanced_miniplayer_type_entry_3 @@ -43,8 +44,9 @@ + DISABLED ORIGINAL - PHONE + MINIMAL TABLET MODERN_1 MODERN_2 @@ -54,11 +56,18 @@ @string/revanced_miniplayer_type_entry_1 @string/revanced_miniplayer_type_entry_2 @string/revanced_miniplayer_type_entry_3 + @string/revanced_miniplayer_type_entry_4 + @string/revanced_miniplayer_type_entry_5 + @string/revanced_miniplayer_type_entry_6 + ORIGINAL - PHONE + MINIMAL TABLET + MODERN_1 + MODERN_2 + MODERN_3 diff --git a/patches/src/main/resources/addresources/values/strings.xml b/patches/src/main/resources/addresources/values/strings.xml index 34c145280..86fb2405c 100644 --- a/patches/src/main/resources/addresources/values/strings.xml +++ b/patches/src/main/resources/addresources/values/strings.xml @@ -1021,8 +1021,9 @@ This is because Crowdin requires temporarily flattening this file and removing t Miniplayer Change the style of the in app minimized player Miniplayer type + Disabled Original - Phone + Minimal Tablet Modern 1 Modern 2