refactor(shared-resource-id): move resource type to enum

This commit is contained in:
inotia00 2023-04-08 05:09:09 +09:00
parent 9b3adf928c
commit 0079846a12
3 changed files with 52 additions and 36 deletions

View File

@ -9,6 +9,8 @@ import app.revanced.patcher.patch.ResourcePatch
import app.revanced.patcher.patch.annotations.DependsOn import app.revanced.patcher.patch.annotations.DependsOn
import app.revanced.patches.shared.annotation.YouTubeMusicCompatibility import app.revanced.patches.shared.annotation.YouTubeMusicCompatibility
import app.revanced.patches.shared.patch.mapping.ResourceMappingPatch import app.revanced.patches.shared.patch.mapping.ResourceMappingPatch
import app.revanced.util.enum.ResourceType
import app.revanced.util.enum.ResourceType.*
@Name("music-resource-id") @Name("music-resource-id")
@DependsOn([ResourceMappingPatch::class]) @DependsOn([ResourceMappingPatch::class])
@ -25,15 +27,15 @@ class SharedResourceIdPatch : ResourcePatch {
override fun execute(context: ResourceContext): PatchResult { override fun execute(context: ResourceContext): PatchResult {
fun findSharedResourceId(type: String, name: String) = ResourceMappingPatch fun find(type: ResourceType, name: String) = ResourceMappingPatch
.resourceMappings .resourceMappings
.single { it.type == type && it.name == name }.id .single { it.type == type.value && it.name == name }.id
colorGreyLabelId = findSharedResourceId("color", "ytm_color_grey_12") colorGreyLabelId = find(COLOR, "ytm_color_grey_12")
dialogSolidLabelId = findSharedResourceId("style", "Theme.YouTubeMusic.Dialog.Solid") dialogSolidLabelId = find(STYLE, "Theme.YouTubeMusic.Dialog.Solid")
disabledIconLabelId = findSharedResourceId("dimen", "disabled_icon_alpha") disabledIconLabelId = find(DIMEN, "disabled_icon_alpha")
floatingActionButtonLabelId = findSharedResourceId("id", "floating_action_button") floatingActionButtonLabelId = find(ID, "floating_action_button")
isTabletLabelId = findSharedResourceId("bool", "is_tablet") isTabletLabelId = find(BOOL, "is_tablet")
return PatchResultSuccess() return PatchResultSuccess()
} }

View File

@ -9,6 +9,8 @@ import app.revanced.patcher.patch.ResourcePatch
import app.revanced.patcher.patch.annotations.DependsOn import app.revanced.patcher.patch.annotations.DependsOn
import app.revanced.patches.shared.annotation.YouTubeCompatibility import app.revanced.patches.shared.annotation.YouTubeCompatibility
import app.revanced.patches.shared.patch.mapping.ResourceMappingPatch import app.revanced.patches.shared.patch.mapping.ResourceMappingPatch
import app.revanced.util.enum.ResourceType
import app.revanced.util.enum.ResourceType.*
@Name("shared-resource-id") @Name("shared-resource-id")
@DependsOn([ResourceMappingPatch::class]) @DependsOn([ResourceMappingPatch::class])
@ -47,37 +49,37 @@ class SharedResourceIdPatch : ResourcePatch {
override fun execute(context: ResourceContext): PatchResult { override fun execute(context: ResourceContext): PatchResult {
fun findSharedResourceId(type: String, name: String) = ResourceMappingPatch fun find(type: ResourceType, name: String) = ResourceMappingPatch
.resourceMappings .resourceMappings
.single { it.type == type && it.name == name }.id .single { it.type == type.value && it.name == name }.id
accessibilityProgressTimeLabelId = findSharedResourceId("string", "accessibility_player_progress_time") accessibilityProgressTimeLabelId = find(STRING, "accessibility_player_progress_time")
accountSwitcherAccessibilityLabelId = findSharedResourceId("string", "account_switcher_accessibility_label") accountSwitcherAccessibilityLabelId = find(STRING, "account_switcher_accessibility_label")
appearanceStringId = findSharedResourceId("string", "app_theme_appearance_dark") appearanceStringId = find(STRING, "app_theme_appearance_dark")
backgroundCategoryLabelId = findSharedResourceId("string", "pref_background_and_offline_category") backgroundCategoryLabelId = find(STRING, "pref_background_and_offline_category")
barContainerHeightLabelId = findSharedResourceId("dimen", "bar_container_height") barContainerHeightLabelId = find(DIMEN, "bar_container_height")
bottomUiContainerResourceId = findSharedResourceId("id", "bottom_ui_container_stub") bottomUiContainerResourceId = find(ID, "bottom_ui_container_stub")
channelListSubMenuLabelId = findSharedResourceId("layout", "channel_list_sub_menu") channelListSubMenuLabelId = find(LAYOUT, "channel_list_sub_menu")
chapterRepeatOnResourceId = findSharedResourceId("string", "chapter_repeat_on") chapterRepeatOnResourceId = find(STRING, "chapter_repeat_on")
compactLinkLabelId = findSharedResourceId("layout", "compact_link") compactLinkLabelId = find(LAYOUT, "compact_link")
controlsLayoutStubResourceId = findSharedResourceId("id", "controls_layout_stub") controlsLayoutStubResourceId = find(ID, "controls_layout_stub")
donationCompanionResourceId = findSharedResourceId("layout", "donation_companion") donationCompanionResourceId = find(LAYOUT, "donation_companion")
emptyColorLabelId = findSharedResourceId("color", "inline_time_bar_colorized_bar_empty_color_dark") emptyColorLabelId = find(COLOR, "inline_time_bar_colorized_bar_empty_color_dark")
fabLabelId = findSharedResourceId("id", "fab") fabLabelId = find(ID, "fab")
filterBarHeightLabelId = findSharedResourceId("dimen", "filter_bar_height") filterBarHeightLabelId = find(DIMEN, "filter_bar_height")
floatyBarQueueLabelId = findSharedResourceId("string", "floaty_bar_queue_status") floatyBarQueueLabelId = find(STRING, "floaty_bar_queue_status")
imageOnlyTabId = findSharedResourceId("layout", "image_only_tab") imageOnlyTabId = find(LAYOUT, "image_only_tab")
imageWithTextTabId = findSharedResourceId("layout", "image_with_text_tab") imageWithTextTabId = find(LAYOUT, "image_with_text_tab")
layoutCircle = findSharedResourceId("layout", "endscreen_element_layout_circle") layoutCircle = find(LAYOUT, "endscreen_element_layout_circle")
layoutIcon = findSharedResourceId("layout", "endscreen_element_layout_icon") layoutIcon = find(LAYOUT, "endscreen_element_layout_icon")
layoutVideo = findSharedResourceId("layout", "endscreen_element_layout_video") layoutVideo = find(LAYOUT, "endscreen_element_layout_video")
liveChatButtonId = findSharedResourceId("id", "live_chat_overlay_button") liveChatButtonId = find(ID, "live_chat_overlay_button")
reelPlayerFooterLabelId = findSharedResourceId("layout", "reel_player_dyn_footer_vert_stories3") reelPlayerFooterLabelId = find(LAYOUT, "reel_player_dyn_footer_vert_stories3")
relatedChipCloudMarginLabelId = findSharedResourceId("layout", "related_chip_cloud_reduced_margins") relatedChipCloudMarginLabelId = find(LAYOUT, "related_chip_cloud_reduced_margins")
scrubbingLabelId = findSharedResourceId("dimen", "vertical_touch_offset_to_enter_fine_scrubbing") scrubbingLabelId = find(DIMEN, "vertical_touch_offset_to_enter_fine_scrubbing")
timeStampsContainerLabelId = findSharedResourceId("id", "timestamps_container") timeStampsContainerLabelId = find(ID, "timestamps_container")
tooltipLabelId = findSharedResourceId("layout", "tooltip_content_view") tooltipLabelId = find(LAYOUT, "tooltip_content_view")
videoQualityFragmentLabelId = findSharedResourceId("layout", "video_quality_bottom_sheet_list_fragment_title") videoQualityFragmentLabelId = find(LAYOUT, "video_quality_bottom_sheet_list_fragment_title")
return PatchResultSuccess() return PatchResultSuccess()
} }

View File

@ -0,0 +1,12 @@
package app.revanced.util.enum
internal enum class ResourceType(val value: String) {
BOOL("bool"),
COLOR("color"),
DIMEN("dimen"),
DRAWABLE("drawable"),
ID("id"),
LAYOUT("layout"),
STRING("string"),
STYLE("style")
}