Skip to content

Commit f4e2257

Browse files
Aunali321oSumAtrIX
andauthored
feat(Public API): Make BottomControlsResource#addControls public (#2514)
Co-authored-by: oSumAtrIX <[email protected]>
1 parent de4823c commit f4e2257

File tree

4 files changed

+56
-40
lines changed

4 files changed

+56
-40
lines changed

api/revanced-patches.api

+1
Original file line numberDiff line numberDiff line change
@@ -1464,6 +1464,7 @@ public final class app/revanced/patches/youtube/misc/minimizedplayback/Minimized
14641464

14651465
public final class app/revanced/patches/youtube/misc/playercontrols/BottomControlsResourcePatch : app/revanced/patcher/patch/ResourcePatch, java/io/Closeable {
14661466
public static final field INSTANCE Lapp/revanced/patches/youtube/misc/playercontrols/BottomControlsResourcePatch;
1467+
public final fun addControls (Ljava/lang/String;)V
14671468
public fun close ()V
14681469
public synthetic fun execute (Lapp/revanced/patcher/data/Context;)V
14691470
public fun execute (Lapp/revanced/patcher/data/ResourceContext;)V

src/main/kotlin/app/revanced/patches/youtube/interaction/copyvideourl/CopyVideoUrlResourcePatch.kt

+19-10
Original file line numberDiff line numberDiff line change
@@ -28,30 +28,39 @@ internal object CopyVideoUrlResourcePatch : ResourcePatch() {
2828
SwitchPreference(
2929
"revanced_copy_video_url",
3030
StringResource("revanced_copy_video_url_title", "Show copy video URL button"),
31-
StringResource("revanced_copy_video_url_summary_on", "Button is shown. Tap to copy video URL. Tap and hold to copy video URL with timestamp"),
31+
StringResource(
32+
"revanced_copy_video_url_summary_on",
33+
"Button is shown. Tap to copy video URL. Tap and hold to copy video URL with timestamp"
34+
),
3235
StringResource("revanced_copy_video_url_summary_off", "Button is not shown")
3336
),
3437
SwitchPreference(
3538
"revanced_copy_video_url_timestamp",
3639
StringResource("revanced_copy_video_url_timestamp_title", "Show copy timestamp URL button"),
37-
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"),
40+
StringResource(
41+
"revanced_copy_video_url_timestamp_summary_on",
42+
"Button is shown. Tap to copy video URL with timestamp. Tap and hold to copy video without timestamp"
43+
),
3844
StringResource("revanced_copy_video_url_timestamp_summary_off", "Button is not shown")
3945
)
4046
),
41-
StringResource("revanced_copy_video_url_preference_screen_summary", "Settings related to copy URL buttons in video player")
47+
StringResource(
48+
"revanced_copy_video_url_preference_screen_summary",
49+
"Settings related to copy URL buttons in video player"
50+
)
4251
)
4352
)
4453

45-
context.copyResources("copyvideourl", ResourceGroup(
46-
resourceDirectoryName = "drawable",
47-
"revanced_yt_copy.xml",
48-
"revanced_yt_copy_timestamp.xml"
49-
)
54+
context.copyResources(
55+
"copyvideourl", ResourceGroup(
56+
resourceDirectoryName = "drawable",
57+
"revanced_yt_copy.xml",
58+
"revanced_yt_copy_timestamp.xml"
59+
)
5060
)
5161

52-
// merge strings
5362
context.mergeStrings("copyvideourl/host/values/strings.xml")
5463

55-
BottomControlsResourcePatch.addControls("copyvideourl/host/layout/${BottomControlsResourcePatch.TARGET_RESOURCE_NAME}")
64+
BottomControlsResourcePatch.addControls("copyvideourl")
5665
}
5766
}

src/main/kotlin/app/revanced/patches/youtube/interaction/downloads/ExternalDownloadsResourcePatch.kt

+17-9
Original file line numberDiff line numberDiff line change
@@ -28,27 +28,35 @@ internal object ExternalDownloadsResourcePatch : ResourcePatch() {
2828
"revanced_external_downloader",
2929
StringResource("revanced_external_downloader_title", "Show external download button"),
3030
StringResource("revanced_external_downloader_summary_on", "Download button shown in player"),
31-
StringResource("revanced_external_downloader_summary_off", "Download button not shown in player")
31+
StringResource(
32+
"revanced_external_downloader_summary_off",
33+
"Download button not shown in player"
34+
)
3235
),
3336
TextPreference(
3437
"revanced_external_downloader_name",
3538
StringResource("revanced_external_downloader_name_title", "Downloader package name"),
36-
StringResource("revanced_external_downloader_name_summary", "Package name of your installed external downloader app, such as NewPipe or Seal"),
39+
StringResource(
40+
"revanced_external_downloader_name_summary",
41+
"Package name of your installed external downloader app, such as NewPipe or Seal"
42+
),
3743
InputType.TEXT
3844
)
3945
),
40-
StringResource("revanced_external_downloader_preference_screen_summary", "Settings for using an external downloader")
46+
StringResource(
47+
"revanced_external_downloader_preference_screen_summary",
48+
"Settings for using an external downloader"
49+
)
4150
)
4251
)
4352

44-
45-
// Copy strings
4653
context.mergeStrings("downloads/host/values/strings.xml")
4754

48-
// Copy resources
49-
context.copyResources("downloads", ResourceGroup("drawable", "revanced_yt_download_button.xml"))
55+
context.copyResources(
56+
"downloads",
57+
ResourceGroup("drawable", "revanced_yt_download_button.xml")
58+
)
5059

51-
// Add download button node
52-
BottomControlsResourcePatch.addControls("downloads/host/layout/${BottomControlsResourcePatch.TARGET_RESOURCE_NAME}")
60+
BottomControlsResourcePatch.addControls("downloads")
5361
}
5462
}

src/main/kotlin/app/revanced/patches/youtube/misc/playercontrols/BottomControlsResourcePatch.kt

+19-21
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,15 @@ import java.io.Closeable
1111
object BottomControlsResourcePatch : ResourcePatch(), Closeable {
1212
internal var bottomUiContainerResourceId: Long = -1
1313

14-
internal const val TARGET_RESOURCE_NAME = "youtube_controls_bottom_ui_container.xml"
14+
private const val TARGET_RESOURCE_NAME = "youtube_controls_bottom_ui_container.xml"
1515
private const val TARGET_RESOURCE = "res/layout/$TARGET_RESOURCE_NAME"
1616

17+
// The element to the left of the element being added.
18+
private var lastLeftOf = "fullscreen_button"
19+
1720
private lateinit var resourceContext: ResourceContext
1821
private lateinit var targetXmlEditor: DomFileEditor
1922

20-
// The element to which to add the new elements to
21-
private var lastLeftOf = "fullscreen_button"
22-
2323
override fun execute(context: ResourceContext) {
2424
resourceContext = context
2525
targetXmlEditor = context.xmlEditor[TARGET_RESOURCE]
@@ -30,46 +30,44 @@ object BottomControlsResourcePatch : ResourcePatch(), Closeable {
3030

3131
/**
3232
* Add new controls to the bottom of the YouTube player.
33-
* @param hostYouTubeControlsBottomUiResourceName The hosting resource name containing the elements.
33+
*
34+
* @param resourceDirectoryName The name of the directory containing the hosting resource.
3435
*/
35-
internal fun addControls(hostYouTubeControlsBottomUiResourceName: String) {
36-
val sourceXmlEditor =
37-
resourceContext.xmlEditor[this::class.java.classLoader.getResourceAsStream(
38-
hostYouTubeControlsBottomUiResourceName
39-
)!!]
36+
fun addControls(resourceDirectoryName: String) {
37+
val sourceXmlEditor = resourceContext.xmlEditor[
38+
this::class.java.classLoader.getResourceAsStream(
39+
"$resourceDirectoryName/host/layout/$TARGET_RESOURCE_NAME"
40+
)!!
41+
]
4042

41-
val targetElement =
42-
"android.support.constraint.ConstraintLayout"
43+
val targetElement = "android.support.constraint.ConstraintLayout"
4344

4445
val hostElements = sourceXmlEditor.file.getElementsByTagName(targetElement).item(0).childNodes
4546

4647
val destinationResourceFile = targetXmlEditor.file
47-
val destinationElement =
48-
destinationResourceFile.getElementsByTagName(targetElement).item(0)
48+
val destinationElement = destinationResourceFile.getElementsByTagName(targetElement).item(0)
4949

5050
for (index in 1 until hostElements.length) {
5151
val element = hostElements.item(index).cloneNode(true)
5252

53-
// if the element has no attributes theres no point to adding it to the destination
53+
// If the element has no attributes there's no point to adding it to the destination.
5454
if (!element.hasAttributes()) continue
5555

56-
// set the elements lastLeftOf attribute to the lastLeftOf value
56+
// Set the elements lastLeftOf attribute to the lastLeftOf value.
5757
val namespace = "@+id"
5858
element.attributes.getNamedItem("yt:layout_constraintRight_toLeftOf").nodeValue =
5959
"$namespace/$lastLeftOf"
6060

61-
// set lastLeftOf attribute to the current element
61+
// Set lastLeftOf attribute to the current element.
6262
val nameSpaceLength = 5
6363
lastLeftOf = element.attributes.getNamedItem("android:id").nodeValue.substring(nameSpaceLength)
6464

65-
// copy the element
65+
// Add the element.
6666
destinationResourceFile.adoptNode(element)
6767
destinationElement.appendChild(element)
6868
}
6969
sourceXmlEditor.close()
7070
}
7171

72-
override fun close() {
73-
targetXmlEditor.close()
74-
}
72+
override fun close() = targetXmlEditor.close()
7573
}

0 commit comments

Comments
 (0)