From 2801d00569ce4ac364c22c8e9209f02e38bc38f1 Mon Sep 17 00:00:00 2001 From: Aunali321 Date: Tue, 19 Dec 2023 00:05:43 +0530 Subject: [PATCH 1/4] feat(YouTube): Make `addControls` method from `BottomControlsResourcePatch` patch public --- .../misc/playercontrols/BottomControlsResourcePatch.kt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/kotlin/app/revanced/patches/youtube/misc/playercontrols/BottomControlsResourcePatch.kt b/src/main/kotlin/app/revanced/patches/youtube/misc/playercontrols/BottomControlsResourcePatch.kt index c602faa481..7d2f12e829 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/misc/playercontrols/BottomControlsResourcePatch.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/misc/playercontrols/BottomControlsResourcePatch.kt @@ -11,7 +11,7 @@ import java.io.Closeable object BottomControlsResourcePatch : ResourcePatch(), Closeable { internal var bottomUiContainerResourceId: Long = -1 - internal const val TARGET_RESOURCE_NAME = "youtube_controls_bottom_ui_container.xml" + const val TARGET_RESOURCE_NAME = "youtube_controls_bottom_ui_container.xml" private const val TARGET_RESOURCE = "res/layout/$TARGET_RESOURCE_NAME" private lateinit var resourceContext: ResourceContext @@ -32,7 +32,7 @@ object BottomControlsResourcePatch : ResourcePatch(), Closeable { * Add new controls to the bottom of the YouTube player. * @param hostYouTubeControlsBottomUiResourceName The hosting resource name containing the elements. */ - internal fun addControls(hostYouTubeControlsBottomUiResourceName: String) { + fun addControls(hostYouTubeControlsBottomUiResourceName: String) { val sourceXmlEditor = resourceContext.xmlEditor[this::class.java.classLoader.getResourceAsStream( hostYouTubeControlsBottomUiResourceName From 974cade7aebf6d662291d2960750a4aa85e3f171 Mon Sep 17 00:00:00 2001 From: Aunali321 Date: Tue, 19 Dec 2023 00:11:25 +0530 Subject: [PATCH 2/4] chore: run apiDump task --- api/revanced-patches.api | 2 ++ 1 file changed, 2 insertions(+) diff --git a/api/revanced-patches.api b/api/revanced-patches.api index 50d757f7f7..3186b14979 100644 --- a/api/revanced-patches.api +++ b/api/revanced-patches.api @@ -1464,6 +1464,8 @@ public final class app/revanced/patches/youtube/misc/minimizedplayback/Minimized public final class app/revanced/patches/youtube/misc/playercontrols/BottomControlsResourcePatch : app/revanced/patcher/patch/ResourcePatch, java/io/Closeable { public static final field INSTANCE Lapp/revanced/patches/youtube/misc/playercontrols/BottomControlsResourcePatch; + public static final field TARGET_RESOURCE_NAME Ljava/lang/String; + public final fun addControls (Ljava/lang/String;)V public fun close ()V public synthetic fun execute (Lapp/revanced/patcher/data/Context;)V public fun execute (Lapp/revanced/patcher/data/ResourceContext;)V From c48de9dff9f58fc89076d5afea4a136f7b1ca4ed Mon Sep 17 00:00:00 2001 From: oSumAtrIX Date: Mon, 18 Dec 2023 20:03:05 +0100 Subject: [PATCH 3/4] refactor: Eliminate the necessity of supplying the target resource name --- api/revanced-patches.api | 1 - .../copyvideourl/CopyVideoUrlResourcePatch.kt | 29 +++++++++----- .../ExternalDownloadsResourcePatch.kt | 27 ++++++++----- .../BottomControlsResourcePatch.kt | 40 +++++++++---------- 4 files changed, 56 insertions(+), 41 deletions(-) diff --git a/api/revanced-patches.api b/api/revanced-patches.api index 3186b14979..adf3015203 100644 --- a/api/revanced-patches.api +++ b/api/revanced-patches.api @@ -1464,7 +1464,6 @@ public final class app/revanced/patches/youtube/misc/minimizedplayback/Minimized public final class app/revanced/patches/youtube/misc/playercontrols/BottomControlsResourcePatch : app/revanced/patcher/patch/ResourcePatch, java/io/Closeable { public static final field INSTANCE Lapp/revanced/patches/youtube/misc/playercontrols/BottomControlsResourcePatch; - public static final field TARGET_RESOURCE_NAME Ljava/lang/String; public final fun addControls (Ljava/lang/String;)V public fun close ()V public synthetic fun execute (Lapp/revanced/patcher/data/Context;)V diff --git a/src/main/kotlin/app/revanced/patches/youtube/interaction/copyvideourl/CopyVideoUrlResourcePatch.kt b/src/main/kotlin/app/revanced/patches/youtube/interaction/copyvideourl/CopyVideoUrlResourcePatch.kt index f057096a6c..cb03d0f828 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/interaction/copyvideourl/CopyVideoUrlResourcePatch.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/interaction/copyvideourl/CopyVideoUrlResourcePatch.kt @@ -28,30 +28,39 @@ internal object CopyVideoUrlResourcePatch : ResourcePatch() { SwitchPreference( "revanced_copy_video_url", StringResource("revanced_copy_video_url_title", "Show copy video URL button"), - StringResource("revanced_copy_video_url_summary_on", "Button is shown. Tap to copy video URL. Tap and hold to copy video URL with timestamp"), + StringResource( + "revanced_copy_video_url_summary_on", + "Button is shown. Tap to copy video URL. Tap and hold to copy video URL with timestamp" + ), StringResource("revanced_copy_video_url_summary_off", "Button is not shown") ), SwitchPreference( "revanced_copy_video_url_timestamp", StringResource("revanced_copy_video_url_timestamp_title", "Show copy timestamp URL button"), - StringResource("revanced_copy_video_url_timestamp_summary_on", "Button is shown. Tap to copy video URL with timestamp. Tap and hold to copy video without timestamp"), + StringResource( + "revanced_copy_video_url_timestamp_summary_on", + "Button is shown. Tap to copy video URL with timestamp. Tap and hold to copy video without timestamp" + ), StringResource("revanced_copy_video_url_timestamp_summary_off", "Button is not shown") ) ), - StringResource("revanced_copy_video_url_preference_screen_summary", "Settings related to copy URL buttons in video player") + StringResource( + "revanced_copy_video_url_preference_screen_summary", + "Settings related to copy URL buttons in video player" + ) ) ) - context.copyResources("copyvideourl", ResourceGroup( - resourceDirectoryName = "drawable", - "revanced_yt_copy.xml", - "revanced_yt_copy_timestamp.xml" - ) + context.copyResources( + "copyvideourl", ResourceGroup( + resourceDirectoryName = "drawable", + "revanced_yt_copy.xml", + "revanced_yt_copy_timestamp.xml" + ) ) - // merge strings context.mergeStrings("copyvideourl/host/values/strings.xml") - BottomControlsResourcePatch.addControls("copyvideourl/host/layout/${BottomControlsResourcePatch.TARGET_RESOURCE_NAME}") + BottomControlsResourcePatch.addControls("copyvideourl") } } \ No newline at end of file diff --git a/src/main/kotlin/app/revanced/patches/youtube/interaction/downloads/ExternalDownloadsResourcePatch.kt b/src/main/kotlin/app/revanced/patches/youtube/interaction/downloads/ExternalDownloadsResourcePatch.kt index 852693b3da..bd919503c0 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/interaction/downloads/ExternalDownloadsResourcePatch.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/interaction/downloads/ExternalDownloadsResourcePatch.kt @@ -28,27 +28,36 @@ internal object ExternalDownloadsResourcePatch : ResourcePatch() { "revanced_external_downloader", StringResource("revanced_external_downloader_title", "Show external download button"), StringResource("revanced_external_downloader_summary_on", "Download button shown in player"), - StringResource("revanced_external_downloader_summary_off", "Download button not shown in player") + StringResource( + "revanced_external_downloader_summary_off", + "Download button not shown in player" + ) ), TextPreference( "revanced_external_downloader_name", StringResource("revanced_external_downloader_name_title", "Downloader package name"), - StringResource("revanced_external_downloader_name_summary", "Package name of your installed external downloader app, such as NewPipe or Seal"), + StringResource( + "revanced_external_downloader_name_summary", + "Package name of your installed external downloader app, such as NewPipe or Seal" + ), InputType.TEXT ) ), - StringResource("revanced_external_downloader_preference_screen_summary", "Settings for using an external downloader") + StringResource( + "revanced_external_downloader_preference_screen_summary", + "Settings for using an external downloader" + ) ) ) - - // Copy strings context.mergeStrings("downloads/host/values/strings.xml") - // Copy resources - context.copyResources("downloads", ResourceGroup("drawable", "revanced_yt_download_button.xml")) + context.copyResources( + "downloads", + ResourceGroup("drawable", "revanced_yt_download_button.xml") + ) - // Add download button node - BottomControlsResourcePatch.addControls("downloads/host/layout/${BottomControlsResourcePatch.TARGET_RESOURCE_NAME}") + // Add download button node. + BottomControlsResourcePatch.addControls("downloads") } } diff --git a/src/main/kotlin/app/revanced/patches/youtube/misc/playercontrols/BottomControlsResourcePatch.kt b/src/main/kotlin/app/revanced/patches/youtube/misc/playercontrols/BottomControlsResourcePatch.kt index 7d2f12e829..23afdbb0cf 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/misc/playercontrols/BottomControlsResourcePatch.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/misc/playercontrols/BottomControlsResourcePatch.kt @@ -11,15 +11,15 @@ import java.io.Closeable object BottomControlsResourcePatch : ResourcePatch(), Closeable { internal var bottomUiContainerResourceId: Long = -1 - const val TARGET_RESOURCE_NAME = "youtube_controls_bottom_ui_container.xml" + private const val TARGET_RESOURCE_NAME = "youtube_controls_bottom_ui_container.xml" private const val TARGET_RESOURCE = "res/layout/$TARGET_RESOURCE_NAME" + // The element to the left of the element being added. + private var lastLeftOf = "fullscreen_button" + private lateinit var resourceContext: ResourceContext private lateinit var targetXmlEditor: DomFileEditor - // The element to which to add the new elements to - private var lastLeftOf = "fullscreen_button" - override fun execute(context: ResourceContext) { resourceContext = context targetXmlEditor = context.xmlEditor[TARGET_RESOURCE] @@ -30,46 +30,44 @@ object BottomControlsResourcePatch : ResourcePatch(), Closeable { /** * Add new controls to the bottom of the YouTube player. - * @param hostYouTubeControlsBottomUiResourceName The hosting resource name containing the elements. + * + * @param resourceDirectoryName The name of the directory containing the hosting resource. */ - fun addControls(hostYouTubeControlsBottomUiResourceName: String) { - val sourceXmlEditor = - resourceContext.xmlEditor[this::class.java.classLoader.getResourceAsStream( - hostYouTubeControlsBottomUiResourceName - )!!] + fun addControls(resourceDirectoryName: String) { + val sourceXmlEditor = resourceContext.xmlEditor[ + this::class.java.classLoader.getResourceAsStream( + "$resourceDirectoryName/host/layout/$TARGET_RESOURCE_NAME" + )!! + ] - val targetElement = - "android.support.constraint.ConstraintLayout" + val targetElement = "android.support.constraint.ConstraintLayout" val hostElements = sourceXmlEditor.file.getElementsByTagName(targetElement).item(0).childNodes val destinationResourceFile = targetXmlEditor.file - val destinationElement = - destinationResourceFile.getElementsByTagName(targetElement).item(0) + val destinationElement = destinationResourceFile.getElementsByTagName(targetElement).item(0) for (index in 1 until hostElements.length) { val element = hostElements.item(index).cloneNode(true) - // if the element has no attributes theres no point to adding it to the destination + // If the element has no attributes there's no point to adding it to the destination. if (!element.hasAttributes()) continue - // set the elements lastLeftOf attribute to the lastLeftOf value + // Set the elements lastLeftOf attribute to the lastLeftOf value. val namespace = "@+id" element.attributes.getNamedItem("yt:layout_constraintRight_toLeftOf").nodeValue = "$namespace/$lastLeftOf" - // set lastLeftOf attribute to the current element + // Set lastLeftOf attribute to the current element. val nameSpaceLength = 5 lastLeftOf = element.attributes.getNamedItem("android:id").nodeValue.substring(nameSpaceLength) - // copy the element + // Add the element. destinationResourceFile.adoptNode(element) destinationElement.appendChild(element) } sourceXmlEditor.close() } - override fun close() { - targetXmlEditor.close() - } + override fun close() = targetXmlEditor.close() } From 79148455792390bcae1ed9bca6b7221d30ea5923 Mon Sep 17 00:00:00 2001 From: oSumAtrIX Date: Mon, 18 Dec 2023 20:03:58 +0100 Subject: [PATCH 4/4] Update src/main/kotlin/app/revanced/patches/youtube/interaction/downloads/ExternalDownloadsResourcePatch.kt --- .../interaction/downloads/ExternalDownloadsResourcePatch.kt | 1 - 1 file changed, 1 deletion(-) diff --git a/src/main/kotlin/app/revanced/patches/youtube/interaction/downloads/ExternalDownloadsResourcePatch.kt b/src/main/kotlin/app/revanced/patches/youtube/interaction/downloads/ExternalDownloadsResourcePatch.kt index bd919503c0..3873a90972 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/interaction/downloads/ExternalDownloadsResourcePatch.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/interaction/downloads/ExternalDownloadsResourcePatch.kt @@ -57,7 +57,6 @@ internal object ExternalDownloadsResourcePatch : ResourcePatch() { ResourceGroup("drawable", "revanced_yt_download_button.xml") ) - // Add download button node. BottomControlsResourcePatch.addControls("downloads") } }