From e3f3d8a3b8cdb937ae7219bb1ac2ae40e688c331 Mon Sep 17 00:00:00 2001 From: MondayNitro <87489540+MondayNitro@users.noreply.github.com> Date: Fri, 31 Jan 2025 08:17:30 +0530 Subject: [PATCH] feat(YouTube - Snack bar components): Add patch option `Apply corner radius to playlist bottom bar` (#137) * add corner radius for under player snackbar and open playlist bar * fix build error * feat: Add patch option `Apply corner radius to playlist bottom bar` --------- Co-authored-by: inotia00 <108592928+inotia00@users.noreply.github.com> --- .../snackbar/SnackBarComponentsPatch.kt | 32 +++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/patches/src/main/kotlin/app/revanced/patches/youtube/general/snackbar/SnackBarComponentsPatch.kt b/patches/src/main/kotlin/app/revanced/patches/youtube/general/snackbar/SnackBarComponentsPatch.kt index 5175a04ec..71c3e7436 100644 --- a/patches/src/main/kotlin/app/revanced/patches/youtube/general/snackbar/SnackBarComponentsPatch.kt +++ b/patches/src/main/kotlin/app/revanced/patches/youtube/general/snackbar/SnackBarComponentsPatch.kt @@ -5,6 +5,7 @@ import app.revanced.patcher.extensions.InstructionExtensions.addInstructions import app.revanced.patcher.extensions.InstructionExtensions.addInstructionsWithLabels import app.revanced.patcher.extensions.InstructionExtensions.getInstruction import app.revanced.patcher.extensions.InstructionExtensions.replaceInstruction +import app.revanced.patcher.patch.booleanOption import app.revanced.patcher.patch.bytecodePatch import app.revanced.patcher.patch.resourcePatch import app.revanced.patcher.patch.stringOption @@ -212,6 +213,14 @@ val snackBarComponentsPatch = resourcePatch( required = true, ) + val applyCornerRadiusToPlaylistBottomBarOption by booleanOption( + key = "applyCornerRadiusToPlaylistBottomBar", + default = false, + title = "Apply corner radius to playlist bottom bar", + description = "Whether to apply the same corner radius to the bottom bar of the playlist as the snack bar.", + required = true + ) + val darkThemeBackgroundColor = stringOption( key = "darkThemeBackgroundColor", default = ytBackgroundColorDark, @@ -248,6 +257,8 @@ val snackBarComponentsPatch = resourcePatch( // Check patch options first. val cornerRadius = cornerRadiusOption .valueOrThrow() + val applyCornerRadiusToPlaylistBottomBar = + applyCornerRadiusToPlaylistBottomBarOption == true val darkThemeColor = darkThemeBackgroundColor .valueOrThrow() val lightThemeColor = lightThemeBackgroundColor @@ -326,6 +337,27 @@ val snackBarComponentsPatch = resourcePatch( } } + document("res/values/dimens.xml").use { document -> + val resourcesNode = document.getElementsByTagName("resources").item(0) as Element + + for (i in 0 until resourcesNode.childNodes.length) { + val node = resourcesNode.childNodes.item(i) as? Element ?: continue + val dimenName = node.getAttribute("name") + + if (dimenName.equals("snackbar_corner_radius")) { + node.textContent = cornerRadius + } + } + } + + if (applyCornerRadiusToPlaylistBottomBar) { + document("res/drawable/playlist_entry_point_corner_drawable.xml").use { document -> + document.getNode("corners").apply { + attributes.getNamedItem("android:radius").nodeValue = cornerRadius + } + } + } + // region add settings addPreference(