feat(youtube/copy-video-url): add tap and hold functionality to copy video url buttons (#2174)

This commit is contained in:
LisoUseInAIKyrios 2023-05-19 19:42:27 +04:00 committed by oSumAtrIX
parent 89ef0fcd42
commit 95bbf46e77
No known key found for this signature in database
GPG Key ID: A9B3094ACDB604B4
4 changed files with 22 additions and 15 deletions

View File

@ -26,8 +26,7 @@ import app.revanced.patches.youtube.video.information.patch.VideoInformationPatc
@Version("0.0.1") @Version("0.0.1")
class CopyVideoUrlBytecodePatch : BytecodePatch() { class CopyVideoUrlBytecodePatch : BytecodePatch() {
private companion object { private companion object {
const val INTEGRATIONS_PACKAGE = "Lapp/revanced/integrations" const val INTEGRATIONS_PLAYER_PACKAGE = "Lapp/revanced/integrations/videoplayer"
const val INTEGRATIONS_PLAYER_PACKAGE = "$INTEGRATIONS_PACKAGE/videoplayer"
val BUTTONS_DESCRIPTORS = listOf( val BUTTONS_DESCRIPTORS = listOf(
"$INTEGRATIONS_PLAYER_PACKAGE/CopyVideoUrlButton;", "$INTEGRATIONS_PLAYER_PACKAGE/CopyVideoUrlButton;",
"$INTEGRATIONS_PLAYER_PACKAGE/CopyVideoUrlTimestampButton;" "$INTEGRATIONS_PLAYER_PACKAGE/CopyVideoUrlTimestampButton;"
@ -38,10 +37,8 @@ class CopyVideoUrlBytecodePatch : BytecodePatch() {
// Initialize buttons and inject visibility control // Initialize buttons and inject visibility control
BUTTONS_DESCRIPTORS.forEach { descriptor -> BUTTONS_DESCRIPTORS.forEach { descriptor ->
val initializeButtonDescriptor = "$descriptor->initializeButton(Ljava/lang/Object;)V" PlayerControlsBytecodePatch.initializeControl("$descriptor->initializeButton(Landroid/view/View;)V")
val visibilityDescriptor = "$descriptor->changeVisibility(Z)V" PlayerControlsBytecodePatch.injectVisibilityCheckCall("$descriptor->changeVisibility(Z)V")
PlayerControlsBytecodePatch.initializeControl(initializeButtonDescriptor)
PlayerControlsBytecodePatch.injectVisibilityCheckCall(visibilityDescriptor)
} }
return PatchResultSuccess() return PatchResultSuccess()

View File

@ -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.patches.youtube.misc.settings.bytecode.patch.SettingsPatch
import app.revanced.util.resources.ResourceUtils import app.revanced.util.resources.ResourceUtils
import app.revanced.util.resources.ResourceUtils.copyResources import app.revanced.util.resources.ResourceUtils.copyResources
import app.revanced.util.resources.ResourceUtils.mergeStrings
@Name("copy-video-url-resource") @Name("copy-video-url-resource")
@DependsOn([BottomControlsResourcePatch::class, SettingsPatch::class]) @DependsOn([BottomControlsResourcePatch::class, SettingsPatch::class])
@ -28,13 +29,13 @@ class 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, 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") 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, 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") StringResource("revanced_copy_video_url_timestamp_summary_off", "Button is not shown")
) )
), ),
@ -48,6 +49,9 @@ class CopyVideoUrlResourcePatch : ResourcePatch {
"revanced_yt_copy_timestamp.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/host/layout/${BottomControlsResourcePatch.TARGET_RESOURCE_NAME}")
return PatchResultSuccess() return PatchResultSuccess()

View File

@ -21,23 +21,24 @@ import app.revanced.patches.youtube.video.information.patch.VideoInformationPatc
@DownloadsCompatibility @DownloadsCompatibility
@Version("0.0.1") @Version("0.0.1")
class DownloadsBytecodePatch : BytecodePatch() { class DownloadsBytecodePatch : BytecodePatch() {
override fun execute(context: BytecodeContext): PatchResult { private companion object {
val integrationsPackage = "app/revanced/integrations" const val BUTTON_DESCRIPTOR = "Lapp/revanced/integrations/videoplayer/DownloadButton;"
val classDescriptor = "L$integrationsPackage/videoplayer/DownloadButton;" }
override fun execute(context: BytecodeContext): PatchResult {
/* /*
initialize the control initialize the control
*/ */
val initializeDownloadsDescriptor = "$classDescriptor->initializeButton(Ljava/lang/Object;)V" PlayerControlsBytecodePatch.initializeControl(
PlayerControlsBytecodePatch.initializeControl(initializeDownloadsDescriptor) "$BUTTON_DESCRIPTOR->initializeButton(Landroid/view/View;)V")
/* /*
add code to change the visibility of the control add code to change the visibility of the control
*/ */
val changeVisibilityDescriptor = "$classDescriptor->changeVisibility(Z)V" PlayerControlsBytecodePatch.injectVisibilityCheckCall(
PlayerControlsBytecodePatch.injectVisibilityCheckCall(changeVisibilityDescriptor) "$BUTTON_DESCRIPTOR->changeVisibility(Z)V")
return PatchResultSuccess() return PatchResultSuccess()
} }

View File

@ -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>