1
1
package app.revanced.patches.youtube.layout.visual
2
2
3
3
import app.revanced.patcher.data.ResourceContext
4
+ import app.revanced.patcher.patch.options.PatchOption.PatchExtensions.booleanPatchOption
4
5
import app.revanced.patcher.patch.options.PatchOption.PatchExtensions.stringPatchOption
5
6
import app.revanced.patches.youtube.layout.branding.icon.CustomBrandingIconPatch
6
7
import app.revanced.patches.youtube.utils.compatibility.Constants.COMPATIBLE_PACKAGE
7
8
import app.revanced.patches.youtube.utils.settings.SettingsPatch
8
9
import app.revanced.util.ResourceGroup
10
+ import app.revanced.util.Utils.trimIndentMultiline
9
11
import app.revanced.util.copyResources
10
12
import app.revanced.util.doRecursively
11
13
import app.revanced.util.patch.BaseResourcePatch
12
14
import app.revanced.util.underBarOrThrow
13
15
import org.w3c.dom.Element
16
+ import java.io.Closeable
14
17
15
18
@Suppress(" DEPRECATION" , " unused" )
16
19
object VisualPreferencesIconsPatch : BaseResourcePatch(
17
20
name = " Visual preferences icons" ,
18
21
description = " Adds icons to specific preferences in the settings." ,
19
22
dependencies = setOf(SettingsPatch ::class),
20
- compatiblePackages = COMPATIBLE_PACKAGE ,
21
- use = false
22
- ) {
23
+ compatiblePackages = COMPATIBLE_PACKAGE
24
+ ), Closeable {
23
25
private const val DEFAULT_ICON = " extension"
26
+ private const val EMPTY_ICON = " empty_icon"
24
27
25
28
private val RVXSettingsMenuIcon = stringPatchOption(
26
29
key = " RVXSettingsMenuIcon" ,
@@ -37,7 +40,24 @@ object VisualPreferencesIconsPatch : BaseResourcePatch(
37
40
required = true
38
41
)
39
42
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
+
40
59
override fun execute (context : ResourceContext ) {
60
+ this .context = context
41
61
42
62
// Check patch options first.
43
63
val selectedIconType = RVXSettingsMenuIcon
@@ -46,6 +66,12 @@ object VisualPreferencesIconsPatch : BaseResourcePatch(
46
66
val customBrandingIconType = CustomBrandingIconPatch .AppIcon
47
67
.underBarOrThrow()
48
68
69
+ if (ApplyToAll == true ) {
70
+ preferenceKey + = rvxPreferenceKey
71
+ }
72
+
73
+ preferenceIcon = preferenceKey.setPreferenceIcon()
74
+
49
75
// region copy shared resources.
50
76
51
77
arrayOf(
@@ -55,7 +81,7 @@ object VisualPreferencesIconsPatch : BaseResourcePatch(
55
81
),
56
82
ResourceGroup (
57
83
" drawable-xxhdpi" ,
58
- " $emptyIcon .png"
84
+ " $EMPTY_ICON .png"
59
85
),
60
86
).forEach { resourceGroup ->
61
87
context.copyResources(" youtube/visual/shared" , resourceGroup)
@@ -90,6 +116,11 @@ object VisualPreferencesIconsPatch : BaseResourcePatch(
90
116
91
117
// endregion.
92
118
119
+ SettingsPatch .updatePatchStatus(this )
120
+ }
121
+
122
+ override fun close () {
123
+
93
124
// region set visual preferences icon.
94
125
95
126
arrayOf(
@@ -109,9 +140,12 @@ object VisualPreferencesIconsPatch : BaseResourcePatch(
109
140
110
141
// Add custom RVX settings menu icon
111
142
in intentKey -> intentIcon[title]
112
- in emptyTitles -> emptyIcon
143
+ in emptyTitles -> EMPTY_ICON
113
144
else -> null
114
145
}
146
+ if (drawableName == EMPTY_ICON &&
147
+ ApplyToAll == false ) return @loop
148
+
115
149
drawableName?.let {
116
150
node.setAttribute(" android:icon" , " @drawable/$it " )
117
151
}
@@ -122,35 +156,34 @@ object VisualPreferencesIconsPatch : BaseResourcePatch(
122
156
123
157
// endregion.
124
158
125
- SettingsPatch .updatePatchStatus(this )
126
159
}
127
160
128
161
// region preference key and icon.
129
162
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 " ,
134
167
" account_switcher_key" ,
135
- " data_saving_settings_key" ,
136
168
" 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" ,
138
177
" offline_key" ,
139
178
" pair_with_tv_key" ,
140
- " history_key" ,
141
- " your_data_key" ,
142
- " privacy_key" ,
179
+ " parent_tools_key" ,
143
180
" premium_early_access_browse_page_key" ,
181
+ " privacy_key" ,
144
182
" 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" ,
152
185
153
- // Main RVX settings (sorted as displayed in the settings)
186
+ // RVX settings.
154
187
" revanced_preference_screen_ads" ,
155
188
" revanced_preference_screen_alt_thumbnails" ,
156
189
" revanced_preference_screen_feed" ,
@@ -162,7 +195,9 @@ object VisualPreferencesIconsPatch : BaseResourcePatch(
162
195
" revanced_preference_screen_ryd" ,
163
196
" revanced_preference_screen_sb" ,
164
197
" revanced_preference_screen_misc" ,
198
+ )
165
199
200
+ private var rvxPreferenceKey = setOf (
166
201
// Internal RVX settings (items without prefix are listed first, others are sorted alphabetically)
167
202
" gms_core_settings" ,
168
203
" sb_enable_create_segment" ,
@@ -173,11 +208,13 @@ object VisualPreferencesIconsPatch : BaseResourcePatch(
173
208
" revanced_alt_thumbnail_player" ,
174
209
" revanced_alt_thumbnail_search" ,
175
210
" revanced_alt_thumbnail_subscriptions" ,
211
+ " revanced_change_share_sheet" ,
176
212
" revanced_change_shorts_repeat_state" ,
177
213
" revanced_custom_player_overlay_opacity" ,
178
214
" revanced_default_app_settings" ,
179
215
" revanced_default_playback_speed" ,
180
216
" revanced_default_video_quality_wifi" ,
217
+ " revanced_disable_default_playback_speed_music" ,
181
218
" revanced_disable_hdr_auto_brightness" ,
182
219
" revanced_disable_hdr_video" ,
183
220
" revanced_disable_quic_protocol" ,
@@ -186,10 +223,13 @@ object VisualPreferencesIconsPatch : BaseResourcePatch(
186
223
" revanced_enable_external_browser" ,
187
224
" revanced_enable_old_quality_layout" ,
188
225
" revanced_enable_open_links_directly" ,
226
+ " revanced_enable_opus_codec" ,
227
+ " revanced_enable_save_and_restore_brightness" ,
189
228
" revanced_enable_swipe_brightness" ,
190
229
" revanced_enable_swipe_haptic_feedback" ,
191
230
" revanced_enable_swipe_lowest_value_auto_brightness" ,
192
231
" revanced_enable_swipe_press_to_engage" ,
232
+ " revanced_enable_swipe_to_switch_video" ,
193
233
" revanced_enable_swipe_volume" ,
194
234
" revanced_enable_watch_panel_gestures" ,
195
235
" revanced_hide_clip_button" ,
@@ -213,11 +253,14 @@ object VisualPreferencesIconsPatch : BaseResourcePatch(
213
253
" revanced_hide_player_flyout_menu_audio_track" ,
214
254
" revanced_hide_player_flyout_menu_captions" ,
215
255
" revanced_hide_player_flyout_menu_help" ,
256
+ " revanced_hide_player_flyout_menu_listen_with_youtube_music" ,
216
257
" revanced_hide_player_flyout_menu_lock_screen" ,
217
258
" revanced_hide_player_flyout_menu_loop_video" ,
218
259
" revanced_hide_player_flyout_menu_more_info" ,
260
+ " revanced_hide_player_flyout_menu_pip" ,
261
+ " revanced_hide_player_flyout_menu_premium_controls" ,
219
262
" revanced_hide_player_flyout_menu_playback_speed" ,
220
- " revanced_hide_player_flyout_menu_quality_footer " ,
263
+ " revanced_hide_player_flyout_menu_quality_header " ,
221
264
" revanced_hide_player_flyout_menu_report" ,
222
265
" revanced_hide_player_flyout_menu_stable_volume" ,
223
266
" revanced_hide_player_flyout_menu_stats_for_nerds" ,
@@ -235,7 +278,9 @@ object VisualPreferencesIconsPatch : BaseResourcePatch(
235
278
" revanced_hide_quick_actions_share_button" ,
236
279
" revanced_hide_remix_button" ,
237
280
" revanced_hide_report_button" ,
281
+ " revanced_hide_rewards_button" ,
238
282
" revanced_hide_share_button" ,
283
+ " revanced_hide_shop_button" ,
239
284
" revanced_hide_shorts_comments_button" ,
240
285
" revanced_hide_shorts_dislike_button" ,
241
286
" revanced_hide_shorts_like_button" ,
@@ -247,6 +292,10 @@ object VisualPreferencesIconsPatch : BaseResourcePatch(
247
292
" revanced_hide_shorts_shelf_search" ,
248
293
" revanced_hide_shorts_shelf_subscriptions" ,
249
294
" 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" ,
250
299
" revanced_overlay_button_always_repeat" ,
251
300
" revanced_overlay_button_copy_video_url" ,
252
301
" revanced_overlay_button_copy_video_url_timestamp" ,
@@ -280,6 +329,7 @@ object VisualPreferencesIconsPatch : BaseResourcePatch(
280
329
" revanced_preference_screen_toolbar" ,
281
330
" revanced_preference_screen_video_description" ,
282
331
" revanced_preference_screen_video_filter" ,
332
+ " revanced_preference_screen_watch_history" ,
283
333
" revanced_sanitize_sharing_links" ,
284
334
" revanced_swipe_gestures_lock_mode" ,
285
335
" revanced_swipe_magnitude_threshold" ,
@@ -299,13 +349,16 @@ object VisualPreferencesIconsPatch : BaseResourcePatch(
299
349
" revanced_custom_playback_speeds" ,
300
350
" revanced_custom_playback_speed_menu_type" ,
301
351
" revanced_default_video_quality_mobile" ,
352
+ " revanced_disable_like_dislike_glow" ,
302
353
" revanced_disable_default_playback_speed_live" ,
303
354
" revanced_enable_custom_playback_speed" ,
304
- " revanced_external_downloader_package_name" ,
305
355
" revanced_hide_shorts_comments_disabled_button" ,
306
356
" revanced_hide_player_flyout_menu_captions_footer" ,
357
+ " revanced_hide_player_flyout_menu_quality_footer" ,
307
358
" revanced_remember_playback_speed_last_selected" ,
359
+ " revanced_remember_playback_speed_last_selected_toast" ,
308
360
" revanced_remember_video_quality_last_selected" ,
361
+ " revanced_remember_video_quality_last_selected_toast" ,
309
362
" revanced_restore_old_video_quality_menu" ,
310
363
" revanced_enable_debug_buffer_logging" ,
311
364
" revanced_whitelist_settings" ,
@@ -314,7 +367,7 @@ object VisualPreferencesIconsPatch : BaseResourcePatch(
314
367
// A lot of mappings here.
315
368
// The performance impact should be negligible in this context,
316
369
// as the operations involved are not computationally intensive.
317
- private val preferenceIcon = preferenceKey. associateWith { title ->
370
+ private fun Set<String>. setPreferenceIcon () = associateWith { title ->
318
371
when (title) {
319
372
// Main RVX settings
320
373
" revanced_preference_screen_general" -> " general_key_icon"
@@ -326,6 +379,7 @@ object VisualPreferencesIconsPatch : BaseResourcePatch(
326
379
" revanced_alt_thumbnail_player" -> " revanced_preference_screen_player_icon"
327
380
" revanced_alt_thumbnail_search" -> " revanced_hide_shorts_shelf_search_icon"
328
381
" revanced_alt_thumbnail_subscriptions" -> " revanced_hide_navigation_subscriptions_button_icon"
382
+ " revanced_change_share_sheet" -> " revanced_hide_shorts_share_button_icon"
329
383
" revanced_custom_player_overlay_opacity" -> " revanced_swipe_overlay_background_alpha_icon"
330
384
" revanced_default_app_settings" -> " revanced_preference_screen_settings_menu_icon"
331
385
" revanced_default_playback_speed" -> " revanced_overlay_button_speed_dialog_icon"
@@ -344,9 +398,12 @@ object VisualPreferencesIconsPatch : BaseResourcePatch(
344
398
" revanced_hide_player_captions_button" -> " captions_key_icon"
345
399
" revanced_hide_player_flyout_menu_ambient_mode" -> " revanced_preference_screen_ambient_mode_icon"
346
400
" 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"
347
402
" revanced_hide_player_flyout_menu_loop_video" -> " revanced_overlay_button_always_repeat_icon"
348
403
" 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"
350
407
" revanced_hide_player_flyout_menu_report" -> " revanced_hide_report_button_icon"
351
408
" revanced_hide_player_fullscreen_button" -> " revanced_preference_screen_fullscreen_icon"
352
409
" revanced_hide_quick_actions_dislike_button" -> " revanced_preference_screen_ryd_icon"
@@ -362,6 +419,9 @@ object VisualPreferencesIconsPatch : BaseResourcePatch(
362
419
" revanced_hide_shorts_shelf_home_related_videos" -> " revanced_hide_navigation_home_button_icon"
363
420
" revanced_hide_shorts_shelf_subscriptions" -> " revanced_hide_navigation_subscriptions_button_icon"
364
421
" 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"
365
425
" revanced_preference_screen_account_menu" -> " account_switcher_key_icon"
366
426
" revanced_preference_screen_channel_bar" -> " account_switcher_key_icon"
367
427
" revanced_preference_screen_channel_profile" -> " account_switcher_key_icon"
@@ -372,13 +432,15 @@ object VisualPreferencesIconsPatch : BaseResourcePatch(
372
432
" revanced_preference_screen_patch_information" -> " about_key_icon"
373
433
" revanced_preference_screen_shorts_player" -> " revanced_preference_screen_shorts_icon"
374
434
" revanced_preference_screen_video_filter" -> " revanced_preference_screen_video_icon"
435
+ " revanced_preference_screen_watch_history" -> " history_key_icon"
375
436
" revanced_swipe_gestures_lock_mode" -> " revanced_hide_player_flyout_menu_lock_screen_icon"
376
437
" revanced_disable_hdr_auto_brightness" -> " revanced_disable_hdr_video_icon"
377
438
else -> " ${title} _icon"
378
439
}
379
440
}
441
+
442
+ private lateinit var preferenceIcon: Map <String , String >
380
443
private val intentIcon = intentKey.associateWith { " ${it} _icon" }
381
- private const val emptyIcon = " empty_icon"
382
444
383
445
// endregion.
384
446
0 commit comments