diff --git a/api/revanced-patches.api b/api/revanced-patches.api index 50d757f7..adf30152 100644 --- a/api/revanced-patches.api +++ b/api/revanced-patches.api @@ -1464,6 +1464,7 @@ 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 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 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 f057096a..cb03d0f8 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 852693b3..3873a909 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,35 @@ 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}") + 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 c602faa4..23afdbb0 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 - internal 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. */ - internal 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() }