feat(Public API): Make BottomControlsResource#addControls
public (#2514)
Co-authored-by: oSumAtrIX <johan.melkonyan1@web.de>
This commit is contained in:
parent
de4823c139
commit
f4e2257072
|
@ -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
|
||||
|
|
|
@ -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(
|
||||
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")
|
||||
}
|
||||
}
|
|
@ -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")
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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()
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue