Skip to content

Commit

Permalink
feat(youtube/copy-video-url): add tap and hold functionality to copy …
Browse files Browse the repository at this point in the history
…video url buttons (#2174)
  • Loading branch information
LisoUseInAIKyrios authored and oSumAtrIX committed May 19, 2023
1 parent 89ef0fc commit 95bbf46
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,7 @@ import app.revanced.patches.youtube.video.information.patch.VideoInformationPatc
@Version("0.0.1")
class CopyVideoUrlBytecodePatch : BytecodePatch() {
private companion object {
const val INTEGRATIONS_PACKAGE = "Lapp/revanced/integrations"
const val INTEGRATIONS_PLAYER_PACKAGE = "$INTEGRATIONS_PACKAGE/videoplayer"
const val INTEGRATIONS_PLAYER_PACKAGE = "Lapp/revanced/integrations/videoplayer"
val BUTTONS_DESCRIPTORS = listOf(
"$INTEGRATIONS_PLAYER_PACKAGE/CopyVideoUrlButton;",
"$INTEGRATIONS_PLAYER_PACKAGE/CopyVideoUrlTimestampButton;"
Expand All @@ -38,10 +37,8 @@ class CopyVideoUrlBytecodePatch : BytecodePatch() {

// Initialize buttons and inject visibility control
BUTTONS_DESCRIPTORS.forEach { descriptor ->
val initializeButtonDescriptor = "$descriptor->initializeButton(Ljava/lang/Object;)V"
val visibilityDescriptor = "$descriptor->changeVisibility(Z)V"
PlayerControlsBytecodePatch.initializeControl(initializeButtonDescriptor)
PlayerControlsBytecodePatch.injectVisibilityCheckCall(visibilityDescriptor)
PlayerControlsBytecodePatch.initializeControl("$descriptor->initializeButton(Landroid/view/View;)V")
PlayerControlsBytecodePatch.injectVisibilityCheckCall("$descriptor->changeVisibility(Z)V")
}

return PatchResultSuccess()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import app.revanced.patches.youtube.misc.playercontrols.resource.patch.BottomCon
import app.revanced.patches.youtube.misc.settings.bytecode.patch.SettingsPatch
import app.revanced.util.resources.ResourceUtils
import app.revanced.util.resources.ResourceUtils.copyResources
import app.revanced.util.resources.ResourceUtils.mergeStrings

@Name("copy-video-url-resource")
@DependsOn([BottomControlsResourcePatch::class, SettingsPatch::class])
Expand All @@ -28,13 +29,13 @@ class 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, click to copy video URL without 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, click to copy video URL with 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")
)
),
Expand All @@ -48,6 +49,9 @@ class CopyVideoUrlResourcePatch : ResourcePatch {
"revanced_yt_copy_timestamp.xml"
))

// merge strings
context.mergeStrings("copyvideourl/host/values/strings.xml")

BottomControlsResourcePatch.addControls("copyvideourl/host/layout/${BottomControlsResourcePatch.TARGET_RESOURCE_NAME}")

return PatchResultSuccess()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,23 +21,24 @@ import app.revanced.patches.youtube.video.information.patch.VideoInformationPatc
@DownloadsCompatibility
@Version("0.0.1")
class DownloadsBytecodePatch : BytecodePatch() {
override fun execute(context: BytecodeContext): PatchResult {
val integrationsPackage = "app/revanced/integrations"
val classDescriptor = "L$integrationsPackage/videoplayer/DownloadButton;"
private companion object {
const val BUTTON_DESCRIPTOR = "Lapp/revanced/integrations/videoplayer/DownloadButton;"
}

override fun execute(context: BytecodeContext): PatchResult {
/*
initialize the control
*/

val initializeDownloadsDescriptor = "$classDescriptor->initializeButton(Ljava/lang/Object;)V"
PlayerControlsBytecodePatch.initializeControl(initializeDownloadsDescriptor)
PlayerControlsBytecodePatch.initializeControl(
"$BUTTON_DESCRIPTOR->initializeButton(Landroid/view/View;)V")

/*
add code to change the visibility of the control
*/

val changeVisibilityDescriptor = "$classDescriptor->changeVisibility(Z)V"
PlayerControlsBytecodePatch.injectVisibilityCheckCall(changeVisibilityDescriptor)
PlayerControlsBytecodePatch.injectVisibilityCheckCall(
"$BUTTON_DESCRIPTOR->changeVisibility(Z)V")

return PatchResultSuccess()
}
Expand Down
5 changes: 5 additions & 0 deletions src/main/resources/copyvideourl/host/values/strings.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="revanced_share_copy_url_success">URL copied to clipboard</string>
<string name="revanced_share_copy_url_timestamp_success">URL with timestamp copied</string>
</resources>

0 comments on commit 95bbf46

Please sign in to comment.