feat(Public API): Make BottomControlsResource#addControls public (#2514)

Co-authored-by: oSumAtrIX <johan.melkonyan1@web.de>
This commit is contained in:
Aunali321 2023-12-19 00:36:20 +05:30 committed by GitHub
parent de4823c139
commit f4e2257072
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 56 additions and 40 deletions

View File

@ -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 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 INSTANCE Lapp/revanced/patches/youtube/misc/playercontrols/BottomControlsResourcePatch;
public final fun addControls (Ljava/lang/String;)V
public fun close ()V public fun close ()V
public synthetic fun execute (Lapp/revanced/patcher/data/Context;)V public synthetic fun execute (Lapp/revanced/patcher/data/Context;)V
public fun execute (Lapp/revanced/patcher/data/ResourceContext;)V public fun execute (Lapp/revanced/patcher/data/ResourceContext;)V

View File

@ -28,30 +28,39 @@ internal object CopyVideoUrlResourcePatch : ResourcePatch() {
SwitchPreference( SwitchPreference(
"revanced_copy_video_url", "revanced_copy_video_url",
StringResource("revanced_copy_video_url_title", "Show copy video URL button"), 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") StringResource("revanced_copy_video_url_summary_off", "Button is not shown")
), ),
SwitchPreference( SwitchPreference(
"revanced_copy_video_url_timestamp", "revanced_copy_video_url_timestamp",
StringResource("revanced_copy_video_url_timestamp_title", "Show copy timestamp URL button"), 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_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( context.copyResources(
resourceDirectoryName = "drawable", "copyvideourl", ResourceGroup(
"revanced_yt_copy.xml", resourceDirectoryName = "drawable",
"revanced_yt_copy_timestamp.xml" "revanced_yt_copy.xml",
) "revanced_yt_copy_timestamp.xml"
)
) )
// merge strings
context.mergeStrings("copyvideourl/host/values/strings.xml") context.mergeStrings("copyvideourl/host/values/strings.xml")
BottomControlsResourcePatch.addControls("copyvideourl/host/layout/${BottomControlsResourcePatch.TARGET_RESOURCE_NAME}") BottomControlsResourcePatch.addControls("copyvideourl")
} }
} }

View File

@ -28,27 +28,35 @@ internal object ExternalDownloadsResourcePatch : ResourcePatch() {
"revanced_external_downloader", "revanced_external_downloader",
StringResource("revanced_external_downloader_title", "Show external download button"), 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_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( TextPreference(
"revanced_external_downloader_name", "revanced_external_downloader_name",
StringResource("revanced_external_downloader_name_title", "Downloader package 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 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") context.mergeStrings("downloads/host/values/strings.xml")
// Copy resources context.copyResources(
context.copyResources("downloads", ResourceGroup("drawable", "revanced_yt_download_button.xml")) "downloads",
ResourceGroup("drawable", "revanced_yt_download_button.xml")
)
// Add download button node BottomControlsResourcePatch.addControls("downloads")
BottomControlsResourcePatch.addControls("downloads/host/layout/${BottomControlsResourcePatch.TARGET_RESOURCE_NAME}")
} }
} }

View File

@ -11,15 +11,15 @@ import java.io.Closeable
object BottomControlsResourcePatch : ResourcePatch(), Closeable { object BottomControlsResourcePatch : ResourcePatch(), Closeable {
internal var bottomUiContainerResourceId: Long = -1 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" 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 resourceContext: ResourceContext
private lateinit var targetXmlEditor: DomFileEditor 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) { override fun execute(context: ResourceContext) {
resourceContext = context resourceContext = context
targetXmlEditor = context.xmlEditor[TARGET_RESOURCE] targetXmlEditor = context.xmlEditor[TARGET_RESOURCE]
@ -30,46 +30,44 @@ object BottomControlsResourcePatch : ResourcePatch(), Closeable {
/** /**
* Add new controls to the bottom of the YouTube player. * 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) { fun addControls(resourceDirectoryName: String) {
val sourceXmlEditor = val sourceXmlEditor = resourceContext.xmlEditor[
resourceContext.xmlEditor[this::class.java.classLoader.getResourceAsStream( this::class.java.classLoader.getResourceAsStream(
hostYouTubeControlsBottomUiResourceName "$resourceDirectoryName/host/layout/$TARGET_RESOURCE_NAME"
)!!] )!!
]
val targetElement = val targetElement = "android.support.constraint.ConstraintLayout"
"android.support.constraint.ConstraintLayout"
val hostElements = sourceXmlEditor.file.getElementsByTagName(targetElement).item(0).childNodes val hostElements = sourceXmlEditor.file.getElementsByTagName(targetElement).item(0).childNodes
val destinationResourceFile = targetXmlEditor.file val destinationResourceFile = targetXmlEditor.file
val destinationElement = val destinationElement = destinationResourceFile.getElementsByTagName(targetElement).item(0)
destinationResourceFile.getElementsByTagName(targetElement).item(0)
for (index in 1 until hostElements.length) { for (index in 1 until hostElements.length) {
val element = hostElements.item(index).cloneNode(true) 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 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" val namespace = "@+id"
element.attributes.getNamedItem("yt:layout_constraintRight_toLeftOf").nodeValue = element.attributes.getNamedItem("yt:layout_constraintRight_toLeftOf").nodeValue =
"$namespace/$lastLeftOf" "$namespace/$lastLeftOf"
// set lastLeftOf attribute to the current element // Set lastLeftOf attribute to the current element.
val nameSpaceLength = 5 val nameSpaceLength = 5
lastLeftOf = element.attributes.getNamedItem("android:id").nodeValue.substring(nameSpaceLength) lastLeftOf = element.attributes.getNamedItem("android:id").nodeValue.substring(nameSpaceLength)
// copy the element // Add the element.
destinationResourceFile.adoptNode(element) destinationResourceFile.adoptNode(element)
destinationElement.appendChild(element) destinationElement.appendChild(element)
} }
sourceXmlEditor.close() sourceXmlEditor.close()
} }
override fun close() { override fun close() = targetXmlEditor.close()
targetXmlEditor.close()
}
} }