From a03ed95af6ff6b66a44f7321576404bf45ac1466 Mon Sep 17 00:00:00 2001 From: inotia00 <108592928+inotia00@users.noreply.github.com> Date: Sun, 7 Apr 2024 16:08:07 +0900 Subject: [PATCH] feat(YouTube Music/Settings): move SponsorBlock settings and Return YouTube Dislike settings to RVX Settings --- .../account/component/MenuComponentPatch.kt | 6 +- .../music/account/handle/HandlePatch.kt | 2 +- .../music/account/tos/TermsContainerPatch.kt | 2 +- .../component/ActionBarComponentPatch.kt | 18 +- .../music/ads/general/GeneralAdsPatch.kt | 12 +- .../compactdialog/CompactDialogPatch.kt | 2 +- .../flyoutpanel/component/FlyoutPanelPatch.kt | 137 +++++---- .../replace/ReplaceDismissQueuePatch.kt | 4 +- .../flyoutpanel/replace/ReplaceReportPatch.kt | 4 +- .../general/autocaptions/AutoCaptionsPatch.kt | 2 +- .../general/buttonshelf/ButtonShelfPatch.kt | 2 +- .../carouselshelf/CarouselShelfPatch.kt | 2 +- .../general/castbutton/CastButtonPatch.kt | 2 +- .../general/categorybar/CategoryBarPatch.kt | 2 +- .../ChannelGuidelinesPatch.kt | 2 +- .../general/customfilter/CustomFilterPatch.kt | 4 +- .../dialog/ViewerDiscretionDialogPatch.kt | 2 +- .../general/emojipicker/EmojiPickerPatch.kt | 2 +- .../floatingbutton/FloatingButtonPatch.kt | 2 +- .../historybutton/HistoryButtonPatch.kt | 2 +- .../landscapemode/LandScapeModePatch.kt | 2 +- .../OldStyleLibraryShelfPatch.kt | 2 +- .../general/playlistcard/PlaylistCardPatch.kt | 2 +- .../redirection/DislikeRedirectionPatch.kt | 2 +- .../general/sampleshelf/SampleShelfPatch.kt | 2 +- .../general/startpage/ChangeStartPagePatch.kt | 2 +- .../taptoupdate/TapToUpdateButtonPatch.kt | 2 +- .../music/misc/codecs/ForceOpusCodecPatch.kt | 2 +- .../music/misc/debugging/DebuggingPatch.kt | 4 +- .../spoofappversion/SpoofAppVersionPatch.kt | 4 +- .../misc/tracking/SanitizeUrlQueryPatch.kt | 2 +- .../black/BlackNavigationBarPatch.kt | 2 +- .../component/NavigationBarComponentPatch.kt | 14 +- .../colormatchplayer/ColorMatchPlayerPatch.kt | 2 +- .../minimizedplayer/MinimizedPlayerPatch.kt | 2 +- .../nextprevious/MiniPlayerButtonPatch.kt | 4 +- .../OldPlayerBackgroundPatch.kt | 2 +- .../oldplayerlayout/OldPlayerLayoutPatch.kt | 2 +- .../player/repeat/RememberRepeatPatch.kt | 2 +- .../player/replace/ReplaceCastButtonPatch.kt | 2 +- .../music/player/share/ShareButtonPatch.kt | 2 +- .../player/shuffle/RememberShufflePatch.kt | 2 +- .../SwipeToDismissMiniPlayerPatch.kt | 2 +- .../music/player/zenmode/ZenModePatch.kt | 4 +- .../ReturnYouTubeDislikePatch.kt | 111 +++----- .../music/utils/settings/CategoryType.kt | 2 + .../music/utils/settings/ResourceUtils.kt | 192 +++++-------- .../music/utils/settings/SettingsPatch.kt | 66 +++-- .../utils/sponsorblock/SponsorBlockPatch.kt | 266 +++++++++++++++--- .../customspeed/CustomPlaybackSpeedPatch.kt | 2 +- .../music/video/quality/VideoQualityPatch.kt | 2 +- .../music/video/speed/PlaybackSpeedPatch.kt | 2 +- 52 files changed, 531 insertions(+), 391 deletions(-) diff --git a/src/main/kotlin/app/revanced/patches/music/account/component/MenuComponentPatch.kt b/src/main/kotlin/app/revanced/patches/music/account/component/MenuComponentPatch.kt index aca17623c..740d0d4ff 100644 --- a/src/main/kotlin/app/revanced/patches/music/account/component/MenuComponentPatch.kt +++ b/src/main/kotlin/app/revanced/patches/music/account/component/MenuComponentPatch.kt @@ -42,17 +42,17 @@ object MenuComponentPatch : BaseBytecodePatch( } } - SettingsPatch.addMusicPreference( + SettingsPatch.addSwitchPreference( CategoryType.ACCOUNT, "revanced_hide_account_menu", "false" ) - SettingsPatch.addMusicPreferenceWithIntent( + SettingsPatch.addPreferenceWithIntent( CategoryType.ACCOUNT, "revanced_hide_account_menu_filter_strings", "revanced_hide_account_menu" ) - SettingsPatch.addMusicPreference( + SettingsPatch.addSwitchPreference( CategoryType.ACCOUNT, "revanced_hide_account_menu_empty_component", "false", diff --git a/src/main/kotlin/app/revanced/patches/music/account/handle/HandlePatch.kt b/src/main/kotlin/app/revanced/patches/music/account/handle/HandlePatch.kt index d8908d71b..ce3447d12 100644 --- a/src/main/kotlin/app/revanced/patches/music/account/handle/HandlePatch.kt +++ b/src/main/kotlin/app/revanced/patches/music/account/handle/HandlePatch.kt @@ -67,7 +67,7 @@ object HandlePatch : BaseBytecodePatch( } } - SettingsPatch.addMusicPreference( + SettingsPatch.addSwitchPreference( CategoryType.ACCOUNT, "revanced_hide_handle", "true" diff --git a/src/main/kotlin/app/revanced/patches/music/account/tos/TermsContainerPatch.kt b/src/main/kotlin/app/revanced/patches/music/account/tos/TermsContainerPatch.kt index 3d220d071..f16b9b991 100644 --- a/src/main/kotlin/app/revanced/patches/music/account/tos/TermsContainerPatch.kt +++ b/src/main/kotlin/app/revanced/patches/music/account/tos/TermsContainerPatch.kt @@ -47,7 +47,7 @@ object TermsContainerPatch : BaseBytecodePatch( } } - SettingsPatch.addMusicPreference( + SettingsPatch.addSwitchPreference( CategoryType.ACCOUNT, "revanced_hide_terms_container", "false" diff --git a/src/main/kotlin/app/revanced/patches/music/actionbar/component/ActionBarComponentPatch.kt b/src/main/kotlin/app/revanced/patches/music/actionbar/component/ActionBarComponentPatch.kt index cd9cca076..c0b2356b7 100644 --- a/src/main/kotlin/app/revanced/patches/music/actionbar/component/ActionBarComponentPatch.kt +++ b/src/main/kotlin/app/revanced/patches/music/actionbar/component/ActionBarComponentPatch.kt @@ -153,47 +153,47 @@ object ActionBarComponentPatch : BaseBytecodePatch( } } - SettingsPatch.addMusicPreference( + SettingsPatch.addSwitchPreference( CategoryType.ACTION_BAR, "revanced_hide_action_button_add_to_playlist", "false" ) - SettingsPatch.addMusicPreference( + SettingsPatch.addSwitchPreference( CategoryType.ACTION_BAR, "revanced_hide_action_button_comment", "false" ) - SettingsPatch.addMusicPreference( + SettingsPatch.addSwitchPreference( CategoryType.ACTION_BAR, "revanced_hide_action_button_download", "false" ) - SettingsPatch.addMusicPreference( + SettingsPatch.addSwitchPreference( CategoryType.ACTION_BAR, "revanced_hide_action_button_label", "false" ) - SettingsPatch.addMusicPreference( + SettingsPatch.addSwitchPreference( CategoryType.ACTION_BAR, "revanced_hide_action_button_like_dislike", "false" ) - SettingsPatch.addMusicPreference( + SettingsPatch.addSwitchPreference( CategoryType.ACTION_BAR, "revanced_hide_action_button_radio", "false" ) - SettingsPatch.addMusicPreference( + SettingsPatch.addSwitchPreference( CategoryType.ACTION_BAR, "revanced_hide_action_button_share", "false" ) - SettingsPatch.addMusicPreference( + SettingsPatch.addSwitchPreference( CategoryType.ACTION_BAR, "revanced_hook_action_button_download", "false" ) - SettingsPatch.addMusicPreferenceWithIntent( + SettingsPatch.addPreferenceWithIntent( CategoryType.ACTION_BAR, "revanced_external_downloader_package_name", "revanced_hook_action_button_download" diff --git a/src/main/kotlin/app/revanced/patches/music/ads/general/GeneralAdsPatch.kt b/src/main/kotlin/app/revanced/patches/music/ads/general/GeneralAdsPatch.kt index 5b86c9750..cdf45aa31 100644 --- a/src/main/kotlin/app/revanced/patches/music/ads/general/GeneralAdsPatch.kt +++ b/src/main/kotlin/app/revanced/patches/music/ads/general/GeneralAdsPatch.kt @@ -158,32 +158,32 @@ object GeneralAdsPatch : BaseBytecodePatch( } } - SettingsPatch.addMusicPreference( + SettingsPatch.addSwitchPreference( CategoryType.ADS, "revanced_hide_fullscreen_ads", "true" ) - SettingsPatch.addMusicPreference( + SettingsPatch.addSwitchPreference( CategoryType.ADS, "revanced_hide_general_ads", "true" ) - SettingsPatch.addMusicPreference( + SettingsPatch.addSwitchPreference( CategoryType.ADS, "revanced_hide_music_ads", "true" ) - SettingsPatch.addMusicPreference( + SettingsPatch.addSwitchPreference( CategoryType.ADS, "revanced_hide_paid_promotion", "true" ) - SettingsPatch.addMusicPreference( + SettingsPatch.addSwitchPreference( CategoryType.ADS, "revanced_hide_premium_promotion", "true" ) - SettingsPatch.addMusicPreference( + SettingsPatch.addSwitchPreference( CategoryType.ADS, "revanced_hide_premium_renewal", "true" diff --git a/src/main/kotlin/app/revanced/patches/music/flyoutpanel/compactdialog/CompactDialogPatch.kt b/src/main/kotlin/app/revanced/patches/music/flyoutpanel/compactdialog/CompactDialogPatch.kt index 0500817d9..f8fa1eacb 100644 --- a/src/main/kotlin/app/revanced/patches/music/flyoutpanel/compactdialog/CompactDialogPatch.kt +++ b/src/main/kotlin/app/revanced/patches/music/flyoutpanel/compactdialog/CompactDialogPatch.kt @@ -34,7 +34,7 @@ object CompactDialogPatch : BaseBytecodePatch( ) } - SettingsPatch.addMusicPreference( + SettingsPatch.addSwitchPreference( CategoryType.FLYOUT, "revanced_enable_compact_dialog", "true" diff --git a/src/main/kotlin/app/revanced/patches/music/flyoutpanel/component/FlyoutPanelPatch.kt b/src/main/kotlin/app/revanced/patches/music/flyoutpanel/component/FlyoutPanelPatch.kt index 20ea0fd22..93dad9372 100644 --- a/src/main/kotlin/app/revanced/patches/music/flyoutpanel/component/FlyoutPanelPatch.kt +++ b/src/main/kotlin/app/revanced/patches/music/flyoutpanel/component/FlyoutPanelPatch.kt @@ -75,147 +75,174 @@ object FlyoutPanelPatch : BaseBytecodePatch( if (SettingsPatch.upward0636) { LithoFilterPatch.addFilter(FILTER_CLASS_DESCRIPTOR) - SettingsPatch.addMusicPreference( + SettingsPatch.addSwitchPreference( CategoryType.FLYOUT, "revanced_hide_flyout_panel_3_column_component", "false" ) } - SettingsPatch.addMusicPreferenceWithoutSummary( + SettingsPatch.addSwitchPreference( CategoryType.FLYOUT, "revanced_hide_flyout_panel_add_to_queue", - "false" + "false", + false ) - SettingsPatch.addMusicPreferenceWithoutSummary( + SettingsPatch.addSwitchPreference( CategoryType.FLYOUT, "revanced_hide_flyout_panel_captions", - "false" + "false", + false ) - SettingsPatch.addMusicPreferenceWithoutSummary( + SettingsPatch.addSwitchPreference( CategoryType.FLYOUT, "revanced_hide_flyout_panel_delete_playlist", - "false" + "false", + false ) - SettingsPatch.addMusicPreferenceWithoutSummary( + SettingsPatch.addSwitchPreference( CategoryType.FLYOUT, "revanced_hide_flyout_panel_dismiss_queue", - "false" + "false", + false ) - SettingsPatch.addMusicPreferenceWithoutSummary( + SettingsPatch.addSwitchPreference( CategoryType.FLYOUT, "revanced_hide_flyout_panel_download", - "false" + "false", + false ) - SettingsPatch.addMusicPreferenceWithoutSummary( + SettingsPatch.addSwitchPreference( CategoryType.FLYOUT, "revanced_hide_flyout_panel_edit_playlist", - "false" + "false", + false ) - SettingsPatch.addMusicPreferenceWithoutSummary( + SettingsPatch.addSwitchPreference( CategoryType.FLYOUT, "revanced_hide_flyout_panel_go_to_album", - "false" + "false", + false ) - SettingsPatch.addMusicPreferenceWithoutSummary( + SettingsPatch.addSwitchPreference( CategoryType.FLYOUT, "revanced_hide_flyout_panel_go_to_artist", - "false" + "false", + false ) - SettingsPatch.addMusicPreferenceWithoutSummary( + SettingsPatch.addSwitchPreference( CategoryType.FLYOUT, "revanced_hide_flyout_panel_go_to_episode", - "false" + "false", + false ) - SettingsPatch.addMusicPreferenceWithoutSummary( + SettingsPatch.addSwitchPreference( CategoryType.FLYOUT, "revanced_hide_flyout_panel_go_to_podcast", - "false" + "false", + false ) - SettingsPatch.addMusicPreferenceWithoutSummary( + SettingsPatch.addSwitchPreference( CategoryType.FLYOUT, "revanced_hide_flyout_panel_help", - "false" + "false", + false ) - SettingsPatch.addMusicPreferenceWithoutSummary( + SettingsPatch.addSwitchPreference( CategoryType.FLYOUT, "revanced_hide_flyout_panel_like_dislike", - "false" + "false", + false ) - SettingsPatch.addMusicPreferenceWithoutSummary( + SettingsPatch.addSwitchPreference( CategoryType.FLYOUT, "revanced_hide_flyout_panel_play_next", - "false" + "false", + false ) - SettingsPatch.addMusicPreferenceWithoutSummary( + SettingsPatch.addSwitchPreference( CategoryType.FLYOUT, "revanced_hide_flyout_panel_quality", - "false" + "false", + false ) - SettingsPatch.addMusicPreferenceWithoutSummary( + SettingsPatch.addSwitchPreference( CategoryType.FLYOUT, "revanced_hide_flyout_panel_remove_from_library", - "false" + "false", + false ) - SettingsPatch.addMusicPreferenceWithoutSummary( + SettingsPatch.addSwitchPreference( CategoryType.FLYOUT, "revanced_hide_flyout_panel_remove_from_playlist", - "false" + "false", + false ) - SettingsPatch.addMusicPreferenceWithoutSummary( + SettingsPatch.addSwitchPreference( CategoryType.FLYOUT, "revanced_hide_flyout_panel_report", - "false" + "false", + false ) - SettingsPatch.addMusicPreferenceWithoutSummary( + SettingsPatch.addSwitchPreference( CategoryType.FLYOUT, "revanced_hide_flyout_panel_save_episode_for_later", - "false" + "false", + false ) - SettingsPatch.addMusicPreferenceWithoutSummary( + SettingsPatch.addSwitchPreference( CategoryType.FLYOUT, "revanced_hide_flyout_panel_save_to_library", - "false" + "false", + false ) - SettingsPatch.addMusicPreferenceWithoutSummary( + SettingsPatch.addSwitchPreference( CategoryType.FLYOUT, "revanced_hide_flyout_panel_save_to_playlist", - "false" + "false", + false ) - SettingsPatch.addMusicPreferenceWithoutSummary( + SettingsPatch.addSwitchPreference( CategoryType.FLYOUT, "revanced_hide_flyout_panel_share", - "false" + "false", + false ) - SettingsPatch.addMusicPreferenceWithoutSummary( + SettingsPatch.addSwitchPreference( CategoryType.FLYOUT, "revanced_hide_flyout_panel_shuffle_play", - "false" + "false", + false ) - SettingsPatch.addMusicPreferenceWithoutSummary( + SettingsPatch.addSwitchPreference( CategoryType.FLYOUT, "revanced_hide_flyout_panel_sleep_timer", - "false" + "false", + false ) - SettingsPatch.addMusicPreferenceWithoutSummary( + SettingsPatch.addSwitchPreference( CategoryType.FLYOUT, "revanced_hide_flyout_panel_start_radio", - "false" + "false", + false ) - SettingsPatch.addMusicPreferenceWithoutSummary( + SettingsPatch.addSwitchPreference( CategoryType.FLYOUT, "revanced_hide_flyout_panel_stats_for_nerds", - "false" + "false", + false ) - SettingsPatch.addMusicPreferenceWithoutSummary( + SettingsPatch.addSwitchPreference( CategoryType.FLYOUT, "revanced_hide_flyout_panel_subscribe", - "false" + "false", + false ) - SettingsPatch.addMusicPreferenceWithoutSummary( + SettingsPatch.addSwitchPreference( CategoryType.FLYOUT, "revanced_hide_flyout_panel_view_song_credit", - "false" + "false", + false ) } } diff --git a/src/main/kotlin/app/revanced/patches/music/flyoutpanel/replace/ReplaceDismissQueuePatch.kt b/src/main/kotlin/app/revanced/patches/music/flyoutpanel/replace/ReplaceDismissQueuePatch.kt index d5bbbe553..ab262b7e8 100644 --- a/src/main/kotlin/app/revanced/patches/music/flyoutpanel/replace/ReplaceDismissQueuePatch.kt +++ b/src/main/kotlin/app/revanced/patches/music/flyoutpanel/replace/ReplaceDismissQueuePatch.kt @@ -22,12 +22,12 @@ object ReplaceDismissQueuePatch : BaseBytecodePatch( override fun execute(context: BytecodeContext) { FlyoutPanelMenuItemPatch.replaceComponents() - SettingsPatch.addMusicPreference( + SettingsPatch.addSwitchPreference( CategoryType.FLYOUT, "revanced_replace_flyout_panel_dismiss_queue", "false" ) - SettingsPatch.addMusicPreference( + SettingsPatch.addSwitchPreference( CategoryType.FLYOUT, "revanced_replace_flyout_panel_dismiss_queue_continue_watch", "true", diff --git a/src/main/kotlin/app/revanced/patches/music/flyoutpanel/replace/ReplaceReportPatch.kt b/src/main/kotlin/app/revanced/patches/music/flyoutpanel/replace/ReplaceReportPatch.kt index 664996873..a017fd1e4 100644 --- a/src/main/kotlin/app/revanced/patches/music/flyoutpanel/replace/ReplaceReportPatch.kt +++ b/src/main/kotlin/app/revanced/patches/music/flyoutpanel/replace/ReplaceReportPatch.kt @@ -45,12 +45,12 @@ object ReplaceReportPatch : BaseBytecodePatch( } } - SettingsPatch.addMusicPreference( + SettingsPatch.addSwitchPreference( CategoryType.FLYOUT, "revanced_replace_flyout_panel_report", "true" ) - SettingsPatch.addMusicPreference( + SettingsPatch.addSwitchPreference( CategoryType.FLYOUT, "revanced_replace_flyout_panel_report_only_player", "true", diff --git a/src/main/kotlin/app/revanced/patches/music/general/autocaptions/AutoCaptionsPatch.kt b/src/main/kotlin/app/revanced/patches/music/general/autocaptions/AutoCaptionsPatch.kt index 2df5c1eb5..5e813a22a 100644 --- a/src/main/kotlin/app/revanced/patches/music/general/autocaptions/AutoCaptionsPatch.kt +++ b/src/main/kotlin/app/revanced/patches/music/general/autocaptions/AutoCaptionsPatch.kt @@ -23,7 +23,7 @@ object AutoCaptionsPatch : BaseResourcePatch( VideoIdPatch.hookBackgroundPlayVideoId("$GENERAL_CLASS_DESCRIPTOR->newVideoStarted(Ljava/lang/String;)V") - SettingsPatch.addMusicPreference( + SettingsPatch.addSwitchPreference( CategoryType.GENERAL, "revanced_disable_auto_captions", "false" diff --git a/src/main/kotlin/app/revanced/patches/music/general/buttonshelf/ButtonShelfPatch.kt b/src/main/kotlin/app/revanced/patches/music/general/buttonshelf/ButtonShelfPatch.kt index b705ae4fc..f86ea45c2 100644 --- a/src/main/kotlin/app/revanced/patches/music/general/buttonshelf/ButtonShelfPatch.kt +++ b/src/main/kotlin/app/revanced/patches/music/general/buttonshelf/ButtonShelfPatch.kt @@ -24,7 +24,7 @@ object ButtonShelfPatch : BaseResourcePatch( override fun execute(context: ResourceContext) { LithoFilterPatch.addFilter(FILTER_CLASS_DESCRIPTOR) - SettingsPatch.addMusicPreference( + SettingsPatch.addSwitchPreference( CategoryType.GENERAL, "revanced_hide_button_shelf", "false" diff --git a/src/main/kotlin/app/revanced/patches/music/general/carouselshelf/CarouselShelfPatch.kt b/src/main/kotlin/app/revanced/patches/music/general/carouselshelf/CarouselShelfPatch.kt index ffb2fd00d..765ab0d87 100644 --- a/src/main/kotlin/app/revanced/patches/music/general/carouselshelf/CarouselShelfPatch.kt +++ b/src/main/kotlin/app/revanced/patches/music/general/carouselshelf/CarouselShelfPatch.kt @@ -24,7 +24,7 @@ object CarouselShelfPatch : BaseResourcePatch( override fun execute(context: ResourceContext) { LithoFilterPatch.addFilter(FILTER_CLASS_DESCRIPTOR) - SettingsPatch.addMusicPreference( + SettingsPatch.addSwitchPreference( CategoryType.GENERAL, "revanced_hide_carousel_shelf", "false" diff --git a/src/main/kotlin/app/revanced/patches/music/general/castbutton/CastButtonPatch.kt b/src/main/kotlin/app/revanced/patches/music/general/castbutton/CastButtonPatch.kt index 545586e5a..6598b8922 100644 --- a/src/main/kotlin/app/revanced/patches/music/general/castbutton/CastButtonPatch.kt +++ b/src/main/kotlin/app/revanced/patches/music/general/castbutton/CastButtonPatch.kt @@ -66,7 +66,7 @@ object CastButtonPatch : BaseBytecodePatch( } } - SettingsPatch.addMusicPreference( + SettingsPatch.addSwitchPreference( CategoryType.GENERAL, "revanced_hide_cast_button", "true" diff --git a/src/main/kotlin/app/revanced/patches/music/general/categorybar/CategoryBarPatch.kt b/src/main/kotlin/app/revanced/patches/music/general/categorybar/CategoryBarPatch.kt index 10d78c6da..b33d63acf 100644 --- a/src/main/kotlin/app/revanced/patches/music/general/categorybar/CategoryBarPatch.kt +++ b/src/main/kotlin/app/revanced/patches/music/general/categorybar/CategoryBarPatch.kt @@ -37,7 +37,7 @@ object CategoryBarPatch : BaseBytecodePatch( } } - SettingsPatch.addMusicPreference( + SettingsPatch.addSwitchPreference( CategoryType.GENERAL, "revanced_hide_category_bar", "false" diff --git a/src/main/kotlin/app/revanced/patches/music/general/channelguidelines/ChannelGuidelinesPatch.kt b/src/main/kotlin/app/revanced/patches/music/general/channelguidelines/ChannelGuidelinesPatch.kt index 0cc1824ba..d0ccd1cd8 100644 --- a/src/main/kotlin/app/revanced/patches/music/general/channelguidelines/ChannelGuidelinesPatch.kt +++ b/src/main/kotlin/app/revanced/patches/music/general/channelguidelines/ChannelGuidelinesPatch.kt @@ -24,7 +24,7 @@ object ChannelGuidelinesPatch : BaseResourcePatch( override fun execute(context: ResourceContext) { LithoFilterPatch.addFilter(FILTER_CLASS_DESCRIPTOR) - SettingsPatch.addMusicPreference( + SettingsPatch.addSwitchPreference( CategoryType.GENERAL, "revanced_hide_channel_guidelines", "true" diff --git a/src/main/kotlin/app/revanced/patches/music/general/customfilter/CustomFilterPatch.kt b/src/main/kotlin/app/revanced/patches/music/general/customfilter/CustomFilterPatch.kt index d89f606b3..d155b29a6 100644 --- a/src/main/kotlin/app/revanced/patches/music/general/customfilter/CustomFilterPatch.kt +++ b/src/main/kotlin/app/revanced/patches/music/general/customfilter/CustomFilterPatch.kt @@ -24,12 +24,12 @@ object CustomFilterPatch : BaseResourcePatch( override fun execute(context: ResourceContext) { LithoFilterPatch.addFilter(FILTER_CLASS_DESCRIPTOR) - SettingsPatch.addMusicPreference( + SettingsPatch.addSwitchPreference( CategoryType.GENERAL, "revanced_custom_filter", "false" ) - SettingsPatch.addMusicPreferenceWithIntent( + SettingsPatch.addPreferenceWithIntent( CategoryType.GENERAL, "revanced_custom_filter_strings", "revanced_custom_filter" diff --git a/src/main/kotlin/app/revanced/patches/music/general/dialog/ViewerDiscretionDialogPatch.kt b/src/main/kotlin/app/revanced/patches/music/general/dialog/ViewerDiscretionDialogPatch.kt index b9d6ff5b5..5f7eac53f 100644 --- a/src/main/kotlin/app/revanced/patches/music/general/dialog/ViewerDiscretionDialogPatch.kt +++ b/src/main/kotlin/app/revanced/patches/music/general/dialog/ViewerDiscretionDialogPatch.kt @@ -19,7 +19,7 @@ object ViewerDiscretionDialogPatch : BaseResourcePatch( ) { override fun execute(context: ResourceContext) { - SettingsPatch.addMusicPreference( + SettingsPatch.addSwitchPreference( CategoryType.GENERAL, "revanced_remove_viewer_discretion_dialog", "false" diff --git a/src/main/kotlin/app/revanced/patches/music/general/emojipicker/EmojiPickerPatch.kt b/src/main/kotlin/app/revanced/patches/music/general/emojipicker/EmojiPickerPatch.kt index d29434486..2a1a5fb18 100644 --- a/src/main/kotlin/app/revanced/patches/music/general/emojipicker/EmojiPickerPatch.kt +++ b/src/main/kotlin/app/revanced/patches/music/general/emojipicker/EmojiPickerPatch.kt @@ -24,7 +24,7 @@ object EmojiPickerPatch : BaseResourcePatch( override fun execute(context: ResourceContext) { LithoFilterPatch.addFilter(FILTER_CLASS_DESCRIPTOR) - SettingsPatch.addMusicPreference( + SettingsPatch.addSwitchPreference( CategoryType.GENERAL, "revanced_hide_emoji_picker", "false" diff --git a/src/main/kotlin/app/revanced/patches/music/general/floatingbutton/FloatingButtonPatch.kt b/src/main/kotlin/app/revanced/patches/music/general/floatingbutton/FloatingButtonPatch.kt index 878360f60..efcf003e8 100644 --- a/src/main/kotlin/app/revanced/patches/music/general/floatingbutton/FloatingButtonPatch.kt +++ b/src/main/kotlin/app/revanced/patches/music/general/floatingbutton/FloatingButtonPatch.kt @@ -47,7 +47,7 @@ object FloatingButtonPatch : BaseBytecodePatch( } } - SettingsPatch.addMusicPreference( + SettingsPatch.addSwitchPreference( CategoryType.GENERAL, "revanced_hide_new_playlist_button", "false" diff --git a/src/main/kotlin/app/revanced/patches/music/general/historybutton/HistoryButtonPatch.kt b/src/main/kotlin/app/revanced/patches/music/general/historybutton/HistoryButtonPatch.kt index d0f83e776..5f4efa167 100644 --- a/src/main/kotlin/app/revanced/patches/music/general/historybutton/HistoryButtonPatch.kt +++ b/src/main/kotlin/app/revanced/patches/music/general/historybutton/HistoryButtonPatch.kt @@ -49,7 +49,7 @@ object HistoryButtonPatch : BaseBytecodePatch( } } - SettingsPatch.addMusicPreference( + SettingsPatch.addSwitchPreference( CategoryType.GENERAL, "revanced_hide_history_button", "false" diff --git a/src/main/kotlin/app/revanced/patches/music/general/landscapemode/LandScapeModePatch.kt b/src/main/kotlin/app/revanced/patches/music/general/landscapemode/LandScapeModePatch.kt index 6fb38889b..f8d6ba709 100644 --- a/src/main/kotlin/app/revanced/patches/music/general/landscapemode/LandScapeModePatch.kt +++ b/src/main/kotlin/app/revanced/patches/music/general/landscapemode/LandScapeModePatch.kt @@ -39,7 +39,7 @@ object LandScapeModePatch : BaseBytecodePatch( } } - SettingsPatch.addMusicPreference( + SettingsPatch.addSwitchPreference( CategoryType.GENERAL, "revanced_enable_landscape_mode", "true" diff --git a/src/main/kotlin/app/revanced/patches/music/general/oldstylelibraryshelf/OldStyleLibraryShelfPatch.kt b/src/main/kotlin/app/revanced/patches/music/general/oldstylelibraryshelf/OldStyleLibraryShelfPatch.kt index 56f0c3bc9..bf888d44d 100644 --- a/src/main/kotlin/app/revanced/patches/music/general/oldstylelibraryshelf/OldStyleLibraryShelfPatch.kt +++ b/src/main/kotlin/app/revanced/patches/music/general/oldstylelibraryshelf/OldStyleLibraryShelfPatch.kt @@ -40,7 +40,7 @@ object OldStyleLibraryShelfPatch : BaseBytecodePatch( } } - SettingsPatch.addMusicPreference( + SettingsPatch.addSwitchPreference( CategoryType.GENERAL, "revanced_enable_old_style_library_shelf", "false" diff --git a/src/main/kotlin/app/revanced/patches/music/general/playlistcard/PlaylistCardPatch.kt b/src/main/kotlin/app/revanced/patches/music/general/playlistcard/PlaylistCardPatch.kt index 9852a6f05..8d54dcaf0 100644 --- a/src/main/kotlin/app/revanced/patches/music/general/playlistcard/PlaylistCardPatch.kt +++ b/src/main/kotlin/app/revanced/patches/music/general/playlistcard/PlaylistCardPatch.kt @@ -24,7 +24,7 @@ object PlaylistCardPatch : BaseResourcePatch( override fun execute(context: ResourceContext) { LithoFilterPatch.addFilter(FILTER_CLASS_DESCRIPTOR) - SettingsPatch.addMusicPreference( + SettingsPatch.addSwitchPreference( CategoryType.GENERAL, "revanced_hide_playlist_card", "false" diff --git a/src/main/kotlin/app/revanced/patches/music/general/redirection/DislikeRedirectionPatch.kt b/src/main/kotlin/app/revanced/patches/music/general/redirection/DislikeRedirectionPatch.kt index 644e4ce38..b207f1d82 100644 --- a/src/main/kotlin/app/revanced/patches/music/general/redirection/DislikeRedirectionPatch.kt +++ b/src/main/kotlin/app/revanced/patches/music/general/redirection/DislikeRedirectionPatch.kt @@ -72,7 +72,7 @@ object DislikeRedirectionPatch : BaseBytecodePatch( } } - SettingsPatch.addMusicPreference( + SettingsPatch.addSwitchPreference( CategoryType.GENERAL, "revanced_disable_dislike_redirection", "false" diff --git a/src/main/kotlin/app/revanced/patches/music/general/sampleshelf/SampleShelfPatch.kt b/src/main/kotlin/app/revanced/patches/music/general/sampleshelf/SampleShelfPatch.kt index 405276ff4..fdbee34d1 100644 --- a/src/main/kotlin/app/revanced/patches/music/general/sampleshelf/SampleShelfPatch.kt +++ b/src/main/kotlin/app/revanced/patches/music/general/sampleshelf/SampleShelfPatch.kt @@ -24,7 +24,7 @@ object SampleShelfPatch : BaseResourcePatch( override fun execute(context: ResourceContext) { LithoFilterPatch.addFilter(FILTER_CLASS_DESCRIPTOR) - SettingsPatch.addMusicPreference( + SettingsPatch.addSwitchPreference( CategoryType.GENERAL, "revanced_hide_samples_shelf", "false" diff --git a/src/main/kotlin/app/revanced/patches/music/general/startpage/ChangeStartPagePatch.kt b/src/main/kotlin/app/revanced/patches/music/general/startpage/ChangeStartPagePatch.kt index 80091a742..07839e5d7 100644 --- a/src/main/kotlin/app/revanced/patches/music/general/startpage/ChangeStartPagePatch.kt +++ b/src/main/kotlin/app/revanced/patches/music/general/startpage/ChangeStartPagePatch.kt @@ -46,7 +46,7 @@ object ChangeStartPagePatch : BaseBytecodePatch( */ contexts.copyXmlNode("music/startpage/host", "values/arrays.xml", "resources") - SettingsPatch.addMusicPreferenceWithIntent( + SettingsPatch.addPreferenceWithIntent( CategoryType.GENERAL, "revanced_change_start_page" ) diff --git a/src/main/kotlin/app/revanced/patches/music/general/taptoupdate/TapToUpdateButtonPatch.kt b/src/main/kotlin/app/revanced/patches/music/general/taptoupdate/TapToUpdateButtonPatch.kt index 2fb254470..b037c1c44 100644 --- a/src/main/kotlin/app/revanced/patches/music/general/taptoupdate/TapToUpdateButtonPatch.kt +++ b/src/main/kotlin/app/revanced/patches/music/general/taptoupdate/TapToUpdateButtonPatch.kt @@ -36,7 +36,7 @@ object TapToUpdateButtonPatch : BaseBytecodePatch( } } - SettingsPatch.addMusicPreference( + SettingsPatch.addSwitchPreference( CategoryType.GENERAL, "revanced_hide_tap_to_update_button", "false" diff --git a/src/main/kotlin/app/revanced/patches/music/misc/codecs/ForceOpusCodecPatch.kt b/src/main/kotlin/app/revanced/patches/music/misc/codecs/ForceOpusCodecPatch.kt index cf95865be..8f4afa051 100644 --- a/src/main/kotlin/app/revanced/patches/music/misc/codecs/ForceOpusCodecPatch.kt +++ b/src/main/kotlin/app/revanced/patches/music/misc/codecs/ForceOpusCodecPatch.kt @@ -19,7 +19,7 @@ object ForceOpusCodecPatch : BaseResourcePatch( ) { override fun execute(context: ResourceContext) { - SettingsPatch.addMusicPreference( + SettingsPatch.addSwitchPreference( CategoryType.MISC, "revanced_enable_opus_codec", "true" diff --git a/src/main/kotlin/app/revanced/patches/music/misc/debugging/DebuggingPatch.kt b/src/main/kotlin/app/revanced/patches/music/misc/debugging/DebuggingPatch.kt index 88f2ef9a9..1b51409a8 100644 --- a/src/main/kotlin/app/revanced/patches/music/misc/debugging/DebuggingPatch.kt +++ b/src/main/kotlin/app/revanced/patches/music/misc/debugging/DebuggingPatch.kt @@ -16,12 +16,12 @@ object DebuggingPatch : BaseResourcePatch( ) { override fun execute(context: ResourceContext) { - SettingsPatch.addMusicPreference( + SettingsPatch.addSwitchPreference( CategoryType.MISC, "revanced_enable_debug_logging", "false" ) - SettingsPatch.addMusicPreference( + SettingsPatch.addSwitchPreference( CategoryType.MISC, "revanced_enable_debug_buffer_logging", "false", diff --git a/src/main/kotlin/app/revanced/patches/music/misc/spoofappversion/SpoofAppVersionPatch.kt b/src/main/kotlin/app/revanced/patches/music/misc/spoofappversion/SpoofAppVersionPatch.kt index 3bf38798a..f6b378c66 100644 --- a/src/main/kotlin/app/revanced/patches/music/misc/spoofappversion/SpoofAppVersionPatch.kt +++ b/src/main/kotlin/app/revanced/patches/music/misc/spoofappversion/SpoofAppVersionPatch.kt @@ -25,12 +25,12 @@ object SpoofAppVersionPatch : BaseResourcePatch( */ context.copyXmlNode("music/spoofappversion/host", "values/arrays.xml", "resources") - SettingsPatch.addMusicPreference( + SettingsPatch.addSwitchPreference( CategoryType.MISC, "revanced_spoof_app_version", "false" ) - SettingsPatch.addMusicPreferenceWithIntent( + SettingsPatch.addPreferenceWithIntent( CategoryType.MISC, "revanced_spoof_app_version_target", "revanced_spoof_app_version" diff --git a/src/main/kotlin/app/revanced/patches/music/misc/tracking/SanitizeUrlQueryPatch.kt b/src/main/kotlin/app/revanced/patches/music/misc/tracking/SanitizeUrlQueryPatch.kt index fabff8534..df5bfa9db 100644 --- a/src/main/kotlin/app/revanced/patches/music/misc/tracking/SanitizeUrlQueryPatch.kt +++ b/src/main/kotlin/app/revanced/patches/music/misc/tracking/SanitizeUrlQueryPatch.kt @@ -18,7 +18,7 @@ object SanitizeUrlQueryPatch : BaseResourcePatch( ) { override fun execute(context: ResourceContext) { - SettingsPatch.addMusicPreference( + SettingsPatch.addSwitchPreference( CategoryType.MISC, "revanced_sanitize_sharing_links", "true" diff --git a/src/main/kotlin/app/revanced/patches/music/navigation/black/BlackNavigationBarPatch.kt b/src/main/kotlin/app/revanced/patches/music/navigation/black/BlackNavigationBarPatch.kt index 60ffb6d6e..e85187fcd 100644 --- a/src/main/kotlin/app/revanced/patches/music/navigation/black/BlackNavigationBarPatch.kt +++ b/src/main/kotlin/app/revanced/patches/music/navigation/black/BlackNavigationBarPatch.kt @@ -40,7 +40,7 @@ object BlackNavigationBarPatch : BaseBytecodePatch( } } - SettingsPatch.addMusicPreference( + SettingsPatch.addSwitchPreference( CategoryType.NAVIGATION, "revanced_enable_black_navigation_bar", "true" diff --git a/src/main/kotlin/app/revanced/patches/music/navigation/component/NavigationBarComponentPatch.kt b/src/main/kotlin/app/revanced/patches/music/navigation/component/NavigationBarComponentPatch.kt index a04261187..9435bcdc8 100644 --- a/src/main/kotlin/app/revanced/patches/music/navigation/component/NavigationBarComponentPatch.kt +++ b/src/main/kotlin/app/revanced/patches/music/navigation/component/NavigationBarComponentPatch.kt @@ -92,37 +92,37 @@ object NavigationBarComponentPatch : BaseBytecodePatch( } } - SettingsPatch.addMusicPreference( + SettingsPatch.addSwitchPreference( CategoryType.NAVIGATION, "revanced_hide_explore_button", "false" ) - SettingsPatch.addMusicPreference( + SettingsPatch.addSwitchPreference( CategoryType.NAVIGATION, "revanced_hide_home_button", "false" ) - SettingsPatch.addMusicPreference( + SettingsPatch.addSwitchPreference( CategoryType.NAVIGATION, "revanced_hide_library_button", "false" ) - SettingsPatch.addMusicPreference( + SettingsPatch.addSwitchPreference( CategoryType.NAVIGATION, "revanced_hide_navigation_bar", "false" ) - SettingsPatch.addMusicPreference( + SettingsPatch.addSwitchPreference( CategoryType.NAVIGATION, "revanced_hide_navigation_label", "false" ) - SettingsPatch.addMusicPreference( + SettingsPatch.addSwitchPreference( CategoryType.NAVIGATION, "revanced_hide_samples_button", "false" ) - SettingsPatch.addMusicPreference( + SettingsPatch.addSwitchPreference( CategoryType.NAVIGATION, "revanced_hide_upgrade_button", "true" diff --git a/src/main/kotlin/app/revanced/patches/music/player/colormatchplayer/ColorMatchPlayerPatch.kt b/src/main/kotlin/app/revanced/patches/music/player/colormatchplayer/ColorMatchPlayerPatch.kt index 77d6f6447..7716e8413 100644 --- a/src/main/kotlin/app/revanced/patches/music/player/colormatchplayer/ColorMatchPlayerPatch.kt +++ b/src/main/kotlin/app/revanced/patches/music/player/colormatchplayer/ColorMatchPlayerPatch.kt @@ -97,7 +97,7 @@ object ColorMatchPlayerPatch : BaseBytecodePatch( } } - SettingsPatch.addMusicPreference( + SettingsPatch.addSwitchPreference( CategoryType.PLAYER, "revanced_enable_color_match_player", "true" diff --git a/src/main/kotlin/app/revanced/patches/music/player/minimizedplayer/MinimizedPlayerPatch.kt b/src/main/kotlin/app/revanced/patches/music/player/minimizedplayer/MinimizedPlayerPatch.kt index e9993bad0..e417d6e5a 100644 --- a/src/main/kotlin/app/revanced/patches/music/player/minimizedplayer/MinimizedPlayerPatch.kt +++ b/src/main/kotlin/app/revanced/patches/music/player/minimizedplayer/MinimizedPlayerPatch.kt @@ -36,7 +36,7 @@ object MinimizedPlayerPatch : BaseBytecodePatch( } } - SettingsPatch.addMusicPreference( + SettingsPatch.addSwitchPreference( CategoryType.PLAYER, "revanced_enable_force_minimized_player", "true" diff --git a/src/main/kotlin/app/revanced/patches/music/player/nextprevious/MiniPlayerButtonPatch.kt b/src/main/kotlin/app/revanced/patches/music/player/nextprevious/MiniPlayerButtonPatch.kt index 071060d52..643f61a06 100644 --- a/src/main/kotlin/app/revanced/patches/music/player/nextprevious/MiniPlayerButtonPatch.kt +++ b/src/main/kotlin/app/revanced/patches/music/player/nextprevious/MiniPlayerButtonPatch.kt @@ -121,12 +121,12 @@ object MiniPlayerButtonPatch : BaseBytecodePatch( mppWatchWhileLayoutMutableMethod.setViewArray() - SettingsPatch.addMusicPreference( + SettingsPatch.addSwitchPreference( CategoryType.PLAYER, "revanced_enable_mini_player_next_button", "true" ) - SettingsPatch.addMusicPreference( + SettingsPatch.addSwitchPreference( CategoryType.PLAYER, "revanced_enable_mini_player_previous_button", "false" diff --git a/src/main/kotlin/app/revanced/patches/music/player/oldplayerbackground/OldPlayerBackgroundPatch.kt b/src/main/kotlin/app/revanced/patches/music/player/oldplayerbackground/OldPlayerBackgroundPatch.kt index edf535fb7..fae7d1f4d 100644 --- a/src/main/kotlin/app/revanced/patches/music/player/oldplayerbackground/OldPlayerBackgroundPatch.kt +++ b/src/main/kotlin/app/revanced/patches/music/player/oldplayerbackground/OldPlayerBackgroundPatch.kt @@ -26,7 +26,7 @@ object OldPlayerBackgroundPatch : BaseBytecodePatch( "Please use YT Music 6.33.52 or earlier." ) - SettingsPatch.addMusicPreference( + SettingsPatch.addSwitchPreference( CategoryType.PLAYER, "revanced_enable_old_player_background", "false" diff --git a/src/main/kotlin/app/revanced/patches/music/player/oldplayerlayout/OldPlayerLayoutPatch.kt b/src/main/kotlin/app/revanced/patches/music/player/oldplayerlayout/OldPlayerLayoutPatch.kt index 5d5a5c5db..769429f75 100644 --- a/src/main/kotlin/app/revanced/patches/music/player/oldplayerlayout/OldPlayerLayoutPatch.kt +++ b/src/main/kotlin/app/revanced/patches/music/player/oldplayerlayout/OldPlayerLayoutPatch.kt @@ -26,7 +26,7 @@ object OldPlayerLayoutPatch : BaseBytecodePatch( "Please use YT Music 6.29.58 or earlier." ) - SettingsPatch.addMusicPreference( + SettingsPatch.addSwitchPreference( CategoryType.PLAYER, "revanced_enable_old_player_layout", "false" diff --git a/src/main/kotlin/app/revanced/patches/music/player/repeat/RememberRepeatPatch.kt b/src/main/kotlin/app/revanced/patches/music/player/repeat/RememberRepeatPatch.kt index 19b0c0970..21913c912 100644 --- a/src/main/kotlin/app/revanced/patches/music/player/repeat/RememberRepeatPatch.kt +++ b/src/main/kotlin/app/revanced/patches/music/player/repeat/RememberRepeatPatch.kt @@ -35,7 +35,7 @@ object RememberRepeatPatch : BaseBytecodePatch( } } - SettingsPatch.addMusicPreference( + SettingsPatch.addSwitchPreference( CategoryType.PLAYER, "revanced_remember_repeat_state", "true" diff --git a/src/main/kotlin/app/revanced/patches/music/player/replace/ReplaceCastButtonPatch.kt b/src/main/kotlin/app/revanced/patches/music/player/replace/ReplaceCastButtonPatch.kt index 5e123fdb7..b2e72524c 100644 --- a/src/main/kotlin/app/revanced/patches/music/player/replace/ReplaceCastButtonPatch.kt +++ b/src/main/kotlin/app/revanced/patches/music/player/replace/ReplaceCastButtonPatch.kt @@ -99,7 +99,7 @@ object ReplaceCastButtonPatch : BaseBytecodePatch( contexts.copyResources("music/cast", resourceGroup) } - SettingsPatch.addMusicPreference( + SettingsPatch.addSwitchPreference( CategoryType.PLAYER, "revanced_replace_player_cast_button", "false" diff --git a/src/main/kotlin/app/revanced/patches/music/player/share/ShareButtonPatch.kt b/src/main/kotlin/app/revanced/patches/music/player/share/ShareButtonPatch.kt index 522bf87cc..7686affa7 100644 --- a/src/main/kotlin/app/revanced/patches/music/player/share/ShareButtonPatch.kt +++ b/src/main/kotlin/app/revanced/patches/music/player/share/ShareButtonPatch.kt @@ -39,7 +39,7 @@ object ShareButtonPatch : BaseBytecodePatch( } } - SettingsPatch.addMusicPreference( + SettingsPatch.addSwitchPreference( CategoryType.PLAYER, "revanced_hide_fullscreen_share_button", "false" diff --git a/src/main/kotlin/app/revanced/patches/music/player/shuffle/RememberShufflePatch.kt b/src/main/kotlin/app/revanced/patches/music/player/shuffle/RememberShufflePatch.kt index 2305bdb61..4976fce77 100644 --- a/src/main/kotlin/app/revanced/patches/music/player/shuffle/RememberShufflePatch.kt +++ b/src/main/kotlin/app/revanced/patches/music/player/shuffle/RememberShufflePatch.kt @@ -160,7 +160,7 @@ object RememberShufflePatch : BaseBytecodePatch( } } - SettingsPatch.addMusicPreference( + SettingsPatch.addSwitchPreference( CategoryType.PLAYER, "revanced_remember_shuffle_state", "true" diff --git a/src/main/kotlin/app/revanced/patches/music/player/swipetodismiss/SwipeToDismissMiniPlayerPatch.kt b/src/main/kotlin/app/revanced/patches/music/player/swipetodismiss/SwipeToDismissMiniPlayerPatch.kt index 6c80a972a..57ddbd091 100644 --- a/src/main/kotlin/app/revanced/patches/music/player/swipetodismiss/SwipeToDismissMiniPlayerPatch.kt +++ b/src/main/kotlin/app/revanced/patches/music/player/swipetodismiss/SwipeToDismissMiniPlayerPatch.kt @@ -199,7 +199,7 @@ object SwipeToDismissMiniPlayerPatch : BaseBytecodePatch( } - SettingsPatch.addMusicPreference( + SettingsPatch.addSwitchPreference( CategoryType.PLAYER, "revanced_enable_swipe_to_dismiss_mini_player", "true" diff --git a/src/main/kotlin/app/revanced/patches/music/player/zenmode/ZenModePatch.kt b/src/main/kotlin/app/revanced/patches/music/player/zenmode/ZenModePatch.kt index 9c4b1b333..fc5218b1a 100644 --- a/src/main/kotlin/app/revanced/patches/music/player/zenmode/ZenModePatch.kt +++ b/src/main/kotlin/app/revanced/patches/music/player/zenmode/ZenModePatch.kt @@ -73,12 +73,12 @@ object ZenModePatch : BaseBytecodePatch( } } - SettingsPatch.addMusicPreference( + SettingsPatch.addSwitchPreference( CategoryType.PLAYER, "revanced_enable_zen_mode", "false" ) - SettingsPatch.addMusicPreference( + SettingsPatch.addSwitchPreference( CategoryType.PLAYER, "revanced_enable_zen_mode_podcast", "false", diff --git a/src/main/kotlin/app/revanced/patches/music/utils/returnyoutubedislike/ReturnYouTubeDislikePatch.kt b/src/main/kotlin/app/revanced/patches/music/utils/returnyoutubedislike/ReturnYouTubeDislikePatch.kt index 87d528c58..037c22065 100644 --- a/src/main/kotlin/app/revanced/patches/music/utils/returnyoutubedislike/ReturnYouTubeDislikePatch.kt +++ b/src/main/kotlin/app/revanced/patches/music/utils/returnyoutubedislike/ReturnYouTubeDislikePatch.kt @@ -2,12 +2,14 @@ package app.revanced.patches.music.utils.returnyoutubedislike import app.revanced.patcher.data.ResourceContext import app.revanced.patches.music.utils.integrations.Constants.COMPATIBLE_PACKAGE -import app.revanced.patches.music.utils.settings.ResourceUtils.RETURN_YOUTUBE_DISLIKE_SETTINGS_KEY -import app.revanced.patches.music.utils.settings.ResourceUtils.addReVancedMusicPreference +import app.revanced.patches.music.utils.settings.CategoryType +import app.revanced.patches.music.utils.settings.ResourceUtils.PREFERENCE_CATEGORY_TAG_NAME +import app.revanced.patches.music.utils.settings.ResourceUtils.SETTINGS_HEADER_PATH +import app.revanced.patches.music.utils.settings.ResourceUtils.addPreferenceCategoryUnderPreferenceScreen import app.revanced.patches.music.utils.settings.SettingsPatch +import app.revanced.util.adoptChild import app.revanced.util.patch.BaseResourcePatch import org.w3c.dom.Element -import org.w3c.dom.Node @Suppress("DEPRECATION", "unused") object ReturnYouTubeDislikePatch : BaseResourcePatch( @@ -19,45 +21,56 @@ object ReturnYouTubeDislikePatch : BaseResourcePatch( ), compatiblePackages = COMPATIBLE_PACKAGE ) { + private const val ABOUT_CATEGORY_KEY = "revanced_ryd_about" + override fun execute(context: ResourceContext) { - context.addReVancedMusicPreference(RETURN_YOUTUBE_DISLIKE_SETTINGS_KEY) - context.addSwitchPreference("revanced_ryd_enabled", "true") - context.addSwitchPreference( + SettingsPatch.addSwitchPreference( + CategoryType.RETURN_YOUTUBE_DISLIKE, + "revanced_ryd_enabled", + "true" + ) + SettingsPatch.addSwitchPreference( + CategoryType.RETURN_YOUTUBE_DISLIKE, "revanced_ryd_dislike_percentage", "false", "revanced_ryd_enabled" ) - context.addSwitchPreference("revanced_ryd_compact_layout", "false", "revanced_ryd_enabled") - context.addSwitchPreference( + SettingsPatch.addSwitchPreference( + CategoryType.RETURN_YOUTUBE_DISLIKE, + "revanced_ryd_compact_layout", + "false", + "revanced_ryd_enabled" + ) + SettingsPatch.addSwitchPreference( + CategoryType.RETURN_YOUTUBE_DISLIKE, "revanced_ryd_toast_on_connection_error", "false", "revanced_ryd_enabled" ) - context.addPreferenceCategory("revanced_ryd_about") - context.addAboutPreference("revanced_ryd_attribution") - } + context.addPreferenceCategoryUnderPreferenceScreen( + CategoryType.RETURN_YOUTUBE_DISLIKE.value, + ABOUT_CATEGORY_KEY + ) - private const val YOUTUBE_SETTINGS_PATH = "res/xml/settings_headers.xml" - private const val SWITCH_PREFERENCE_TAG_NAME = - "com.google.android.apps.youtube.music.ui.preference.SwitchCompatPreference" - private const val PREFERENCE_CATEGORY_TAG_NAME = - "com.google.android.apps.youtube.music.ui.preference.PreferenceCategoryCompat" + context.addAboutPreference( + ABOUT_CATEGORY_KEY, + "revanced_ryd_attribution", + "https://returnyoutubedislike.com" + ) - private fun Node.adoptChild(tagName: String, block: Element.() -> Unit) { - val child = ownerDocument.createElement(tagName) - child.block() - appendChild(child) } private fun ResourceContext.addAboutPreference( - key: String + preferenceCategoryKey: String, + key: String, + data: String ) { - this.xmlEditor[YOUTUBE_SETTINGS_PATH].use { editor -> + this.xmlEditor[SETTINGS_HEADER_PATH].use { editor -> val tags = editor.file.getElementsByTagName(PREFERENCE_CATEGORY_TAG_NAME) List(tags.length) { tags.item(it) as Element } - .filter { it.getAttribute("android:key").contains("revanced_ryd_about") } + .filter { it.getAttribute("android:key").contains(preferenceCategoryKey) } .forEach { it.adoptChild("Preference") { setAttribute("android:title", "@string/$key" + "_title") @@ -65,61 +78,11 @@ object ReturnYouTubeDislikePatch : BaseResourcePatch( setAttribute("android:key", key) this.adoptChild("intent") { setAttribute("android:action", "android.intent.action.VIEW") - setAttribute("android:data", "https://returnyoutubedislike.com") + setAttribute("android:data", data) } } } } } - private fun ResourceContext.addPreferenceCategory( - category: String - ) { - this.xmlEditor[YOUTUBE_SETTINGS_PATH].use { editor -> - val tags = editor.file.getElementsByTagName("PreferenceScreen") - List(tags.length) { tags.item(it) as Element } - .filter { - it.getAttribute("android:key").contains(RETURN_YOUTUBE_DISLIKE_SETTINGS_KEY) - } - .forEach { - it.adoptChild(PREFERENCE_CATEGORY_TAG_NAME) { - setAttribute("android:title", "@string/$category") - setAttribute("android:key", category) - } - } - } - } - - private fun ResourceContext.addSwitchPreference( - key: String, - defaultValue: String - ) { - addSwitchPreference(key, defaultValue, "") - } - - private fun ResourceContext.addSwitchPreference( - key: String, - defaultValue: String, - dependencyKey: String - ) { - this.xmlEditor[YOUTUBE_SETTINGS_PATH].use { editor -> - val tags = editor.file.getElementsByTagName("PreferenceScreen") - List(tags.length) { tags.item(it) as Element } - .filter { - it.getAttribute("android:key").contains(RETURN_YOUTUBE_DISLIKE_SETTINGS_KEY) - } - .forEach { - it.adoptChild(SWITCH_PREFERENCE_TAG_NAME) { - setAttribute("android:title", "@string/$key" + "_title") - setAttribute("android:summary", "@string/$key" + "_summary") - setAttribute("android:key", key) - if (dependencyKey.isNotEmpty()) { - setAttribute("android:dependency", dependencyKey) - } - setAttribute("android:defaultValue", defaultValue) - } - } - } - } - } \ No newline at end of file diff --git a/src/main/kotlin/app/revanced/patches/music/utils/settings/CategoryType.kt b/src/main/kotlin/app/revanced/patches/music/utils/settings/CategoryType.kt index 1cb3fcd99..2629e9cf2 100644 --- a/src/main/kotlin/app/revanced/patches/music/utils/settings/CategoryType.kt +++ b/src/main/kotlin/app/revanced/patches/music/utils/settings/CategoryType.kt @@ -9,5 +9,7 @@ enum class CategoryType(val value: String, var added: Boolean) { MISC("misc", false), NAVIGATION("navigation", false), PLAYER("player", false), + RETURN_YOUTUBE_DISLIKE("ryd", false), + SPONSOR_BLOCK("sb", false), VIDEO("video", false) } \ No newline at end of file diff --git a/src/main/kotlin/app/revanced/patches/music/utils/settings/ResourceUtils.kt b/src/main/kotlin/app/revanced/patches/music/utils/settings/ResourceUtils.kt index 10cc39358..0cad92813 100644 --- a/src/main/kotlin/app/revanced/patches/music/utils/settings/ResourceUtils.kt +++ b/src/main/kotlin/app/revanced/patches/music/utils/settings/ResourceUtils.kt @@ -7,39 +7,28 @@ import app.revanced.util.doRecursively import app.revanced.util.insertNode import org.w3c.dom.Element -@Suppress("DEPRECATION", "MemberVisibilityCanBePrivate") +@Suppress("DEPRECATION") object ResourceUtils { - const val YOUTUBE_MUSIC_SETTINGS_PATH = "res/xml/settings_headers.xml" + private const val RVX_SETTINGS_KEY = "revanced_extended_settings" - const val YOUTUBE_MUSIC_SETTINGS_KEY = "revanced_extended_settings" + const val SETTINGS_HEADER_PATH = "res/xml/settings_headers.xml" - const val RETURN_YOUTUBE_DISLIKE_SETTINGS_KEY = "revanced_ryd_settings" - - const val YOUTUBE_MUSIC_PREFERENCE_SCREEN_TAG_NAME = + const val PREFERENCE_SCREEN_TAG_NAME = "PreferenceScreen" - const val YOUTUBE_MUSIC_PREFERENCE_TAG_NAME = + const val PREFERENCE_CATEGORY_TAG_NAME = + "com.google.android.apps.youtube.music.ui.preference.PreferenceCategoryCompat" + + const val SWITCH_PREFERENCE_TAG_NAME = "com.google.android.apps.youtube.music.ui.preference.SwitchCompatPreference" - const val YOUTUBE_MUSIC_PREFERENCE_TARGET_CLASS = + const val ACTIVITY_HOOK_TARGET_CLASS = "com.google.android.gms.common.api.GoogleApiActivity" var musicPackageName = "com.google.android.apps.youtube.music" - fun ResourceContext.updatePackageName(newPackage: String) { - musicPackageName = newPackage - replacePackageName() - } - - fun setMusicPreferenceCategory(newCategory: String) { - CategoryType.entries.forEach { preference -> - if (newCategory == preference.value) - preference.added = true - } - } - - fun included(category: String): Boolean { + private fun isIncludedCategory(category: String): Boolean { CategoryType.entries.forEach { preference -> if (category == preference.value) return preference.added @@ -47,29 +36,65 @@ object ResourceUtils { return false } - fun ResourceContext.addMusicPreferenceCategory( + private fun ResourceContext.replacePackageName() { + this[SETTINGS_HEADER_PATH].writeText( + this[SETTINGS_HEADER_PATH].readText() + .replace("\"com.google.android.apps.youtube.music\"", "\"" + musicPackageName + "\"") + ) + } + + private fun setPreferenceCategory(newCategory: String) { + CategoryType.entries.forEach { preference -> + if (newCategory == preference.value) + preference.added = true + } + } + + fun ResourceContext.updatePackageName(newPackage: String) { + musicPackageName = newPackage + replacePackageName() + } + + fun ResourceContext.addPreferenceCategory( category: String ) { - this.xmlEditor[YOUTUBE_MUSIC_SETTINGS_PATH].use { editor -> - val tags = editor.file.getElementsByTagName("PreferenceScreen") + this.xmlEditor[SETTINGS_HEADER_PATH].use { editor -> + val tags = editor.file.getElementsByTagName(PREFERENCE_SCREEN_TAG_NAME) List(tags.length) { tags.item(it) as Element } - .filter { it.getAttribute("android:key").contains(YOUTUBE_MUSIC_SETTINGS_KEY) } + .filter { it.getAttribute("android:key").contains(RVX_SETTINGS_KEY) } .forEach { - if (!included(category)) { - it.adoptChild(YOUTUBE_MUSIC_PREFERENCE_SCREEN_TAG_NAME) { + if (!isIncludedCategory(category)) { + it.adoptChild(PREFERENCE_SCREEN_TAG_NAME) { setAttribute("android:title", "@string/revanced_category_$category") setAttribute("android:key", "revanced_settings_$category") } - setMusicPreferenceCategory(category) + setPreferenceCategory(category) } } } } - fun ResourceContext.sortMusicPreferenceCategory( + fun ResourceContext.addPreferenceCategoryUnderPreferenceScreen( + preferenceScreenKey: String, category: String ) { - this.xmlEditor[YOUTUBE_MUSIC_SETTINGS_PATH].use { editor -> + this.xmlEditor[SETTINGS_HEADER_PATH].use { editor -> + val tags = editor.file.getElementsByTagName(PREFERENCE_SCREEN_TAG_NAME) + List(tags.length) { tags.item(it) as Element } + .filter { it.getAttribute("android:key").contains(preferenceScreenKey) } + .forEach { + it.adoptChild(PREFERENCE_CATEGORY_TAG_NAME) { + setAttribute("android:title", "@string/$category") + setAttribute("android:key", category) + } + } + } + } + + fun ResourceContext.sortPreferenceCategory( + category: String + ) { + this.xmlEditor[SETTINGS_HEADER_PATH].use { editor -> editor.file.doRecursively loop@{ if (it !is Element) return@loop @@ -83,21 +108,14 @@ object ResourceUtils { replacePackageName() } - fun ResourceContext.replacePackageName() { - this[YOUTUBE_MUSIC_SETTINGS_PATH].writeText( - this[YOUTUBE_MUSIC_SETTINGS_PATH].readText() - .replace("\"com.google.android.apps.youtube.music\"", "\"" + musicPackageName + "\"") - ) - } - fun ResourceContext.addMicroGPreference( category: String, key: String, packageName: String, targetClassName: String ) { - this.xmlEditor[YOUTUBE_MUSIC_SETTINGS_PATH].use { editor -> - val tags = editor.file.getElementsByTagName(YOUTUBE_MUSIC_PREFERENCE_SCREEN_TAG_NAME) + this.xmlEditor[SETTINGS_HEADER_PATH].use { editor -> + val tags = editor.file.getElementsByTagName(PREFERENCE_SCREEN_TAG_NAME) List(tags.length) { tags.item(it) as Element } .filter { it.getAttribute("android:key").contains("revanced_settings_$category") } .forEach { @@ -117,20 +135,23 @@ object ResourceUtils { } } - fun ResourceContext.addMusicPreference( + fun ResourceContext.addSwitchPreference( category: String, key: String, defaultValue: String, - dependencyKey: String + dependencyKey: String, + setSummary: Boolean ) { - this.xmlEditor[YOUTUBE_MUSIC_SETTINGS_PATH].use { editor -> - val tags = editor.file.getElementsByTagName(YOUTUBE_MUSIC_PREFERENCE_SCREEN_TAG_NAME) + this.xmlEditor[SETTINGS_HEADER_PATH].use { editor -> + val tags = editor.file.getElementsByTagName(PREFERENCE_SCREEN_TAG_NAME) List(tags.length) { tags.item(it) as Element } .filter { it.getAttribute("android:key").contains("revanced_settings_$category") } .forEach { - it.adoptChild(YOUTUBE_MUSIC_PREFERENCE_TAG_NAME) { + it.adoptChild(SWITCH_PREFERENCE_TAG_NAME) { setAttribute("android:title", "@string/$key" + "_title") - setAttribute("android:summary", "@string/$key" + "_summary") + if (setSummary) { + setAttribute("android:summary", "@string/$key" + "_summary") + } setAttribute("android:key", key) setAttribute("android:defaultValue", defaultValue) if (dependencyKey != "") { @@ -141,13 +162,13 @@ object ResourceUtils { } } - fun ResourceContext.addMusicPreferenceWithIntent( + fun ResourceContext.addPreferenceWithIntent( category: String, key: String, dependencyKey: String ) { - this.xmlEditor[YOUTUBE_MUSIC_SETTINGS_PATH].use { editor -> - val tags = editor.file.getElementsByTagName(YOUTUBE_MUSIC_PREFERENCE_SCREEN_TAG_NAME) + this.xmlEditor[SETTINGS_HEADER_PATH].use { editor -> + val tags = editor.file.getElementsByTagName(PREFERENCE_SCREEN_TAG_NAME) List(tags.length) { tags.item(it) as Element } .filter { it.getAttribute("android:key").contains("revanced_settings_$category") } .forEach { @@ -163,7 +184,7 @@ object ResourceUtils { setAttribute("android:data", key) setAttribute( "android:targetClass", - YOUTUBE_MUSIC_PREFERENCE_TARGET_CLASS + ACTIVITY_HOOK_TARGET_CLASS ) } } @@ -171,29 +192,8 @@ object ResourceUtils { } } - fun ResourceContext.addMusicPreferenceWithoutSummary( - category: String, - key: String, - defaultValue: String - ) { - this.xmlEditor[YOUTUBE_MUSIC_SETTINGS_PATH].use { editor -> - val tags = editor.file.getElementsByTagName(YOUTUBE_MUSIC_PREFERENCE_SCREEN_TAG_NAME) - List(tags.length) { tags.item(it) as Element } - .filter { it.getAttribute("android:key").contains("revanced_settings_$category") } - .forEach { - it.adoptChild(YOUTUBE_MUSIC_PREFERENCE_TAG_NAME) { - setAttribute("android:title", "@string/$key" + "_title") - setAttribute("android:key", key) - setAttribute("android:defaultValue", defaultValue) - } - } - } - } - - fun ResourceContext.addReVancedMusicPreference( - key: String - ) { - this.xmlEditor[YOUTUBE_MUSIC_SETTINGS_PATH].use { editor -> + fun ResourceContext.addRVXSettingsPreference() { + this.xmlEditor[SETTINGS_HEADER_PATH].use { editor -> with(editor.file) { doRecursively loop@{ if (it !is Element) return@loop @@ -202,54 +202,12 @@ object ResourceUtils { "app:allowDividerBelow" ).textContent == "false" ) { - it.insertNode("PreferenceScreen", it) { + it.insertNode(PREFERENCE_SCREEN_TAG_NAME, it) { setAttribute( "android:title", - "@string/" + key + "_title" + "@string/revanced_extended_settings_title" ) - setAttribute("android:key", key) - setAttribute("app:allowDividerAbove", "false") - } - it.getAttributeNode("app:allowDividerBelow").textContent = "true" - return@loop - } - } - } - - doRecursively loop@{ - if (it !is Element) return@loop - - it.getAttributeNode("app:allowDividerBelow")?.let { attribute -> - if (attribute.textContent == "true") { - attribute.textContent = "false" - } - } - } - } - } - } - - fun ResourceContext.hookPreference( - key: String, - fragment: String - ) { - this.xmlEditor[YOUTUBE_MUSIC_SETTINGS_PATH].use { editor -> - with(editor.file) { - doRecursively loop@{ - if (it !is Element) return@loop - it.getAttributeNode("android:key")?.let { attribute -> - if (attribute.textContent == "settings_header_about_youtube_music" && it.getAttributeNode( - "app:allowDividerBelow" - ).textContent == "false" - ) { - it.insertNode("Preference", it) { - setAttribute("android:persistent", "false") - setAttribute( - "android:title", - "@string/" + key + "_title" - ) - setAttribute("android:key", key) - setAttribute("android:fragment", fragment) + setAttribute("android:key", "revanced_extended_settings") setAttribute("app:allowDividerAbove", "false") } it.getAttributeNode("app:allowDividerBelow").textContent = "true" diff --git a/src/main/kotlin/app/revanced/patches/music/utils/settings/SettingsPatch.kt b/src/main/kotlin/app/revanced/patches/music/utils/settings/SettingsPatch.kt index c01ea7507..373766e5b 100644 --- a/src/main/kotlin/app/revanced/patches/music/utils/settings/SettingsPatch.kt +++ b/src/main/kotlin/app/revanced/patches/music/utils/settings/SettingsPatch.kt @@ -3,13 +3,11 @@ package app.revanced.patches.music.utils.settings import app.revanced.patcher.data.ResourceContext import app.revanced.patches.music.utils.fix.accessibility.AccessibilityNodeInfoPatch import app.revanced.patches.music.utils.integrations.Constants.COMPATIBLE_PACKAGE -import app.revanced.patches.music.utils.settings.ResourceUtils.YOUTUBE_MUSIC_SETTINGS_KEY -import app.revanced.patches.music.utils.settings.ResourceUtils.addMusicPreference -import app.revanced.patches.music.utils.settings.ResourceUtils.addMusicPreferenceCategory -import app.revanced.patches.music.utils.settings.ResourceUtils.addMusicPreferenceWithIntent -import app.revanced.patches.music.utils.settings.ResourceUtils.addMusicPreferenceWithoutSummary -import app.revanced.patches.music.utils.settings.ResourceUtils.addReVancedMusicPreference -import app.revanced.patches.music.utils.settings.ResourceUtils.sortMusicPreferenceCategory +import app.revanced.patches.music.utils.settings.ResourceUtils.addPreferenceCategory +import app.revanced.patches.music.utils.settings.ResourceUtils.addPreferenceWithIntent +import app.revanced.patches.music.utils.settings.ResourceUtils.addRVXSettingsPreference +import app.revanced.patches.music.utils.settings.ResourceUtils.addSwitchPreference +import app.revanced.patches.music.utils.settings.ResourceUtils.sortPreferenceCategory import app.revanced.util.ResourceGroup import app.revanced.util.copyResources import app.revanced.util.copyXmlNode @@ -19,7 +17,7 @@ import java.io.Closeable import java.util.concurrent.Executors import java.util.concurrent.TimeUnit -@Suppress("DEPRECATION", "SpellCheckingInspection", "unused") +@Suppress("DEPRECATION", "unused") object SettingsPatch : BaseResourcePatch( name = "Settings", description = "Adds ReVanced Extended settings to YouTube Music.", @@ -129,53 +127,54 @@ object SettingsPatch : BaseResourcePatch( } } - context.addReVancedMusicPreference(YOUTUBE_MUSIC_SETTINGS_KEY) + context.addRVXSettingsPreference() } - internal fun addMusicPreference( + internal fun addSwitchPreference( category: CategoryType, key: String, defaultValue: String - ) { - addMusicPreference(category, key, defaultValue, "") - } + ) = addSwitchPreference(category, key, defaultValue, "") - internal fun addMusicPreference( + internal fun addSwitchPreference( + category: CategoryType, + key: String, + defaultValue: String, + setSummary: Boolean + ) = addSwitchPreference(category, key, defaultValue, "", setSummary) + + internal fun addSwitchPreference( category: CategoryType, key: String, defaultValue: String, dependencyKey: String - ) { - val categoryValue = category.value - contexts.addMusicPreferenceCategory(categoryValue) - contexts.addMusicPreference(categoryValue, key, defaultValue, dependencyKey) - } + ) = addSwitchPreference(category, key, defaultValue, dependencyKey, true) - internal fun addMusicPreferenceWithoutSummary( + internal fun addSwitchPreference( category: CategoryType, key: String, - defaultValue: String + defaultValue: String, + dependencyKey: String, + setSummary: Boolean ) { val categoryValue = category.value - contexts.addMusicPreferenceCategory(categoryValue) - contexts.addMusicPreferenceWithoutSummary(categoryValue, key, defaultValue) + contexts.addPreferenceCategory(categoryValue) + contexts.addSwitchPreference(categoryValue, key, defaultValue, dependencyKey, setSummary) } - internal fun addMusicPreferenceWithIntent( + internal fun addPreferenceWithIntent( category: CategoryType, key: String - ) { - addMusicPreferenceWithIntent(category, key, "") - } + ) = addPreferenceWithIntent(category, key, "") - internal fun addMusicPreferenceWithIntent( + internal fun addPreferenceWithIntent( category: CategoryType, key: String, dependencyKey: String ) { val categoryValue = category.value - contexts.addMusicPreferenceCategory(categoryValue) - contexts.addMusicPreferenceWithIntent(categoryValue, key, dependencyKey) + contexts.addPreferenceCategory(categoryValue) + contexts.addPreferenceWithIntent(categoryValue, key, dependencyKey) } override fun close() { @@ -184,14 +183,13 @@ object SettingsPatch : BaseResourcePatch( */ contexts.copyXmlNode("music/settings/host", "values/arrays.xml", "resources") - addMusicPreferenceWithIntent( + addPreferenceWithIntent( CategoryType.MISC, - "revanced_extended_settings_import_export", - "" + "revanced_extended_settings_import_export" ) CategoryType.entries.sorted().forEach { - contexts.sortMusicPreferenceCategory(it.value) + contexts.sortPreferenceCategory(it.value) } } } diff --git a/src/main/kotlin/app/revanced/patches/music/utils/sponsorblock/SponsorBlockPatch.kt b/src/main/kotlin/app/revanced/patches/music/utils/sponsorblock/SponsorBlockPatch.kt index e35c2f967..6e4ad6ad3 100644 --- a/src/main/kotlin/app/revanced/patches/music/utils/sponsorblock/SponsorBlockPatch.kt +++ b/src/main/kotlin/app/revanced/patches/music/utils/sponsorblock/SponsorBlockPatch.kt @@ -2,14 +2,20 @@ package app.revanced.patches.music.utils.sponsorblock import app.revanced.patcher.data.ResourceContext import app.revanced.patches.music.utils.integrations.Constants.COMPATIBLE_PACKAGE +import app.revanced.patches.music.utils.settings.CategoryType import app.revanced.patches.music.utils.settings.ResourceUtils -import app.revanced.patches.music.utils.settings.ResourceUtils.hookPreference +import app.revanced.patches.music.utils.settings.ResourceUtils.ACTIVITY_HOOK_TARGET_CLASS +import app.revanced.patches.music.utils.settings.ResourceUtils.PREFERENCE_CATEGORY_TAG_NAME +import app.revanced.patches.music.utils.settings.ResourceUtils.PREFERENCE_SCREEN_TAG_NAME +import app.revanced.patches.music.utils.settings.ResourceUtils.SETTINGS_HEADER_PATH +import app.revanced.patches.music.utils.settings.ResourceUtils.SWITCH_PREFERENCE_TAG_NAME +import app.revanced.patches.music.utils.settings.ResourceUtils.addPreferenceCategory import app.revanced.patches.music.utils.settings.SettingsPatch -import app.revanced.util.ResourceGroup -import app.revanced.util.copyResources +import app.revanced.util.adoptChild import app.revanced.util.patch.BaseResourcePatch +import org.w3c.dom.Element -@Suppress("DEPRECATION", "unused") +@Suppress("DEPRECATION", "SameParameterValue", "unused") object SponsorBlockPatch : BaseResourcePatch( name = "SponsorBlock", description = "Adds options to enable and configure SponsorBlock, which can skip undesired video segments such as non-music sections.", @@ -19,46 +25,232 @@ object SponsorBlockPatch : BaseResourcePatch( ), compatiblePackages = COMPATIBLE_PACKAGE ) { - override fun execute(context: ResourceContext) { + private const val SEGMENTS_CATEGORY_KEY = "sb_diff_segments" + private const val ABOUT_CATEGORY_KEY = "sb_about" - /** - * Copy preference - */ - arrayOf( - ResourceGroup( - "xml", - "sponsorblock_prefs.xml" + private var SPONSOR_BLOCK_CATEGORY = CategoryType.SPONSOR_BLOCK.value + lateinit var context: ResourceContext + + override fun execute(context: ResourceContext) { + this.context = context + + context.addPreferenceCategory(SPONSOR_BLOCK_CATEGORY) + + addSwitchPreference( + SPONSOR_BLOCK_CATEGORY, + "sb_enabled", + "true" + ) + addSwitchPreference( + SPONSOR_BLOCK_CATEGORY, + "sb_toast_on_skip", + "true", + "sb_enabled" + ) + addSwitchPreference( + SPONSOR_BLOCK_CATEGORY, + "sb_toast_on_connection_error", + "false", + "sb_enabled" + ) + addPreferenceWithIntent( + SPONSOR_BLOCK_CATEGORY, + "sb_api_url", + "sb_enabled" + ) + + addPreferenceCategoryUnderPreferenceScreen( + CategoryType.SPONSOR_BLOCK.value, + SEGMENTS_CATEGORY_KEY + ) + + addSegmentsPreference( + SEGMENTS_CATEGORY_KEY, + "sb_segments_sponsor", + "sb_enabled" + ) + addSegmentsPreference( + SEGMENTS_CATEGORY_KEY, + "sb_segments_selfpromo", + "sb_enabled" + ) + addSegmentsPreference( + SEGMENTS_CATEGORY_KEY, + "sb_segments_interaction", + "sb_enabled" + ) + addSegmentsPreference( + SEGMENTS_CATEGORY_KEY, + "sb_segments_intro", + "sb_enabled" + ) + addSegmentsPreference( + SEGMENTS_CATEGORY_KEY, + "sb_segments_outro", + "sb_enabled" + ) + addSegmentsPreference( + SEGMENTS_CATEGORY_KEY, + "sb_segments_preview", + "sb_enabled" + ) + addSegmentsPreference( + SEGMENTS_CATEGORY_KEY, + "sb_segments_filler", + "sb_enabled" + ) + addSegmentsPreference( + SEGMENTS_CATEGORY_KEY, + "sb_segments_nomusic", + "sb_enabled" + ) + + addPreferenceCategoryUnderPreferenceScreen( + CategoryType.SPONSOR_BLOCK.value, + ABOUT_CATEGORY_KEY + ) + + addAboutPreference( + ABOUT_CATEGORY_KEY, + "sb_about_api", + "https://sponsor.ajay.app" + ) + + context[SETTINGS_HEADER_PATH].apply { + writeText( + readText() + .replace( + "\"sb_segments_nomusic", + "\"sb_segments_music_offtopic" + ) ) - ).forEach { resourceGroup -> - context.copyResources("music/sponsorblock", resourceGroup) } - /** - * Hook SponsorBlock preference - */ - context.hookPreference( - "revanced_sponsorblock_settings", - "com.google.android.apps.youtube.music.settings.fragment.AdvancedPrefsFragmentCompat" - ) + } - val publicFile = context["res/values/public.xml"] - val preferenceFile = context["res/xml/sponsorblock_prefs.xml"] + private fun addSwitchPreference( + category: String, + key: String, + defaultValue: String + ) = addSwitchPreference(category, key, defaultValue, "") - publicFile.writeText( - publicFile.readText() - .replace( - "\"advanced_prefs_compat\"", - "\"sponsorblock_prefs\"" - ) - ) + private fun addSwitchPreference( + category: String, + key: String, + defaultValue: String, + dependencyKey: String + ) { + context.xmlEditor[SETTINGS_HEADER_PATH].use { editor -> + val tags = editor.file.getElementsByTagName(PREFERENCE_SCREEN_TAG_NAME) + List(tags.length) { tags.item(it) as Element } + .filter { it.getAttribute("android:key").contains("revanced_settings_$category") } + .forEach { + it.adoptChild(SWITCH_PREFERENCE_TAG_NAME) { + setAttribute("android:title", "@string/revanced_$key") + setAttribute("android:summary", "@string/revanced_$key" + "_sum") + setAttribute("android:key", key) + setAttribute("android:defaultValue", defaultValue) + if (dependencyKey != "") { + setAttribute("android:dependency", dependencyKey) + } + } + } + } + } - preferenceFile.writeText( - preferenceFile.readText() - .replace( - "\"com.google.android.apps.youtube.music\"", - "\"" + ResourceUtils.musicPackageName + "\"" - ) - ) + private fun addPreferenceWithIntent( + category: String, + key: String, + dependencyKey: String + ) { + context.xmlEditor[SETTINGS_HEADER_PATH].use { editor -> + val tags = editor.file.getElementsByTagName(PREFERENCE_SCREEN_TAG_NAME) + List(tags.length) { tags.item(it) as Element } + .filter { it.getAttribute("android:key").contains("revanced_settings_$category") } + .forEach { + it.adoptChild("Preference") { + setAttribute("android:title", "@string/revanced_$key") + setAttribute("android:summary", "@string/revanced_$key" + "_sum") + setAttribute("android:key", key) + setAttribute("android:dependency", dependencyKey) + this.adoptChild("intent") { + setAttribute("android:targetPackage", ResourceUtils.musicPackageName) + setAttribute("android:data", key) + setAttribute( + "android:targetClass", + ACTIVITY_HOOK_TARGET_CLASS + ) + } + } + } + } + } + private fun addPreferenceCategoryUnderPreferenceScreen( + preferenceScreenKey: String, + category: String + ) { + context.xmlEditor[SETTINGS_HEADER_PATH].use { editor -> + val tags = editor.file.getElementsByTagName(PREFERENCE_SCREEN_TAG_NAME) + List(tags.length) { tags.item(it) as Element } + .filter { it.getAttribute("android:key").contains(preferenceScreenKey) } + .forEach { + it.adoptChild(PREFERENCE_CATEGORY_TAG_NAME) { + setAttribute("android:title", "@string/revanced_$category") + setAttribute("android:key", category) + } + } + } + } + + private fun addSegmentsPreference( + preferenceCategoryKey: String, + key: String, + dependencyKey: String + ) { + context.xmlEditor[SETTINGS_HEADER_PATH].use { editor -> + val tags = editor.file.getElementsByTagName(PREFERENCE_CATEGORY_TAG_NAME) + List(tags.length) { tags.item(it) as Element } + .filter { it.getAttribute("android:key").contains(preferenceCategoryKey) } + .forEach { + it.adoptChild("Preference") { + setAttribute("android:title", "@string/revanced_$key") + setAttribute("android:summary", "@string/revanced_$key" + "_sum") + setAttribute("android:key", key) + setAttribute("android:dependency", dependencyKey) + this.adoptChild("intent") { + setAttribute("android:targetPackage", ResourceUtils.musicPackageName) + setAttribute("android:data", key) + setAttribute( + "android:targetClass", + ACTIVITY_HOOK_TARGET_CLASS + ) + } + } + } + } + } + + private fun addAboutPreference( + preferenceCategoryKey: String, + key: String, + data: String + ) { + context.xmlEditor[SETTINGS_HEADER_PATH].use { editor -> + val tags = editor.file.getElementsByTagName(PREFERENCE_CATEGORY_TAG_NAME) + List(tags.length) { tags.item(it) as Element } + .filter { it.getAttribute("android:key").contains(preferenceCategoryKey) } + .forEach { + it.adoptChild("Preference") { + setAttribute("android:title", "@string/revanced_$key") + setAttribute("android:summary", "@string/revanced_$key" + "_sum") + setAttribute("android:key", key) + this.adoptChild("intent") { + setAttribute("android:action", "android.intent.action.VIEW") + setAttribute("android:data", data) + } + } + } + } } } \ No newline at end of file diff --git a/src/main/kotlin/app/revanced/patches/music/video/customspeed/CustomPlaybackSpeedPatch.kt b/src/main/kotlin/app/revanced/patches/music/video/customspeed/CustomPlaybackSpeedPatch.kt index 22b16f137..e76fa7075 100644 --- a/src/main/kotlin/app/revanced/patches/music/video/customspeed/CustomPlaybackSpeedPatch.kt +++ b/src/main/kotlin/app/revanced/patches/music/video/customspeed/CustomPlaybackSpeedPatch.kt @@ -18,7 +18,7 @@ object CustomPlaybackSpeedPatch : BaseResourcePatch( ) { override fun execute(context: ResourceContext) { - SettingsPatch.addMusicPreferenceWithIntent( + SettingsPatch.addPreferenceWithIntent( CategoryType.VIDEO, "revanced_custom_playback_speeds" ) diff --git a/src/main/kotlin/app/revanced/patches/music/video/quality/VideoQualityPatch.kt b/src/main/kotlin/app/revanced/patches/music/video/quality/VideoQualityPatch.kt index 50c235667..76beb4c5e 100644 --- a/src/main/kotlin/app/revanced/patches/music/video/quality/VideoQualityPatch.kt +++ b/src/main/kotlin/app/revanced/patches/music/video/quality/VideoQualityPatch.kt @@ -58,7 +58,7 @@ object VideoQualityPatch : BaseBytecodePatch( VideoIdPatch.hookVideoId("$INTEGRATIONS_VIDEO_QUALITY_CLASS_DESCRIPTOR->newVideoStarted(Ljava/lang/String;)V") - SettingsPatch.addMusicPreference( + SettingsPatch.addSwitchPreference( CategoryType.VIDEO, "revanced_enable_save_video_quality", "true" diff --git a/src/main/kotlin/app/revanced/patches/music/video/speed/PlaybackSpeedPatch.kt b/src/main/kotlin/app/revanced/patches/music/video/speed/PlaybackSpeedPatch.kt index b778c5cb1..522cb3066 100644 --- a/src/main/kotlin/app/revanced/patches/music/video/speed/PlaybackSpeedPatch.kt +++ b/src/main/kotlin/app/revanced/patches/music/video/speed/PlaybackSpeedPatch.kt @@ -50,7 +50,7 @@ object PlaybackSpeedPatch : BaseBytecodePatch( } } - SettingsPatch.addMusicPreference( + SettingsPatch.addSwitchPreference( CategoryType.VIDEO, "revanced_enable_save_playback_speed", "true"