diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml
index d12bebc14..bc653a666 100644
--- a/app/src/main/AndroidManifest.xml
+++ b/app/src/main/AndroidManifest.xml
@@ -169,13 +169,7 @@
-
-
-
-
-
-
-
+
diff --git a/app/src/main/java/com/github/libretube/MainActivity.kt b/app/src/main/java/com/github/libretube/MainActivity.kt
index 01cf4a378..e887c4f6d 100644
--- a/app/src/main/java/com/github/libretube/MainActivity.kt
+++ b/app/src/main/java/com/github/libretube/MainActivity.kt
@@ -1,6 +1,7 @@
package com.github.libretube
import android.app.Activity
+import android.app.ProgressDialog.show
import android.content.Context
import android.content.Intent
import android.content.pm.ActivityInfo
@@ -33,6 +34,7 @@ import androidx.preference.PreferenceManager
import com.github.libretube.util.CronetHelper
import com.google.android.material.bottomnavigation.BottomNavigationView
import com.google.android.material.color.DynamicColors
+import kotlinx.coroutines.NonDisposableHandle.parent
class MainActivity : AppCompatActivity() {
val TAG = "MainActivity"
@@ -142,111 +144,108 @@ class MainActivity : AppCompatActivity() {
override fun onStart() {
super.onStart()
- val data: Uri? = intent?.data
- Log.d(TAG, "dafaq" + data.toString())
+ val intentData: Uri? = intent?.data
+ if (intentData != null && intentData.host != null && intentData.path != null) {
+ Log.d("intentData", "${intentData.host} ${intentData.path} ")
+ loadIntentData(intentData)
+ }
+ }
- if (data != null) {
- Log.d("dafaq", data.host + " ${data.path} ")
- if (data.host != null) {
- if (data.path != null) {
- // channel
- if (data.path!!.contains("/channel/") ||
- data.path!!.contains("/c/") ||
- data.path!!.contains("/user/")
- ) {
- Log.i(TAG, "URI Type: Channel")
- var channel = data.path
- channel = channel!!.replace("/c/", "")
- channel = channel.replace("/user/", "")
- Log.i(TAG, channel)
- val bundle = bundleOf("channel_id" to channel)
- navController.navigate(R.id.channel, bundle)
- } else if (data.path!!.contains("/playlist")) {
- Log.i(TAG, "URI Type: Playlist")
- var playlist = data.query!!
- if (playlist.contains("&")) {
- var playlists = playlist.split("&")
- for (v in playlists) {
- if (v.contains("list=")) {
- playlist = v
- break
- }
- }
- }
- playlist = playlist.replace("list=", "")
- val bundle = bundleOf("playlist_id" to playlist)
- navController.navigate(R.id.playlistFragment, bundle)
- } else if (data.path!!.contains("/shorts/") ||
- data.path!!.contains("/embed/") ||
- data.path!!.contains("/v/")
- ) {
- Log.i(TAG, "URI Type: Video")
- val watch = data.path!!
- .replace("/shorts/", "")
- .replace("/v/", "")
- .replace("/embed/", "")
- val bundle = Bundle()
- bundle.putString("videoId", watch)
- val frag = PlayerFragment()
- frag.arguments = bundle
- supportFragmentManager.beginTransaction()
- .remove(PlayerFragment())
- .commit()
- supportFragmentManager.beginTransaction()
- .replace(R.id.container, frag)
- .commitNow()
- Handler().postDelayed({
- val motionLayout = findViewById(R.id.playerMotionLayout)
- motionLayout.transitionToEnd()
- motionLayout.transitionToStart()
- }, 100)
- } else if (data.path!!.contains("/watch") && data.query != null) {
- Log.d("dafaq", data.query!!)
- var watch = data.query!!
- if (watch.contains("&")) {
- var watches = watch.split("&")
- for (v in watches) {
- if (v.contains("v=")) {
- watch = v
- break
- }
- }
- }
- var bundle = Bundle()
- bundle.putString("videoId", watch.replace("v=", ""))
- var frag = PlayerFragment()
- frag.arguments = bundle
- supportFragmentManager.beginTransaction()
- .remove(PlayerFragment())
- .commit()
- supportFragmentManager.beginTransaction()
- .replace(R.id.container, frag)
- .commitNow()
- Handler().postDelayed({
- val motionLayout = findViewById(R.id.playerMotionLayout)
- motionLayout.transitionToEnd()
- motionLayout.transitionToStart()
- }, 100)
- } else {
- var watch = data.path!!.replace("/", "")
- var bundle = Bundle()
- bundle.putString("videoId", watch)
- var frag = PlayerFragment()
- frag.arguments = bundle
- supportFragmentManager.beginTransaction()
- .remove(PlayerFragment())
- .commit()
- supportFragmentManager.beginTransaction()
- .replace(R.id.container, frag)
- .commitNow()
- Handler().postDelayed({
- val motionLayout = findViewById(R.id.playerMotionLayout)
- motionLayout.transitionToEnd()
- motionLayout.transitionToStart()
- }, 100)
+ private fun loadIntentData(data: Uri) {
+ // channel
+ if (data.path!!.contains("/channel/") ||
+ data.path!!.contains("/c/") ||
+ data.path!!.contains("/user/")
+ ) {
+ Log.i(TAG, "URI Type: Channel")
+ var channel = data.path
+ channel = channel!!.replace("/c/", "")
+ channel = channel.replace("/user/", "")
+ val bundle = bundleOf("channel_id" to channel)
+ navController.navigate(R.id.channel, bundle)
+ } else if (data.path!!.contains("/playlist")) {
+ Log.i(TAG, "URI Type: Playlist")
+ var playlist = data.query!!
+ if (playlist.contains("&")) {
+ var playlists = playlist.split("&")
+ for (v in playlists) {
+ if (v.contains("list=")) {
+ playlist = v
+ break
}
}
}
+ playlist = playlist.replace("list=", "")
+ val bundle = bundleOf("playlist_id" to playlist)
+ navController.navigate(R.id.playlistFragment, bundle)
+ } else if (data.path!!.contains("/shorts/") ||
+ data.path!!.contains("/embed/") ||
+ data.path!!.contains("/v/")
+ ) {
+ Log.i(TAG, "URI Type: Video")
+ val watch = data.path!!
+ .replace("/shorts/", "")
+ .replace("/v/", "")
+ .replace("/embed/", "")
+ val bundle = Bundle()
+ bundle.putString("videoId", watch)
+ val frag = PlayerFragment()
+ frag.arguments = bundle
+ supportFragmentManager.beginTransaction()
+ .remove(PlayerFragment())
+ .commit()
+ supportFragmentManager.beginTransaction()
+ .replace(R.id.container, frag)
+ .commitNow()
+ Handler().postDelayed({
+ val motionLayout = findViewById(R.id.playerMotionLayout)
+ motionLayout.transitionToEnd()
+ motionLayout.transitionToStart()
+ }, 100)
+ } else if (data.path!!.contains("/watch") && data.query != null) {
+ Log.d("dafaq", data.query!!)
+ var watch = data.query!!
+ if (watch.contains("&")) {
+ var watches = watch.split("&")
+ for (v in watches) {
+ if (v.contains("v=")) {
+ watch = v
+ break
+ }
+ }
+ }
+ var bundle = Bundle()
+ bundle.putString("videoId", watch.replace("v=", ""))
+ var frag = PlayerFragment()
+ frag.arguments = bundle
+ supportFragmentManager.beginTransaction()
+ .remove(PlayerFragment())
+ .commit()
+ supportFragmentManager.beginTransaction()
+ .replace(R.id.container, frag)
+ .commitNow()
+ Handler().postDelayed({
+ val motionLayout = findViewById(R.id.playerMotionLayout)
+ motionLayout.transitionToEnd()
+ motionLayout.transitionToStart()
+ }, 100)
+ } else {
+ var watch = data.path!!.replace("/", "")
+ var bundle = Bundle()
+ bundle.putString("videoId", watch)
+ var frag = PlayerFragment()
+ frag.arguments = bundle
+ supportFragmentManager.beginTransaction()
+ .remove(PlayerFragment())
+ .commit()
+ supportFragmentManager.beginTransaction()
+ .replace(R.id.container, frag)
+ .commitNow()
+ Handler().postDelayed({
+ val motionLayout = findViewById(R.id.playerMotionLayout)
+ motionLayout.transitionToEnd()
+ motionLayout.transitionToStart()
+ }, 100)
}
}
diff --git a/app/src/main/java/com/github/libretube/RouterActivity.kt b/app/src/main/java/com/github/libretube/RouterActivity.kt
index 7f7d541b5..e26c17423 100644
--- a/app/src/main/java/com/github/libretube/RouterActivity.kt
+++ b/app/src/main/java/com/github/libretube/RouterActivity.kt
@@ -13,8 +13,11 @@ class RouterActivity : AppCompatActivity() {
super.onCreate(savedInstanceState)
when (intent?.action) {
Intent.ACTION_SEND -> {
- if ("text/plain" == intent.type) {
- handleSendText(intent) // Handle text being sent
+ if (intent.type == "text/plain") {
+ handleSendText(intent)
+ } else {
+ // start app as normal if wrong intent type
+ restartMainActivity(this)
}
}
}