From 7a2f97de6d39b398641ad89fa9f3a9609aceac1b Mon Sep 17 00:00:00 2001 From: Bnyro Date: Tue, 28 Mar 2023 18:17:12 +0200 Subject: [PATCH 1/2] Support sharing live links to LibreTube --- app/src/main/AndroidManifest.xml | 1 + .../java/com/github/libretube/ui/activities/RouterActivity.kt | 4 +++- .../java/com/github/libretube/ui/fragments/PlayerFragment.kt | 2 +- 3 files changed, 5 insertions(+), 2 deletions(-) diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 90abb0683..f8b8b41fb 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -264,6 +264,7 @@ + diff --git a/app/src/main/java/com/github/libretube/ui/activities/RouterActivity.kt b/app/src/main/java/com/github/libretube/ui/activities/RouterActivity.kt index 4be8801e7..7c77654fb 100644 --- a/app/src/main/java/com/github/libretube/ui/activities/RouterActivity.kt +++ b/app/src/main/java/com/github/libretube/ui/activities/RouterActivity.kt @@ -51,12 +51,14 @@ class RouterActivity : BaseActivity() { } uri.path!!.contains("/shorts/") || uri.path!!.contains("/embed/") || - uri.path!!.contains("/v/") + uri.path!!.contains("/v/") || + uri.path!!.contains("/live/") -> { val videoId = uri.path!! .replace("/shorts/", "") .replace("/v/", "") .replace("/embed/", "") + .replace("/live/", "") intent.putExtra(IntentData.videoId, videoId) } diff --git a/app/src/main/java/com/github/libretube/ui/fragments/PlayerFragment.kt b/app/src/main/java/com/github/libretube/ui/fragments/PlayerFragment.kt index 9911351c0..99d323a6f 100644 --- a/app/src/main/java/com/github/libretube/ui/fragments/PlayerFragment.kt +++ b/app/src/main/java/com/github/libretube/ui/fragments/PlayerFragment.kt @@ -334,7 +334,7 @@ class PlayerFragment : Fragment(), OnlinePlayerOptions { if (PlayerHelper.swipeGestureEnabled) { binding.playerMotionLayout.addSwipeUpListener { - if(this::streams.isInitialized) { + if (this::streams.isInitialized) { binding.player.hideController() setFullscreen() } From f9a25738cd072f1a167dbc787586dd89a3fba090 Mon Sep 17 00:00:00 2001 From: Bnyro Date: Tue, 28 Mar 2023 18:23:41 +0200 Subject: [PATCH 2/2] Cleanup link handling in router activity --- .../libretube/ui/activities/RouterActivity.kt | 35 ++++++++++--------- 1 file changed, 19 insertions(+), 16 deletions(-) diff --git a/app/src/main/java/com/github/libretube/ui/activities/RouterActivity.kt b/app/src/main/java/com/github/libretube/ui/activities/RouterActivity.kt index 7c77654fb..d6e4e335d 100644 --- a/app/src/main/java/com/github/libretube/ui/activities/RouterActivity.kt +++ b/app/src/main/java/com/github/libretube/ui/activities/RouterActivity.kt @@ -18,8 +18,8 @@ class RouterActivity : BaseActivity() { // start processing the given text handleSendText(Uri.parse(intent.getStringExtra(Intent.EXTRA_TEXT)!!)) } else if (intent.data != null) { - val uri = intent.data - handleSendText(uri!!) + // link shared as text to the app + handleSendText(intent.data!!) } else { // start app as normal if unknown action, shouldn't be reachable NavigationHelper.restartMainActivity(this) @@ -30,6 +30,8 @@ class RouterActivity : BaseActivity() { * Resolve the uri and return a bundle with the arguments */ private fun resolveType(intent: Intent, uri: Uri): Intent { + val channelNamePaths = listOf("/c/", "/user/") + val videoPaths = listOf("/shorts/", "/embed/", "/v/", "/live/") when { uri.path!!.contains("/channel/") -> { val channelId = uri.path!! @@ -37,10 +39,12 @@ class RouterActivity : BaseActivity() { intent.putExtra(IntentData.channelId, channelId) } - uri.path!!.contains("/c/") || uri.path!!.contains("/user/") -> { - val channelName = uri.path!! - .replace("/c/", "") - .replace("/user/", "") + channelNamePaths.any { uri.path!!.contains(it) } -> { + var channelName = uri.path!! + + channelNamePaths.forEach { + channelName = channelName.replace(it, "") + } intent.putExtra(IntentData.channelName, channelName) } @@ -49,18 +53,17 @@ class RouterActivity : BaseActivity() { intent.putExtra(IntentData.playlistId, playlistId) } - uri.path!!.contains("/shorts/") || - uri.path!!.contains("/embed/") || - uri.path!!.contains("/v/") || - uri.path!!.contains("/live/") - -> { - val videoId = uri.path!! - .replace("/shorts/", "") - .replace("/v/", "") - .replace("/embed/", "") - .replace("/live/", "") + videoPaths.any { uri.path!!.contains(it) } -> { + var videoId = uri.path!! + + videoPaths.forEach { + videoId = videoId.replace(it, "") + } intent.putExtra(IntentData.videoId, videoId) + + uri.getQueryParameter("t") + ?.let { intent.putExtra(IntentData.timeStamp, it.toTimeInSeconds()) } } uri.path!!.contains("/watch") && uri.query != null -> { val videoId = uri.getQueryParameter("v")