Skip to content

Commit 5e4b56c

Browse files
committed
feat(YouTube/Visual preferences icons): add the patch option ApplyToAll that do not apply to sub-settings inotia00/ReVanced_Extended#2392
1 parent bee0fb0 commit 5e4b56c

8 files changed

+216
-28
lines changed

src/main/kotlin/app/revanced/patches/youtube/layout/visual/VisualPreferencesIconsPatch.kt

Lines changed: 90 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,29 @@
11
package app.revanced.patches.youtube.layout.visual
22

33
import app.revanced.patcher.data.ResourceContext
4+
import app.revanced.patcher.patch.options.PatchOption.PatchExtensions.booleanPatchOption
45
import app.revanced.patcher.patch.options.PatchOption.PatchExtensions.stringPatchOption
56
import app.revanced.patches.youtube.layout.branding.icon.CustomBrandingIconPatch
67
import app.revanced.patches.youtube.utils.compatibility.Constants.COMPATIBLE_PACKAGE
78
import app.revanced.patches.youtube.utils.settings.SettingsPatch
89
import app.revanced.util.ResourceGroup
10+
import app.revanced.util.Utils.trimIndentMultiline
911
import app.revanced.util.copyResources
1012
import app.revanced.util.doRecursively
1113
import app.revanced.util.patch.BaseResourcePatch
1214
import app.revanced.util.underBarOrThrow
1315
import org.w3c.dom.Element
16+
import java.io.Closeable
1417

1518
@Suppress("DEPRECATION", "unused")
1619
object VisualPreferencesIconsPatch : BaseResourcePatch(
1720
name = "Visual preferences icons",
1821
description = "Adds icons to specific preferences in the settings.",
1922
dependencies = setOf(SettingsPatch::class),
20-
compatiblePackages = COMPATIBLE_PACKAGE,
21-
use = false
22-
) {
23+
compatiblePackages = COMPATIBLE_PACKAGE
24+
), Closeable {
2325
private const val DEFAULT_ICON = "extension"
26+
private const val EMPTY_ICON = "empty_icon"
2427

2528
private val RVXSettingsMenuIcon = stringPatchOption(
2629
key = "RVXSettingsMenuIcon",
@@ -37,7 +40,24 @@ object VisualPreferencesIconsPatch : BaseResourcePatch(
3740
required = true
3841
)
3942

43+
private val ApplyToAll by booleanPatchOption(
44+
key = "ApplyToAll",
45+
default = false,
46+
title = "Apply to all settings menu",
47+
description = """
48+
Whether to apply Visual preferences icons to all settings menus.
49+
50+
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).
51+
52+
If false: icons are applied only to the parent PreferenceScreen of YouTube settings and RVX settings.
53+
""".trimIndentMultiline(),
54+
required = true
55+
)
56+
57+
private lateinit var context: ResourceContext
58+
4059
override fun execute(context: ResourceContext) {
60+
this.context = context
4161

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

69+
if (ApplyToAll == true) {
70+
preferenceKey += rvxPreferenceKey
71+
}
72+
73+
preferenceIcon = preferenceKey.setPreferenceIcon()
74+
4975
// region copy shared resources.
5076

5177
arrayOf(
@@ -55,7 +81,7 @@ object VisualPreferencesIconsPatch : BaseResourcePatch(
5581
),
5682
ResourceGroup(
5783
"drawable-xxhdpi",
58-
"$emptyIcon.png"
84+
"$EMPTY_ICON.png"
5985
),
6086
).forEach { resourceGroup ->
6187
context.copyResources("youtube/visual/shared", resourceGroup)
@@ -90,6 +116,11 @@ object VisualPreferencesIconsPatch : BaseResourcePatch(
90116

91117
// endregion.
92118

119+
SettingsPatch.updatePatchStatus(this)
120+
}
121+
122+
override fun close() {
123+
93124
// region set visual preferences icon.
94125

95126
arrayOf(
@@ -109,9 +140,12 @@ object VisualPreferencesIconsPatch : BaseResourcePatch(
109140

110141
// Add custom RVX settings menu icon
111142
in intentKey -> intentIcon[title]
112-
in emptyTitles -> emptyIcon
143+
in emptyTitles -> EMPTY_ICON
113144
else -> null
114145
}
146+
if (drawableName == EMPTY_ICON &&
147+
ApplyToAll == false) return@loop
148+
115149
drawableName?.let {
116150
node.setAttribute("android:icon", "@drawable/$it")
117151
}
@@ -122,35 +156,34 @@ object VisualPreferencesIconsPatch : BaseResourcePatch(
122156

123157
// endregion.
124158

125-
SettingsPatch.updatePatchStatus(this)
126159
}
127160

128161
// region preference key and icon.
129162

130-
private val preferenceKey = setOf(
131-
// Main settings (sorted as displayed in the settings)
132-
"parent_tools_key",
133-
"general_key",
163+
private var preferenceKey = setOf(
164+
// YouTube settings.
165+
"about_key",
166+
"accessibility_settings_key",
134167
"account_switcher_key",
135-
"data_saving_settings_key",
136168
"auto_play_key",
137-
"video_quality_settings_key",
169+
"billing_and_payment_key",
170+
"captions_key",
171+
"connected_accounts_browse_page_key",
172+
"data_saving_settings_key",
173+
"general_key",
174+
"history_key",
175+
"live_chat_key",
176+
"notification_key",
138177
"offline_key",
139178
"pair_with_tv_key",
140-
"history_key",
141-
"your_data_key",
142-
"privacy_key",
179+
"parent_tools_key",
143180
"premium_early_access_browse_page_key",
181+
"privacy_key",
144182
"subscription_product_setting_key",
145-
"billing_and_payment_key",
146-
"notification_key",
147-
"connected_accounts_browse_page_key",
148-
"live_chat_key",
149-
"captions_key",
150-
"accessibility_settings_key",
151-
"about_key",
183+
"video_quality_settings_key",
184+
"your_data_key",
152185

153-
// Main RVX settings (sorted as displayed in the settings)
186+
// RVX settings.
154187
"revanced_preference_screen_ads",
155188
"revanced_preference_screen_alt_thumbnails",
156189
"revanced_preference_screen_feed",
@@ -162,7 +195,9 @@ object VisualPreferencesIconsPatch : BaseResourcePatch(
162195
"revanced_preference_screen_ryd",
163196
"revanced_preference_screen_sb",
164197
"revanced_preference_screen_misc",
198+
)
165199

200+
private var rvxPreferenceKey = setOf(
166201
// Internal RVX settings (items without prefix are listed first, others are sorted alphabetically)
167202
"gms_core_settings",
168203
"sb_enable_create_segment",
@@ -173,11 +208,13 @@ object VisualPreferencesIconsPatch : BaseResourcePatch(
173208
"revanced_alt_thumbnail_player",
174209
"revanced_alt_thumbnail_search",
175210
"revanced_alt_thumbnail_subscriptions",
211+
"revanced_change_share_sheet",
176212
"revanced_change_shorts_repeat_state",
177213
"revanced_custom_player_overlay_opacity",
178214
"revanced_default_app_settings",
179215
"revanced_default_playback_speed",
180216
"revanced_default_video_quality_wifi",
217+
"revanced_disable_default_playback_speed_music",
181218
"revanced_disable_hdr_auto_brightness",
182219
"revanced_disable_hdr_video",
183220
"revanced_disable_quic_protocol",
@@ -186,10 +223,13 @@ object VisualPreferencesIconsPatch : BaseResourcePatch(
186223
"revanced_enable_external_browser",
187224
"revanced_enable_old_quality_layout",
188225
"revanced_enable_open_links_directly",
226+
"revanced_enable_opus_codec",
227+
"revanced_enable_save_and_restore_brightness",
189228
"revanced_enable_swipe_brightness",
190229
"revanced_enable_swipe_haptic_feedback",
191230
"revanced_enable_swipe_lowest_value_auto_brightness",
192231
"revanced_enable_swipe_press_to_engage",
232+
"revanced_enable_swipe_to_switch_video",
193233
"revanced_enable_swipe_volume",
194234
"revanced_enable_watch_panel_gestures",
195235
"revanced_hide_clip_button",
@@ -213,11 +253,14 @@ object VisualPreferencesIconsPatch : BaseResourcePatch(
213253
"revanced_hide_player_flyout_menu_audio_track",
214254
"revanced_hide_player_flyout_menu_captions",
215255
"revanced_hide_player_flyout_menu_help",
256+
"revanced_hide_player_flyout_menu_listen_with_youtube_music",
216257
"revanced_hide_player_flyout_menu_lock_screen",
217258
"revanced_hide_player_flyout_menu_loop_video",
218259
"revanced_hide_player_flyout_menu_more_info",
260+
"revanced_hide_player_flyout_menu_pip",
261+
"revanced_hide_player_flyout_menu_premium_controls",
219262
"revanced_hide_player_flyout_menu_playback_speed",
220-
"revanced_hide_player_flyout_menu_quality_footer",
263+
"revanced_hide_player_flyout_menu_quality_header",
221264
"revanced_hide_player_flyout_menu_report",
222265
"revanced_hide_player_flyout_menu_stable_volume",
223266
"revanced_hide_player_flyout_menu_stats_for_nerds",
@@ -235,7 +278,9 @@ object VisualPreferencesIconsPatch : BaseResourcePatch(
235278
"revanced_hide_quick_actions_share_button",
236279
"revanced_hide_remix_button",
237280
"revanced_hide_report_button",
281+
"revanced_hide_rewards_button",
238282
"revanced_hide_share_button",
283+
"revanced_hide_shop_button",
239284
"revanced_hide_shorts_comments_button",
240285
"revanced_hide_shorts_dislike_button",
241286
"revanced_hide_shorts_like_button",
@@ -247,6 +292,10 @@ object VisualPreferencesIconsPatch : BaseResourcePatch(
247292
"revanced_hide_shorts_shelf_search",
248293
"revanced_hide_shorts_shelf_subscriptions",
249294
"revanced_hide_shorts_toolbar",
295+
"revanced_hide_thanks_button",
296+
"revanced_hide_toolbar_cast_button",
297+
"revanced_hide_toolbar_create_button",
298+
"revanced_hide_toolbar_notification_button",
250299
"revanced_overlay_button_always_repeat",
251300
"revanced_overlay_button_copy_video_url",
252301
"revanced_overlay_button_copy_video_url_timestamp",
@@ -280,6 +329,7 @@ object VisualPreferencesIconsPatch : BaseResourcePatch(
280329
"revanced_preference_screen_toolbar",
281330
"revanced_preference_screen_video_description",
282331
"revanced_preference_screen_video_filter",
332+
"revanced_preference_screen_watch_history",
283333
"revanced_sanitize_sharing_links",
284334
"revanced_swipe_gestures_lock_mode",
285335
"revanced_swipe_magnitude_threshold",
@@ -299,13 +349,16 @@ object VisualPreferencesIconsPatch : BaseResourcePatch(
299349
"revanced_custom_playback_speeds",
300350
"revanced_custom_playback_speed_menu_type",
301351
"revanced_default_video_quality_mobile",
352+
"revanced_disable_like_dislike_glow",
302353
"revanced_disable_default_playback_speed_live",
303354
"revanced_enable_custom_playback_speed",
304-
"revanced_external_downloader_package_name",
305355
"revanced_hide_shorts_comments_disabled_button",
306356
"revanced_hide_player_flyout_menu_captions_footer",
357+
"revanced_hide_player_flyout_menu_quality_footer",
307358
"revanced_remember_playback_speed_last_selected",
359+
"revanced_remember_playback_speed_last_selected_toast",
308360
"revanced_remember_video_quality_last_selected",
361+
"revanced_remember_video_quality_last_selected_toast",
309362
"revanced_restore_old_video_quality_menu",
310363
"revanced_enable_debug_buffer_logging",
311364
"revanced_whitelist_settings",
@@ -314,7 +367,7 @@ object VisualPreferencesIconsPatch : BaseResourcePatch(
314367
// A lot of mappings here.
315368
// The performance impact should be negligible in this context,
316369
// as the operations involved are not computationally intensive.
317-
private val preferenceIcon = preferenceKey.associateWith { title ->
370+
private fun Set<String>.setPreferenceIcon() = associateWith { title ->
318371
when (title) {
319372
// Main RVX settings
320373
"revanced_preference_screen_general" -> "general_key_icon"
@@ -326,6 +379,7 @@ object VisualPreferencesIconsPatch : BaseResourcePatch(
326379
"revanced_alt_thumbnail_player" -> "revanced_preference_screen_player_icon"
327380
"revanced_alt_thumbnail_search" -> "revanced_hide_shorts_shelf_search_icon"
328381
"revanced_alt_thumbnail_subscriptions" -> "revanced_hide_navigation_subscriptions_button_icon"
382+
"revanced_change_share_sheet" -> "revanced_hide_shorts_share_button_icon"
329383
"revanced_custom_player_overlay_opacity" -> "revanced_swipe_overlay_background_alpha_icon"
330384
"revanced_default_app_settings" -> "revanced_preference_screen_settings_menu_icon"
331385
"revanced_default_playback_speed" -> "revanced_overlay_button_speed_dialog_icon"
@@ -344,9 +398,12 @@ object VisualPreferencesIconsPatch : BaseResourcePatch(
344398
"revanced_hide_player_captions_button" -> "captions_key_icon"
345399
"revanced_hide_player_flyout_menu_ambient_mode" -> "revanced_preference_screen_ambient_mode_icon"
346400
"revanced_hide_player_flyout_menu_captions" -> "captions_key_icon"
401+
"revanced_hide_player_flyout_menu_listen_with_youtube_music" -> "revanced_hide_player_youtube_music_button_icon"
347402
"revanced_hide_player_flyout_menu_loop_video" -> "revanced_overlay_button_always_repeat_icon"
348403
"revanced_hide_player_flyout_menu_more_info" -> "about_key_icon"
349-
"revanced_hide_player_flyout_menu_quality_footer" -> "revanced_default_video_quality_wifi_icon"
404+
"revanced_hide_player_flyout_menu_pip" -> "offline_key_icon"
405+
"revanced_hide_player_flyout_menu_premium_controls" -> "premium_early_access_browse_page_key_icon"
406+
"revanced_hide_player_flyout_menu_quality_header" -> "revanced_default_video_quality_wifi_icon"
350407
"revanced_hide_player_flyout_menu_report" -> "revanced_hide_report_button_icon"
351408
"revanced_hide_player_fullscreen_button" -> "revanced_preference_screen_fullscreen_icon"
352409
"revanced_hide_quick_actions_dislike_button" -> "revanced_preference_screen_ryd_icon"
@@ -362,6 +419,9 @@ object VisualPreferencesIconsPatch : BaseResourcePatch(
362419
"revanced_hide_shorts_shelf_home_related_videos" -> "revanced_hide_navigation_home_button_icon"
363420
"revanced_hide_shorts_shelf_subscriptions" -> "revanced_hide_navigation_subscriptions_button_icon"
364421
"revanced_hide_shorts_toolbar" -> "revanced_preference_screen_toolbar_icon"
422+
"revanced_hide_toolbar_cast_button" -> "revanced_hide_player_cast_button_icon"
423+
"revanced_hide_toolbar_create_button" -> "revanced_hide_navigation_create_button_icon"
424+
"revanced_hide_toolbar_notification_button" -> "notification_key_icon"
365425
"revanced_preference_screen_account_menu" -> "account_switcher_key_icon"
366426
"revanced_preference_screen_channel_bar" -> "account_switcher_key_icon"
367427
"revanced_preference_screen_channel_profile" -> "account_switcher_key_icon"
@@ -372,13 +432,15 @@ object VisualPreferencesIconsPatch : BaseResourcePatch(
372432
"revanced_preference_screen_patch_information" -> "about_key_icon"
373433
"revanced_preference_screen_shorts_player" -> "revanced_preference_screen_shorts_icon"
374434
"revanced_preference_screen_video_filter" -> "revanced_preference_screen_video_icon"
435+
"revanced_preference_screen_watch_history" -> "history_key_icon"
375436
"revanced_swipe_gestures_lock_mode" -> "revanced_hide_player_flyout_menu_lock_screen_icon"
376437
"revanced_disable_hdr_auto_brightness" -> "revanced_disable_hdr_video_icon"
377438
else -> "${title}_icon"
378439
}
379440
}
441+
442+
private lateinit var preferenceIcon: Map<String, String>
380443
private val intentIcon = intentKey.associateWith { "${it}_icon" }
381-
private const val emptyIcon = "empty_icon"
382444

383445
// endregion.
384446

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<vector
2+
xmlns:android="http://schemas.android.com/apk/res/android"
3+
android:name="vector"
4+
android:width="48dp"
5+
android:height="48dp"
6+
android:viewportWidth="960"
7+
android:viewportHeight="960">
8+
<group
9+
android:scaleX="0.5"
10+
android:scaleY="0.5"
11+
android:pivotX="480"
12+
android:pivotY="480">
13+
<path
14+
android:name="path"
15+
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"
16+
android:fillColor="?ytTextPrimary" />
17+
</group>
18+
</vector>

0 commit comments

Comments
 (0)