fix(YouTube - Custom Shorts action buttons): Patch not working on YouTube 19.38.41+

This commit is contained in:
inotia00 2024-12-21 14:02:28 +09:00
parent e48048b430
commit 749900f6f8

View File

@ -4,15 +4,30 @@ import app.revanced.patcher.patch.resourcePatch
import app.revanced.patcher.patch.stringOption import app.revanced.patcher.patch.stringOption
import app.revanced.patches.youtube.utils.compatibility.Constants.COMPATIBLE_PACKAGE import app.revanced.patches.youtube.utils.compatibility.Constants.COMPATIBLE_PACKAGE
import app.revanced.patches.youtube.utils.patch.PatchList.CUSTOM_SHORTS_ACTION_BUTTONS import app.revanced.patches.youtube.utils.patch.PatchList.CUSTOM_SHORTS_ACTION_BUTTONS
import app.revanced.patches.youtube.utils.playservice.is_19_36_or_greater
import app.revanced.patches.youtube.utils.playservice.versionCheckPatch
import app.revanced.patches.youtube.utils.settings.ResourceUtils.addPreference import app.revanced.patches.youtube.utils.settings.ResourceUtils.addPreference
import app.revanced.patches.youtube.utils.settings.settingsPatch import app.revanced.patches.youtube.utils.settings.settingsPatch
import app.revanced.util.ResourceGroup import app.revanced.util.ResourceGroup
import app.revanced.util.copyResources import app.revanced.util.copyResources
import app.revanced.util.inputStreamFromBundledResourceOrThrow
import app.revanced.util.lowerCaseOrThrow import app.revanced.util.lowerCaseOrThrow
import java.nio.file.Files
import java.nio.file.StandardCopyOption
private const val DEFAULT_ICON = "cairo" private const val DEFAULT_ICON = "cairo"
private const val YOUTUBE_ICON = "youtube" private const val YOUTUBE_ICON = "youtube"
private val sizeArray = arrayOf(
"xxxhdpi",
"xxhdpi",
"xhdpi",
"hdpi",
"mdpi"
)
private val drawableDirectories = sizeArray.map { "drawable-$it" }
@Suppress("unused") @Suppress("unused")
val shortsActionButtonsPatch = resourcePatch( val shortsActionButtonsPatch = resourcePatch(
CUSTOM_SHORTS_ACTION_BUTTONS.title, CUSTOM_SHORTS_ACTION_BUTTONS.title,
@ -20,9 +35,12 @@ val shortsActionButtonsPatch = resourcePatch(
) { ) {
compatibleWith(COMPATIBLE_PACKAGE) compatibleWith(COMPATIBLE_PACKAGE)
dependsOn(settingsPatch) dependsOn(
settingsPatch,
versionCheckPatch
)
val iconType = stringOption( val iconTypeOption = stringOption(
key = "iconType", key = "iconType",
default = DEFAULT_ICON, default = DEFAULT_ICON,
values = mapOf( values = mapOf(
@ -41,7 +59,7 @@ val shortsActionButtonsPatch = resourcePatch(
execute { execute {
// Check patch options first. // Check patch options first.
val iconType = iconType val iconType = iconTypeOption
.lowerCaseOrThrow() .lowerCaseOrThrow()
if (iconType == YOUTUBE_ICON) { if (iconType == YOUTUBE_ICON) {
@ -50,40 +68,41 @@ val shortsActionButtonsPatch = resourcePatch(
return@execute return@execute
} }
arrayOf( val sourceResourceDirectory = "youtube/shorts/actionbuttons/$iconType"
"xxxhdpi",
"xxhdpi",
"xhdpi",
"hdpi",
"mdpi"
).forEach { dpi ->
copyResources(
"youtube/shorts/actionbuttons/$iconType",
ResourceGroup(
"drawable-$dpi",
"ic_remix_filled_white_shadowed.webp",
"ic_right_comment_shadowed.webp",
"ic_right_dislike_off_shadowed.webp",
"ic_right_dislike_on_shadowed.webp",
"ic_right_like_off_shadowed.webp",
"ic_right_like_on_shadowed.webp",
"ic_right_share_shadowed.webp",
// for older versions only val resourceMap = ShortsActionButtons.entries.map { it.newResource to it.resources }
"ic_remix_filled_white_24.webp", val res = get("res")
"ic_right_dislike_on_32c.webp",
"ic_right_like_on_32c.webp" for ((toFileName, fromResourceArray) in resourceMap) {
), fromResourceArray.forEach { fromFileName ->
ResourceGroup( drawableDirectories.forEach { drawableDirectory ->
"drawable", val fromFile = "$drawableDirectory/$fromFileName.webp"
"ic_right_comment_32c.xml", val fromPath = res.resolve(fromFile).toPath()
"ic_right_dislike_off_32c.xml", val toFile = "$drawableDirectory/$toFileName.webp"
"ic_right_like_off_32c.xml", val toPath = res.resolve(toFile).toPath()
"ic_right_share_32c.xml" val inputStreamForLegacy = inputStreamFromBundledResourceOrThrow(sourceResourceDirectory, fromFile)
) val inputStreamForNew = inputStreamFromBundledResourceOrThrow(sourceResourceDirectory, fromFile)
)
Files.copy(inputStreamForLegacy, fromPath, StandardCopyOption.REPLACE_EXISTING)
if (is_19_36_or_greater) {
Files.copy(inputStreamForNew, toPath, StandardCopyOption.REPLACE_EXISTING)
}
}
}
} }
copyResources(
sourceResourceDirectory,
ResourceGroup(
"drawable",
"ic_right_comment_32c.xml",
"ic_right_dislike_off_32c.xml",
"ic_right_like_off_32c.xml",
"ic_right_share_32c.xml"
)
)
addPreference(CUSTOM_SHORTS_ACTION_BUTTONS) addPreference(CUSTOM_SHORTS_ACTION_BUTTONS)
if (iconType == DEFAULT_ICON) { if (iconType == DEFAULT_ICON) {
@ -99,6 +118,46 @@ val shortsActionButtonsPatch = resourcePatch(
"reel_search_bold_24dp.xml" "reel_search_bold_24dp.xml"
) )
) )
} }
} }
internal enum class ShortsActionButtons(val newResource: String, vararg val resources: String) {
LIKE(
"youtube_shorts_like_outline_32dp",
// This replaces the new icon.
"ic_right_like_off_shadowed",
),
LIKE_FILLED(
"youtube_shorts_like_fill_32dp",
"ic_right_like_on_32c",
// This replaces the new icon.
"ic_right_like_on_shadowed",
),
DISLIKE(
"youtube_shorts_dislike_outline_32dp",
// This replaces the new icon.
"ic_right_dislike_off_shadowed",
),
DISLIKE_FILLED(
"youtube_shorts_dislike_fill_32dp",
"ic_right_dislike_on_32c",
// This replaces the new icon.
"ic_right_dislike_on_shadowed",
),
COMMENT(
"youtube_shorts_comment_outline_32dp",
// This replaces the new icon.
"ic_right_comment_shadowed",
),
SHARE(
"youtube_shorts_share_outline_32dp",
// This replaces the new icon.
"ic_right_share_shadowed",
),
REMIX(
"youtube_shorts_remix_outline_32dp",
"ic_remix_filled_white_24",
// This replaces the new icon.
"ic_remix_filled_white_shadowed",
),
}