Skip to content

Commit

Permalink
feat(YouTube/Visual preferences icons): add the patch option `ApplyTo…
Browse files Browse the repository at this point in the history
…All ` that do not apply to sub-settings inotia00/ReVanced_Extended#2392
  • Loading branch information
inotia00 committed Sep 17, 2024
1 parent bee0fb0 commit 5e4b56c
Show file tree
Hide file tree
Showing 8 changed files with 216 additions and 28 deletions.
Original file line number Diff line number Diff line change
@@ -1,26 +1,29 @@
package app.revanced.patches.youtube.layout.visual

import app.revanced.patcher.data.ResourceContext
import app.revanced.patcher.patch.options.PatchOption.PatchExtensions.booleanPatchOption
import app.revanced.patcher.patch.options.PatchOption.PatchExtensions.stringPatchOption
import app.revanced.patches.youtube.layout.branding.icon.CustomBrandingIconPatch
import app.revanced.patches.youtube.utils.compatibility.Constants.COMPATIBLE_PACKAGE
import app.revanced.patches.youtube.utils.settings.SettingsPatch
import app.revanced.util.ResourceGroup
import app.revanced.util.Utils.trimIndentMultiline
import app.revanced.util.copyResources
import app.revanced.util.doRecursively
import app.revanced.util.patch.BaseResourcePatch
import app.revanced.util.underBarOrThrow
import org.w3c.dom.Element
import java.io.Closeable

@Suppress("DEPRECATION", "unused")
object VisualPreferencesIconsPatch : BaseResourcePatch(
name = "Visual preferences icons",
description = "Adds icons to specific preferences in the settings.",
dependencies = setOf(SettingsPatch::class),
compatiblePackages = COMPATIBLE_PACKAGE,
use = false
) {
compatiblePackages = COMPATIBLE_PACKAGE
), Closeable {
private const val DEFAULT_ICON = "extension"
private const val EMPTY_ICON = "empty_icon"

private val RVXSettingsMenuIcon = stringPatchOption(
key = "RVXSettingsMenuIcon",
Expand All @@ -37,7 +40,24 @@ object VisualPreferencesIconsPatch : BaseResourcePatch(
required = true
)

private val ApplyToAll by booleanPatchOption(
key = "ApplyToAll",
default = false,
title = "Apply to all settings menu",
description = """
Whether to apply Visual preferences icons to all settings menus.
If true: icons are applied to the parent PreferenceScreen of YouTube settings, the parent PreferenceScreen of RVX settings and the RVX sub-settings (if supports).
If false: icons are applied only to the parent PreferenceScreen of YouTube settings and RVX settings.
""".trimIndentMultiline(),
required = true
)

private lateinit var context: ResourceContext

override fun execute(context: ResourceContext) {
this.context = context

// Check patch options first.
val selectedIconType = RVXSettingsMenuIcon
Expand All @@ -46,6 +66,12 @@ object VisualPreferencesIconsPatch : BaseResourcePatch(
val customBrandingIconType = CustomBrandingIconPatch.AppIcon
.underBarOrThrow()

if (ApplyToAll == true) {
preferenceKey += rvxPreferenceKey
}

preferenceIcon = preferenceKey.setPreferenceIcon()

// region copy shared resources.

arrayOf(
Expand All @@ -55,7 +81,7 @@ object VisualPreferencesIconsPatch : BaseResourcePatch(
),
ResourceGroup(
"drawable-xxhdpi",
"$emptyIcon.png"
"$EMPTY_ICON.png"
),
).forEach { resourceGroup ->
context.copyResources("youtube/visual/shared", resourceGroup)
Expand Down Expand Up @@ -90,6 +116,11 @@ object VisualPreferencesIconsPatch : BaseResourcePatch(

// endregion.

SettingsPatch.updatePatchStatus(this)
}

override fun close() {

// region set visual preferences icon.

arrayOf(
Expand All @@ -109,9 +140,12 @@ object VisualPreferencesIconsPatch : BaseResourcePatch(

// Add custom RVX settings menu icon
in intentKey -> intentIcon[title]
in emptyTitles -> emptyIcon
in emptyTitles -> EMPTY_ICON
else -> null
}
if (drawableName == EMPTY_ICON &&
ApplyToAll == false) return@loop

drawableName?.let {
node.setAttribute("android:icon", "@drawable/$it")
}
Expand All @@ -122,35 +156,34 @@ object VisualPreferencesIconsPatch : BaseResourcePatch(

// endregion.

SettingsPatch.updatePatchStatus(this)
}

// region preference key and icon.

private val preferenceKey = setOf(
// Main settings (sorted as displayed in the settings)
"parent_tools_key",
"general_key",
private var preferenceKey = setOf(
// YouTube settings.
"about_key",
"accessibility_settings_key",
"account_switcher_key",
"data_saving_settings_key",
"auto_play_key",
"video_quality_settings_key",
"billing_and_payment_key",
"captions_key",
"connected_accounts_browse_page_key",
"data_saving_settings_key",
"general_key",
"history_key",
"live_chat_key",
"notification_key",
"offline_key",
"pair_with_tv_key",
"history_key",
"your_data_key",
"privacy_key",
"parent_tools_key",
"premium_early_access_browse_page_key",
"privacy_key",
"subscription_product_setting_key",
"billing_and_payment_key",
"notification_key",
"connected_accounts_browse_page_key",
"live_chat_key",
"captions_key",
"accessibility_settings_key",
"about_key",
"video_quality_settings_key",
"your_data_key",

// Main RVX settings (sorted as displayed in the settings)
// RVX settings.
"revanced_preference_screen_ads",
"revanced_preference_screen_alt_thumbnails",
"revanced_preference_screen_feed",
Expand All @@ -162,7 +195,9 @@ object VisualPreferencesIconsPatch : BaseResourcePatch(
"revanced_preference_screen_ryd",
"revanced_preference_screen_sb",
"revanced_preference_screen_misc",
)

private var rvxPreferenceKey = setOf(
// Internal RVX settings (items without prefix are listed first, others are sorted alphabetically)
"gms_core_settings",
"sb_enable_create_segment",
Expand All @@ -173,11 +208,13 @@ object VisualPreferencesIconsPatch : BaseResourcePatch(
"revanced_alt_thumbnail_player",
"revanced_alt_thumbnail_search",
"revanced_alt_thumbnail_subscriptions",
"revanced_change_share_sheet",
"revanced_change_shorts_repeat_state",
"revanced_custom_player_overlay_opacity",
"revanced_default_app_settings",
"revanced_default_playback_speed",
"revanced_default_video_quality_wifi",
"revanced_disable_default_playback_speed_music",
"revanced_disable_hdr_auto_brightness",
"revanced_disable_hdr_video",
"revanced_disable_quic_protocol",
Expand All @@ -186,10 +223,13 @@ object VisualPreferencesIconsPatch : BaseResourcePatch(
"revanced_enable_external_browser",
"revanced_enable_old_quality_layout",
"revanced_enable_open_links_directly",
"revanced_enable_opus_codec",
"revanced_enable_save_and_restore_brightness",
"revanced_enable_swipe_brightness",
"revanced_enable_swipe_haptic_feedback",
"revanced_enable_swipe_lowest_value_auto_brightness",
"revanced_enable_swipe_press_to_engage",
"revanced_enable_swipe_to_switch_video",
"revanced_enable_swipe_volume",
"revanced_enable_watch_panel_gestures",
"revanced_hide_clip_button",
Expand All @@ -213,11 +253,14 @@ object VisualPreferencesIconsPatch : BaseResourcePatch(
"revanced_hide_player_flyout_menu_audio_track",
"revanced_hide_player_flyout_menu_captions",
"revanced_hide_player_flyout_menu_help",
"revanced_hide_player_flyout_menu_listen_with_youtube_music",
"revanced_hide_player_flyout_menu_lock_screen",
"revanced_hide_player_flyout_menu_loop_video",
"revanced_hide_player_flyout_menu_more_info",
"revanced_hide_player_flyout_menu_pip",
"revanced_hide_player_flyout_menu_premium_controls",
"revanced_hide_player_flyout_menu_playback_speed",
"revanced_hide_player_flyout_menu_quality_footer",
"revanced_hide_player_flyout_menu_quality_header",
"revanced_hide_player_flyout_menu_report",
"revanced_hide_player_flyout_menu_stable_volume",
"revanced_hide_player_flyout_menu_stats_for_nerds",
Expand All @@ -235,7 +278,9 @@ object VisualPreferencesIconsPatch : BaseResourcePatch(
"revanced_hide_quick_actions_share_button",
"revanced_hide_remix_button",
"revanced_hide_report_button",
"revanced_hide_rewards_button",
"revanced_hide_share_button",
"revanced_hide_shop_button",
"revanced_hide_shorts_comments_button",
"revanced_hide_shorts_dislike_button",
"revanced_hide_shorts_like_button",
Expand All @@ -247,6 +292,10 @@ object VisualPreferencesIconsPatch : BaseResourcePatch(
"revanced_hide_shorts_shelf_search",
"revanced_hide_shorts_shelf_subscriptions",
"revanced_hide_shorts_toolbar",
"revanced_hide_thanks_button",
"revanced_hide_toolbar_cast_button",
"revanced_hide_toolbar_create_button",
"revanced_hide_toolbar_notification_button",
"revanced_overlay_button_always_repeat",
"revanced_overlay_button_copy_video_url",
"revanced_overlay_button_copy_video_url_timestamp",
Expand Down Expand Up @@ -280,6 +329,7 @@ object VisualPreferencesIconsPatch : BaseResourcePatch(
"revanced_preference_screen_toolbar",
"revanced_preference_screen_video_description",
"revanced_preference_screen_video_filter",
"revanced_preference_screen_watch_history",
"revanced_sanitize_sharing_links",
"revanced_swipe_gestures_lock_mode",
"revanced_swipe_magnitude_threshold",
Expand All @@ -299,13 +349,16 @@ object VisualPreferencesIconsPatch : BaseResourcePatch(
"revanced_custom_playback_speeds",
"revanced_custom_playback_speed_menu_type",
"revanced_default_video_quality_mobile",
"revanced_disable_like_dislike_glow",
"revanced_disable_default_playback_speed_live",
"revanced_enable_custom_playback_speed",
"revanced_external_downloader_package_name",
"revanced_hide_shorts_comments_disabled_button",
"revanced_hide_player_flyout_menu_captions_footer",
"revanced_hide_player_flyout_menu_quality_footer",
"revanced_remember_playback_speed_last_selected",
"revanced_remember_playback_speed_last_selected_toast",
"revanced_remember_video_quality_last_selected",
"revanced_remember_video_quality_last_selected_toast",
"revanced_restore_old_video_quality_menu",
"revanced_enable_debug_buffer_logging",
"revanced_whitelist_settings",
Expand All @@ -314,7 +367,7 @@ object VisualPreferencesIconsPatch : BaseResourcePatch(
// A lot of mappings here.
// The performance impact should be negligible in this context,
// as the operations involved are not computationally intensive.
private val preferenceIcon = preferenceKey.associateWith { title ->
private fun Set<String>.setPreferenceIcon() = associateWith { title ->
when (title) {
// Main RVX settings
"revanced_preference_screen_general" -> "general_key_icon"
Expand All @@ -326,6 +379,7 @@ object VisualPreferencesIconsPatch : BaseResourcePatch(
"revanced_alt_thumbnail_player" -> "revanced_preference_screen_player_icon"
"revanced_alt_thumbnail_search" -> "revanced_hide_shorts_shelf_search_icon"
"revanced_alt_thumbnail_subscriptions" -> "revanced_hide_navigation_subscriptions_button_icon"
"revanced_change_share_sheet" -> "revanced_hide_shorts_share_button_icon"
"revanced_custom_player_overlay_opacity" -> "revanced_swipe_overlay_background_alpha_icon"
"revanced_default_app_settings" -> "revanced_preference_screen_settings_menu_icon"
"revanced_default_playback_speed" -> "revanced_overlay_button_speed_dialog_icon"
Expand All @@ -344,9 +398,12 @@ object VisualPreferencesIconsPatch : BaseResourcePatch(
"revanced_hide_player_captions_button" -> "captions_key_icon"
"revanced_hide_player_flyout_menu_ambient_mode" -> "revanced_preference_screen_ambient_mode_icon"
"revanced_hide_player_flyout_menu_captions" -> "captions_key_icon"
"revanced_hide_player_flyout_menu_listen_with_youtube_music" -> "revanced_hide_player_youtube_music_button_icon"
"revanced_hide_player_flyout_menu_loop_video" -> "revanced_overlay_button_always_repeat_icon"
"revanced_hide_player_flyout_menu_more_info" -> "about_key_icon"
"revanced_hide_player_flyout_menu_quality_footer" -> "revanced_default_video_quality_wifi_icon"
"revanced_hide_player_flyout_menu_pip" -> "offline_key_icon"
"revanced_hide_player_flyout_menu_premium_controls" -> "premium_early_access_browse_page_key_icon"
"revanced_hide_player_flyout_menu_quality_header" -> "revanced_default_video_quality_wifi_icon"
"revanced_hide_player_flyout_menu_report" -> "revanced_hide_report_button_icon"
"revanced_hide_player_fullscreen_button" -> "revanced_preference_screen_fullscreen_icon"
"revanced_hide_quick_actions_dislike_button" -> "revanced_preference_screen_ryd_icon"
Expand All @@ -362,6 +419,9 @@ object VisualPreferencesIconsPatch : BaseResourcePatch(
"revanced_hide_shorts_shelf_home_related_videos" -> "revanced_hide_navigation_home_button_icon"
"revanced_hide_shorts_shelf_subscriptions" -> "revanced_hide_navigation_subscriptions_button_icon"
"revanced_hide_shorts_toolbar" -> "revanced_preference_screen_toolbar_icon"
"revanced_hide_toolbar_cast_button" -> "revanced_hide_player_cast_button_icon"
"revanced_hide_toolbar_create_button" -> "revanced_hide_navigation_create_button_icon"
"revanced_hide_toolbar_notification_button" -> "notification_key_icon"
"revanced_preference_screen_account_menu" -> "account_switcher_key_icon"
"revanced_preference_screen_channel_bar" -> "account_switcher_key_icon"
"revanced_preference_screen_channel_profile" -> "account_switcher_key_icon"
Expand All @@ -372,13 +432,15 @@ object VisualPreferencesIconsPatch : BaseResourcePatch(
"revanced_preference_screen_patch_information" -> "about_key_icon"
"revanced_preference_screen_shorts_player" -> "revanced_preference_screen_shorts_icon"
"revanced_preference_screen_video_filter" -> "revanced_preference_screen_video_icon"
"revanced_preference_screen_watch_history" -> "history_key_icon"
"revanced_swipe_gestures_lock_mode" -> "revanced_hide_player_flyout_menu_lock_screen_icon"
"revanced_disable_hdr_auto_brightness" -> "revanced_disable_hdr_video_icon"
else -> "${title}_icon"
}
}

private lateinit var preferenceIcon: Map<String, String>
private val intentIcon = intentKey.associateWith { "${it}_icon" }
private const val emptyIcon = "empty_icon"

// endregion.

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<vector
xmlns:android="http://schemas.android.com/apk/res/android"
android:name="vector"
android:width="48dp"
android:height="48dp"
android:viewportWidth="960"
android:viewportHeight="960">
<group
android:scaleX="0.5"
android:scaleY="0.5"
android:pivotX="480"
android:pivotY="480">
<path
android:name="path"
android:pathData="M 388.351 504.732 C 389.685 483.86 397.531 468.552 411.89 458.809 L 706.121 252.116 L 499.351 546.501 C 490.121 560.501 474.851 568.257 453.543 569.77 C 432.236 571.283 415.71 566.04 403.966 554.04 C 392.223 542.039 387.018 525.603 388.351 504.732 Z M 443.79 133.952 C 480.252 133.952 514.791 138.836 547.406 148.605 C 580.022 158.374 612.509 174.157 644.867 195.952 L 619.021 216.029 C 592.098 198.593 563.521 185.683 533.29 177.298 C 503.06 168.913 473.29 164.721 443.982 164.721 C 352.756 164.721 275.25 196.934 211.466 261.36 C 147.682 325.786 115.79 403.821 115.79 495.465 C 115.79 524.405 119.701 553.311 127.521 582.183 C 135.342 611.054 146.731 637.977 161.688 662.952 L 543.819 662.952 C 548.08 674.91 555.02 685.448 563.853 693.721 L 163.175 693.721 C 157.413 693.721 151.742 692.042 146.161 688.683 C 140.581 685.324 136.149 680.618 132.867 674.567 C 119.637 650.772 108.355 624.298 99.021 595.144 C 89.688 565.99 85.021 532.746 85.021 495.413 C 85.021 446.234 94.347 399.742 112.999 355.939 C 131.651 312.136 157.074 273.828 189.268 241.016 C 221.462 208.204 259.478 182.157 303.316 162.875 C 347.154 143.593 393.979 133.952 443.79 133.952 Z M 774.467 412.847 C 766.903 381.796 754.249 353.629 736.505 328.347 L 757.044 302.501 C 779.3 338.296 794.582 371.565 802.89 402.308 C 802.963 402.579 803.036 402.851 803.109 403.123 C 792.96 406.195 783.516 410.223 774.998 415.049 C 774.823 414.316 774.646 413.582 774.467 412.847 Z M 762.978 475.278 L 874.978 475.278 L 874.978 527.578 L 793.518 527.578 L 793.518 743.348 C 793.518 767.548 785.788 787.381 770.328 802.848 C 754.868 818.314 735.175 826.048 711.248 826.048 C 687.322 826.048 667.615 818.318 652.128 802.858 C 636.642 787.398 628.898 767.704 628.898 743.778 C 628.898 719.851 636.632 700.144 652.098 684.658 C 667.565 669.171 687.398 661.428 711.598 661.428 C 722.418 661.428 732.238 663.018 741.058 666.198 C 749.878 669.378 757.185 674.148 762.978 680.508 L 762.978 475.278 Z"
android:fillColor="?ytTextPrimary" />
</group>
</vector>
Loading

0 comments on commit 5e4b56c

Please sign in to comment.