diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 0db563702..7cc95d66a 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -41,100 +41,6 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + (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 new file mode 100644 index 000000000..2f0ee8c21 --- /dev/null +++ b/app/src/main/java/com/github/libretube/RouterActivity.kt @@ -0,0 +1,47 @@ +package com.github.libretube + +import android.content.Intent +import android.content.pm.PackageManager +import android.net.Uri +import android.os.Bundle +import android.util.Log +import androidx.appcompat.app.AppCompatActivity + +class RouterActivity : AppCompatActivity() { + val TAG = "RouterActivity" + override fun onCreate(savedInstanceState: Bundle?) { + super.onCreate(savedInstanceState) + // Check if Intent Action is ACTION_SEND + if (intent?.action == Intent.ACTION_SEND) { + if (intent.type == "text/plain" && checkHost(intent)) { + // start the main activity using the given URI as data if the host is known + handleSendText(intent) + } else { + // start app as normal if wrong intent type + restartMainActivity(this) + } + } + } + + private fun checkHost(intent: Intent): Boolean { + // check whether the host is known, current solution to replace the broken intent filter + val hostsList = resources.getStringArray(R.array.shareHostsList) + val intentDataUri: Uri = Uri.parse(intent.getStringExtra(Intent.EXTRA_TEXT)) + val intentDataHost = intentDataUri.host + Log.d(TAG, "$intentDataHost") + return hostsList.contains(intentDataHost) + } + + private fun handleSendText(intent: Intent) { + intent.getStringExtra(Intent.EXTRA_TEXT)?.let { + Log.i(TAG, it) + val pm: PackageManager = this.packageManager + // startIntent(this, MainActivity::class.java doesn't work for the activity aliases needed for the logo switch option + val intent = pm.getLaunchIntentForPackage(this.packageName) + intent?.flags = Intent.FLAG_ACTIVITY_CLEAR_TASK + intent?.data = Uri.parse(it) + this.startActivity(intent) + this.finishAndRemoveTask() + } + } +} diff --git a/app/src/main/res/values/array.xml b/app/src/main/res/values/array.xml index 254616997..a654935d6 100644 --- a/app/src/main/res/values/array.xml +++ b/app/src/main/res/values/array.xml @@ -14,6 +14,46 @@ https://pipedapi.moomoo.me https://pa.mint.lgbt + + youtube.com" + m.youtube.com" + www.youtube.com" + music.youtube.com" + youtu.be" + tubus.eduvid.org" + invidio.us" + dev.invidio.us" + www.invidio.us" + redirect.invidious.io" + invidious.snopyta.org" + yewtu.be" + tube.connect.cafe" + invidious.kavin.rocks" + invidious-us.kavin.rocks" + invidious.site" + vid.mint.lgbt" + invidiou.site" + invidious.fdn.fr" + invidious.048596.xyz" + invidious.zee.li" + vid.puffyan.us" + ytprivate.com" + invidious.namazso.eu" + invidious.silkky.cloud" + invidious.exonip.de" + inv.riverside.rocks" + invidious.blamefran.net" + invidious.moomoo.me" + ytb.trom.tf" + yt.cyberhost.uk" + y.com.cm" + piped.tokhmi.xyz" + piped.kavin.rocks" + piped.silkky.cloud" + piped.silkky.cloud" + piped.mint.lgbt" + il.ax" + Afghanistan Albania