feat(YouTube - Miniplayer): Add option to disable miniplayer (#3961)

Co-authored-by: oSumAtrIX <johan.melkonyan1@web.de>
This commit is contained in:
LisoUseInAIKyrios 2024-11-22 20:37:35 +04:00 committed by GitHub
parent 71af1f86e8
commit e565cdb583
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
6 changed files with 109 additions and 63 deletions

View File

@ -24,9 +24,20 @@ public final class MiniplayerPatch {
* Mini player type. Null fields indicates to use the original un-patched value. * Mini player type. Null fields indicates to use the original un-patched value.
*/ */
public enum MiniplayerType { 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. */ /** Unmodified type, and same as un-patched. */
ORIGINAL(null, null), 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), PHONE(false, null),
MINIMAL(false, null),
TABLET(true, null), TABLET(true, null),
MODERN_1(null, 1), MODERN_1(null, 1),
MODERN_2(null, 2), MODERN_2(null, 2),
@ -164,6 +175,18 @@ public final class MiniplayerPatch {
OPACITY_LEVEL = (opacity * 255) / 100; 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. * Injection point.
*/ */

View File

@ -375,15 +375,20 @@ public class Settings extends BaseSettings {
migrateOldSettingToNew(DEPRECATED_SB_UUID_OLD_MIGRATION_SETTING, SB_PRIVATE_USER_ID); 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. // Old spoof versions that no longer work reliably.
if (SpoofAppVersionPatch.isSpoofingToLessThan(SPOOF_APP_VERSION_TARGET.defaultValue)) { if (SpoofAppVersionPatch.isSpoofingToLessThan(SPOOF_APP_VERSION_TARGET.defaultValue)) {
Logger.printInfo(() -> "Resetting spoof app version target"); Logger.printInfo(() -> "Resetting spoof app version target");
SPOOF_APP_VERSION_TARGET.resetToDefault(); SPOOF_APP_VERSION_TARGET.resetToDefault();
} }
migrateOldSettingToNew(DEPRECATED_HIDE_PLAYER_BUTTONS, HIDE_PLAYER_PREVIOUS_NEXT_BUTTONS); // Migrate renamed enum type.
if (MINIPLAYER_TYPE.get() == PHONE) {
migrateOldSettingToNew(DEPRECATED_HIDE_PLAYER_FLYOUT_VIDEO_QUALITY_FOOTER, HIDE_PLAYER_FLYOUT_VIDEO_QUALITY_FOOTER); MINIPLAYER_TYPE.save(MINIMAL);
}
// endregion // endregion
} }

View File

@ -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_HORIZONTAL_DRAG_FEATURE_KEY = 45658112L
internal const val MINIPLAYER_ROUNDED_CORNERS_FEATURE_KEY = 45652224L internal const val MINIPLAYER_ROUNDED_CORNERS_FEATURE_KEY = 45652224L
internal const val MINIPLAYER_INITIAL_SIZE_FEATURE_KEY = 45640023L internal const val MINIPLAYER_INITIAL_SIZE_FEATURE_KEY = 45640023L
internal const val MINIPLAYER_DISABLED_FEATURE_KEY = 45657015L
internal val miniplayerModernConstructorFingerprint = fingerprint { internal val miniplayerModernConstructorFingerprint = fingerprint {
accessFlags(AccessFlags.PUBLIC, AccessFlags.CONSTRUCTOR) accessFlags(AccessFlags.PUBLIC, AccessFlags.CONSTRUCTOR)
@ -50,6 +51,12 @@ internal val miniplayerModernConstructorFingerprint = fingerprint {
literal { 45623000L } 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]. * Matches using the class found in [miniplayerModernViewParentFingerprint].
*/ */

View File

@ -147,8 +147,7 @@ val miniplayerPatch = bytecodePatch(
compatibleWith( compatibleWith(
"com.google.android.youtube"( "com.google.android.youtube"(
"18.38.44", // 18.49.37 // Could be supported, but no reason when 19.16 exists and has modern types.
"18.49.37",
// 19.14.43 // Incomplete code for modern miniplayers. // 19.14.43 // Incomplete code for modern miniplayers.
// 19.15.36 // Different code for handling subtitle texts and not worth supporting. // 19.15.36 // Different code for handling subtitle texts and not worth supporting.
"19.16.39", // First with modern miniplayers. "19.16.39", // First with modern miniplayers.
@ -179,18 +178,21 @@ val miniplayerPatch = bytecodePatch(
val preferences = mutableSetOf<BasePreference>() val preferences = mutableSetOf<BasePreference>()
if (!is_19_16_or_greater) {
preferences += ListPreference( preferences +=
if (is_19_43_or_greater) {
ListPreference(
"revanced_miniplayer_type",
summaryKey = null,
)
} else {
ListPreference(
"revanced_miniplayer_type", "revanced_miniplayer_type",
summaryKey = null, summaryKey = null,
entriesKey = "revanced_miniplayer_type_legacy_entries", entriesKey = "revanced_miniplayer_type_legacy_entries",
entryValuesKey = "revanced_miniplayer_type_legacy_entry_values", entryValuesKey = "revanced_miniplayer_type_legacy_entry_values",
) )
} else { }
preferences += ListPreference(
"revanced_miniplayer_type",
summaryKey = null,
)
if (is_19_25_or_greater) { if (is_19_25_or_greater) {
if (!is_19_29_or_greater) { if (!is_19_29_or_greater) {
@ -229,7 +231,6 @@ val miniplayerPatch = bytecodePatch(
} }
preferences += TextPreference("revanced_miniplayer_opacity", inputType = InputType.NUMBER) preferences += TextPreference("revanced_miniplayer_opacity", inputType = InputType.NUMBER)
}
PreferenceScreen.PLAYER.addPreferences( PreferenceScreen.PLAYER.addPreferences(
PreferenceScreenPreference( PreferenceScreenPreference(
@ -350,11 +351,6 @@ val miniplayerPatch = bytecodePatch(
it.method.insertLegacyTabletMiniplayerOverride(it.patternMatch!!.endIndex) 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 // endregion
// region Enable modern miniplayer. // 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) { if (is_19_25_or_greater) {
miniplayerModernConstructorFingerprint.insertLiteralValueBooleanOverride( miniplayerModernConstructorFingerprint.insertLiteralValueBooleanOverride(
MINIPLAYER_MODERN_FEATURE_LEGACY_KEY, 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 // endregion
// region Fix 19.16 using mixed up drawables for tablet modern. // region Fix 19.16 using mixed up drawables for tablet modern.

View File

@ -34,6 +34,7 @@
</patch> </patch>
<patch id="layout.miniplayer.miniplayerPatch"> <patch id="layout.miniplayer.miniplayerPatch">
<string-array name="revanced_miniplayer_type_entries"> <string-array name="revanced_miniplayer_type_entries">
<item>@string/revanced_miniplayer_type_entry_0</item>
<item>@string/revanced_miniplayer_type_entry_1</item> <item>@string/revanced_miniplayer_type_entry_1</item>
<item>@string/revanced_miniplayer_type_entry_2</item> <item>@string/revanced_miniplayer_type_entry_2</item>
<item>@string/revanced_miniplayer_type_entry_3</item> <item>@string/revanced_miniplayer_type_entry_3</item>
@ -43,8 +44,9 @@
</string-array> </string-array>
<string-array name="revanced_miniplayer_type_entry_values"> <string-array name="revanced_miniplayer_type_entry_values">
<!-- Enum names from the extension. --> <!-- Enum names from the extension. -->
<item>DISABLED</item>
<item>ORIGINAL</item> <item>ORIGINAL</item>
<item>PHONE</item> <item>MINIMAL</item>
<item>TABLET</item> <item>TABLET</item>
<item>MODERN_1</item> <item>MODERN_1</item>
<item>MODERN_2</item> <item>MODERN_2</item>
@ -54,11 +56,18 @@
<item>@string/revanced_miniplayer_type_entry_1</item> <item>@string/revanced_miniplayer_type_entry_1</item>
<item>@string/revanced_miniplayer_type_entry_2</item> <item>@string/revanced_miniplayer_type_entry_2</item>
<item>@string/revanced_miniplayer_type_entry_3</item> <item>@string/revanced_miniplayer_type_entry_3</item>
<item>@string/revanced_miniplayer_type_entry_4</item>
<item>@string/revanced_miniplayer_type_entry_5</item>
<item>@string/revanced_miniplayer_type_entry_6</item>
</string-array> </string-array>
<string-array name="revanced_miniplayer_type_legacy_entry_values"> <string-array name="revanced_miniplayer_type_legacy_entry_values">
<!-- Enum names from the extension. -->
<item>ORIGINAL</item> <item>ORIGINAL</item>
<item>PHONE</item> <item>MINIMAL</item>
<item>TABLET</item> <item>TABLET</item>
<item>MODERN_1</item>
<item>MODERN_2</item>
<item>MODERN_3</item>
</string-array> </string-array>
</patch> </patch>
<patch id="layout.startpage.changeStartPagePatch"> <patch id="layout.startpage.changeStartPagePatch">

View File

@ -1021,8 +1021,9 @@ This is because Crowdin requires temporarily flattening this file and removing t
<string name="revanced_miniplayer_screen_title">Miniplayer</string> <string name="revanced_miniplayer_screen_title">Miniplayer</string>
<string name="revanced_miniplayer_screen_summary">Change the style of the in app minimized player</string> <string name="revanced_miniplayer_screen_summary">Change the style of the in app minimized player</string>
<string name="revanced_miniplayer_type_title">Miniplayer type</string> <string name="revanced_miniplayer_type_title">Miniplayer type</string>
<string name="revanced_miniplayer_type_entry_0">Disabled</string>
<string name="revanced_miniplayer_type_entry_1">Original</string> <string name="revanced_miniplayer_type_entry_1">Original</string>
<string name="revanced_miniplayer_type_entry_2">Phone</string> <string name="revanced_miniplayer_type_entry_2">Minimal</string>
<string name="revanced_miniplayer_type_entry_3">Tablet</string> <string name="revanced_miniplayer_type_entry_3">Tablet</string>
<string name="revanced_miniplayer_type_entry_4">Modern 1</string> <string name="revanced_miniplayer_type_entry_4">Modern 1</string>
<string name="revanced_miniplayer_type_entry_5">Modern 2</string> <string name="revanced_miniplayer_type_entry_5">Modern 2</string>