mirror of
https://github.com/libre-tube/LibreTube.git
synced 2024-12-14 14:20:30 +05:30
Merge pull request #813 from Bnyro/master
support for opening links with /c/ or /user/
This commit is contained in:
commit
22ce32584e
@ -169,92 +169,93 @@ class MainActivity : AppCompatActivity() {
|
|||||||
val intentData: Uri? = intent?.data
|
val intentData: Uri? = intent?.data
|
||||||
// check whether an URI got submitted over the intent data
|
// check whether an URI got submitted over the intent data
|
||||||
if (intentData != null && intentData.host != null && intentData.path != null) {
|
if (intentData != null && intentData.host != null && intentData.path != null) {
|
||||||
Log.d("intentData", "${intentData.host} ${intentData.path} ")
|
Log.d(TAG, "intentData: ${intentData.host} ${intentData.path} ")
|
||||||
// load the URI of the submitted link (e.g. video)
|
// load the URI of the submitted link (e.g. video)
|
||||||
loadIntentData(intentData)
|
loadIntentData(intentData)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun loadIntentData(data: Uri) {
|
private fun loadIntentData(data: Uri) {
|
||||||
// channel
|
if (data.path!!.contains("/channel/")
|
||||||
if (data.path!!.contains("/channel/") ||
|
) {
|
||||||
|
val channelId = data.path!!
|
||||||
|
.replace("/channel/", "")
|
||||||
|
|
||||||
|
loadChannel(channelId = channelId)
|
||||||
|
} else if (
|
||||||
data.path!!.contains("/c/") ||
|
data.path!!.contains("/c/") ||
|
||||||
data.path!!.contains("/user/")
|
data.path!!.contains("/user/")
|
||||||
) {
|
) {
|
||||||
Log.i(TAG, "URI Type: Channel")
|
val channelName = data.path!!
|
||||||
var channel = data.path
|
.replace("/c/", "")
|
||||||
channel = channel!!.replace("/c/", "")
|
.replace("/user/", "")
|
||||||
channel = channel.replace("/user/", "")
|
|
||||||
val bundle = bundleOf("channel_id" to channel)
|
loadChannel(channelName = channelName)
|
||||||
navController.navigate(R.id.channelFragment, bundle)
|
} else if (
|
||||||
} else if (data.path!!.contains("/playlist")) {
|
data.path!!.contains("/playlist")
|
||||||
Log.i(TAG, "URI Type: Playlist")
|
) {
|
||||||
var playlist = data.query!!
|
var playlistId = data.query!!
|
||||||
if (playlist.contains("&")) {
|
if (playlistId.contains("&")) {
|
||||||
val playlists = playlist.split("&")
|
for (v in playlistId.split("&")) {
|
||||||
for (v in playlists) {
|
|
||||||
if (v.contains("list=")) {
|
if (v.contains("list=")) {
|
||||||
playlist = v
|
playlistId = v.replace("list=", "")
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
playlist = playlist.replace("list=", "")
|
|
||||||
val bundle = bundleOf("playlist_id" to playlist)
|
loadPlaylist(playlistId)
|
||||||
navController.navigate(R.id.playlistFragment, bundle)
|
} else if (
|
||||||
} else if (data.path!!.contains("/shorts/") ||
|
data.path!!.contains("/shorts/") ||
|
||||||
data.path!!.contains("/embed/") ||
|
data.path!!.contains("/embed/") ||
|
||||||
data.path!!.contains("/v/")
|
data.path!!.contains("/v/")
|
||||||
) {
|
) {
|
||||||
Log.i(TAG, "URI Type: Video")
|
val videoId = data.path!!
|
||||||
val watch = data.path!!
|
|
||||||
.replace("/shorts/", "")
|
.replace("/shorts/", "")
|
||||||
.replace("/v/", "")
|
.replace("/v/", "")
|
||||||
.replace("/embed/", "")
|
.replace("/embed/", "")
|
||||||
val bundle = Bundle()
|
|
||||||
bundle.putString("videoId", watch)
|
loadVideo(videoId, data.query)
|
||||||
// for time stamped links
|
|
||||||
if (data.query != null && data.query?.contains("t=")!!) {
|
|
||||||
val timeStamp = data.query.toString().split("t=")[1]
|
|
||||||
bundle.putLong("timeStamp", timeStamp.toLong())
|
|
||||||
}
|
|
||||||
loadWatch(bundle)
|
|
||||||
} else if (data.path!!.contains("/watch") && data.query != null) {
|
} else if (data.path!!.contains("/watch") && data.query != null) {
|
||||||
Log.d("dafaq", data.query!!)
|
var videoId = data.query!!
|
||||||
var watch = data.query!!
|
|
||||||
if (watch.contains("&")) {
|
if (videoId.contains("&")) {
|
||||||
val watches = watch.split("&")
|
val watches = videoId.split("&")
|
||||||
for (v in watches) {
|
for (v in watches) {
|
||||||
if (v.contains("v=")) {
|
if (v.contains("v=")) {
|
||||||
watch = v
|
videoId = v.replace("v=", "")
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
videoId = videoId
|
||||||
|
.replace("v=", "")
|
||||||
}
|
}
|
||||||
val bundle = Bundle()
|
|
||||||
bundle.putString("videoId", watch.replace("v=", ""))
|
loadVideo(videoId, data.query)
|
||||||
// for time stamped links
|
|
||||||
if (data.query != null && data.query?.contains("t=")!!) {
|
|
||||||
val timeStamp = data.query.toString().split("t=")[1]
|
|
||||||
bundle.putLong("timeStamp", timeStamp.toLong())
|
|
||||||
}
|
|
||||||
loadWatch(bundle)
|
|
||||||
} else {
|
} else {
|
||||||
val watch = data.path!!.replace("/", "")
|
val videoId = data.path!!.replace("/", "")
|
||||||
val bundle = Bundle()
|
|
||||||
bundle.putString("videoId", watch)
|
loadVideo(videoId, data.query)
|
||||||
// for time stamped links
|
|
||||||
if (data.query != null && data.query?.contains("t=")!!) {
|
|
||||||
val timeStamp = data.query.toString().split("t=")[1]
|
|
||||||
bundle.putLong("timeStamp", timeStamp.toLong())
|
|
||||||
}
|
|
||||||
loadWatch(bundle)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun loadWatch(bundle: Bundle) {
|
private fun loadVideo(videoId: String, query: String?) {
|
||||||
|
Log.i(TAG, "URI type: Video")
|
||||||
|
|
||||||
|
val bundle = Bundle()
|
||||||
|
Log.e(TAG, videoId)
|
||||||
|
|
||||||
|
// for time stamped links
|
||||||
|
if (query != null && query.contains("t=")) {
|
||||||
|
val timeStamp = query.toString().split("t=")[1]
|
||||||
|
bundle.putLong("timeStamp", timeStamp.toLong())
|
||||||
|
}
|
||||||
|
|
||||||
|
bundle.putString("videoId", videoId)
|
||||||
val frag = PlayerFragment()
|
val frag = PlayerFragment()
|
||||||
frag.arguments = bundle
|
frag.arguments = bundle
|
||||||
|
|
||||||
supportFragmentManager.beginTransaction()
|
supportFragmentManager.beginTransaction()
|
||||||
.remove(PlayerFragment())
|
.remove(PlayerFragment())
|
||||||
.commit()
|
.commit()
|
||||||
@ -268,6 +269,24 @@ class MainActivity : AppCompatActivity() {
|
|||||||
}, 100)
|
}, 100)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun loadChannel(
|
||||||
|
channelId: String? = null,
|
||||||
|
channelName: String? = null
|
||||||
|
) {
|
||||||
|
Log.i(TAG, "Uri Type: Channel")
|
||||||
|
|
||||||
|
val bundle = if (channelId != null) bundleOf("channel_id" to channelId)
|
||||||
|
else bundleOf("channel_name" to channelName)
|
||||||
|
navController.navigate(R.id.channelFragment, bundle)
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun loadPlaylist(playlistId: String) {
|
||||||
|
Log.i(TAG, "Uri Type: Playlist")
|
||||||
|
|
||||||
|
val bundle = bundleOf("playlist_id" to playlistId)
|
||||||
|
navController.navigate(R.id.playlistFragment, bundle)
|
||||||
|
}
|
||||||
|
|
||||||
override fun onBackPressed() {
|
override fun onBackPressed() {
|
||||||
if (binding.mainMotionLayout.progress == 0F) {
|
if (binding.mainMotionLayout.progress == 0F) {
|
||||||
try {
|
try {
|
||||||
|
@ -25,6 +25,8 @@ class ChannelFragment : Fragment() {
|
|||||||
private lateinit var binding: FragmentChannelBinding
|
private lateinit var binding: FragmentChannelBinding
|
||||||
|
|
||||||
private var channelId: String? = null
|
private var channelId: String? = null
|
||||||
|
private var channelName: String? = null
|
||||||
|
|
||||||
var nextPage: String? = null
|
var nextPage: String? = null
|
||||||
private var channelAdapter: ChannelAdapter? = null
|
private var channelAdapter: ChannelAdapter? = null
|
||||||
private var isLoading = true
|
private var isLoading = true
|
||||||
@ -33,7 +35,10 @@ class ChannelFragment : Fragment() {
|
|||||||
override fun onCreate(savedInstanceState: Bundle?) {
|
override fun onCreate(savedInstanceState: Bundle?) {
|
||||||
super.onCreate(savedInstanceState)
|
super.onCreate(savedInstanceState)
|
||||||
arguments?.let {
|
arguments?.let {
|
||||||
channelId = it.getString("channel_id")
|
channelId = it.getString("channel_id")?.replace("/channel/", "")
|
||||||
|
channelName = it.getString("channel_name")
|
||||||
|
?.replace("/c/", "")
|
||||||
|
?.replace("/user/", "")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -49,7 +54,6 @@ class ChannelFragment : Fragment() {
|
|||||||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
||||||
super.onViewCreated(view, savedInstanceState)
|
super.onViewCreated(view, savedInstanceState)
|
||||||
|
|
||||||
channelId = channelId!!.replace("/channel/", "")
|
|
||||||
binding.channelName.text = channelId
|
binding.channelName.text = channelId
|
||||||
binding.channelRecView.layoutManager = LinearLayoutManager(context)
|
binding.channelRecView.layoutManager = LinearLayoutManager(context)
|
||||||
|
|
||||||
@ -159,7 +163,8 @@ class ChannelFragment : Fragment() {
|
|||||||
fun run() {
|
fun run() {
|
||||||
lifecycleScope.launchWhenCreated {
|
lifecycleScope.launchWhenCreated {
|
||||||
val response = try {
|
val response = try {
|
||||||
RetrofitInstance.api.getChannel(channelId!!)
|
if (channelId != null) RetrofitInstance.api.getChannel(channelId!!)
|
||||||
|
else RetrofitInstance.api.getChannelByName(channelName!!)
|
||||||
} catch (e: IOException) {
|
} catch (e: IOException) {
|
||||||
binding.channelRefresh.isRefreshing = false
|
binding.channelRefresh.isRefreshing = false
|
||||||
println(e)
|
println(e)
|
||||||
@ -196,6 +201,8 @@ class ChannelFragment : Fragment() {
|
|||||||
|
|
||||||
ConnectionHelper.loadImage(response.bannerUrl, binding.channelBanner)
|
ConnectionHelper.loadImage(response.bannerUrl, binding.channelBanner)
|
||||||
ConnectionHelper.loadImage(response.avatarUrl, binding.channelImage)
|
ConnectionHelper.loadImage(response.avatarUrl, binding.channelImage)
|
||||||
|
|
||||||
|
// recyclerview of the videos by the channel
|
||||||
channelAdapter = ChannelAdapter(
|
channelAdapter = ChannelAdapter(
|
||||||
response.relatedStreams!!.toMutableList(),
|
response.relatedStreams!!.toMutableList(),
|
||||||
childFragmentManager
|
childFragmentManager
|
||||||
|
@ -1079,7 +1079,7 @@ class PlayerFragment : Fragment() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
override fun onSingleTapConfirmed(e: MotionEvent?): Boolean {
|
override fun onSingleTapConfirmed(e: MotionEvent?): Boolean {
|
||||||
toggleController()
|
binding.player.performClick()
|
||||||
return super.onSingleTapConfirmed(e)
|
return super.onSingleTapConfirmed(e)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1108,7 +1108,7 @@ class PlayerFragment : Fragment() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
override fun onSingleTapConfirmed(e: MotionEvent?): Boolean {
|
override fun onSingleTapConfirmed(e: MotionEvent?): Boolean {
|
||||||
toggleController()
|
binding.player.performClick()
|
||||||
return super.onSingleTapConfirmed(e)
|
return super.onSingleTapConfirmed(e)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1130,12 +1130,6 @@ class PlayerFragment : Fragment() {
|
|||||||
binding.rewindFL.visibility = View.GONE
|
binding.rewindFL.visibility = View.GONE
|
||||||
}
|
}
|
||||||
|
|
||||||
// toggle the visibility of the player controller
|
|
||||||
private fun toggleController() {
|
|
||||||
if (exoPlayerView.isControllerFullyVisible) exoPlayerView.hideController()
|
|
||||||
else exoPlayerView.showController()
|
|
||||||
}
|
|
||||||
|
|
||||||
// enable seek bar preview
|
// enable seek bar preview
|
||||||
private fun enableSeekbarPreview() {
|
private fun enableSeekbarPreview() {
|
||||||
playerBinding.exoProgress.addListener(object : TimeBar.OnScrubListener {
|
playerBinding.exoProgress.addListener(object : TimeBar.OnScrubListener {
|
||||||
|
@ -24,7 +24,7 @@ object PreferenceHelper {
|
|||||||
fun setContext(context: Context) {
|
fun setContext(context: Context) {
|
||||||
prefContext = context
|
prefContext = context
|
||||||
settings = getDefaultSharedPreferences(prefContext)
|
settings = getDefaultSharedPreferences(prefContext)
|
||||||
editor = getDefaultSharedPreferencesEditor(prefContext)
|
editor = settings.edit()
|
||||||
}
|
}
|
||||||
|
|
||||||
fun setString(key: String?, value: String?) {
|
fun setString(key: String?, value: String?) {
|
||||||
@ -215,8 +215,4 @@ object PreferenceHelper {
|
|||||||
private fun getDefaultSharedPreferences(context: Context): SharedPreferences {
|
private fun getDefaultSharedPreferences(context: Context): SharedPreferences {
|
||||||
return PreferenceManager.getDefaultSharedPreferences(context)
|
return PreferenceManager.getDefaultSharedPreferences(context)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun getDefaultSharedPreferencesEditor(context: Context): SharedPreferences.Editor {
|
|
||||||
return getDefaultSharedPreferences(context).edit()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -66,6 +66,9 @@ interface PipedApi {
|
|||||||
@GET("channel/{channelId}")
|
@GET("channel/{channelId}")
|
||||||
suspend fun getChannel(@Path("channelId") channelId: String): Channel
|
suspend fun getChannel(@Path("channelId") channelId: String): Channel
|
||||||
|
|
||||||
|
@GET("user/{name}")
|
||||||
|
suspend fun getChannelByName(@Path("name") channelName: String): Channel
|
||||||
|
|
||||||
@GET("nextpage/channel/{channelId}")
|
@GET("nextpage/channel/{channelId}")
|
||||||
suspend fun getChannelNextPage(
|
suspend fun getChannelNextPage(
|
||||||
@Path("channelId") channelId: String,
|
@Path("channelId") channelId: String,
|
||||||
|
@ -15,6 +15,7 @@
|
|||||||
android:layout_gravity="top"
|
android:layout_gravity="top"
|
||||||
android:animateLayoutChanges="true"
|
android:animateLayoutChanges="true"
|
||||||
android:orientation="vertical"
|
android:orientation="vertical"
|
||||||
|
android:paddingTop="5dp"
|
||||||
android:paddingStart="5dp"
|
android:paddingStart="5dp"
|
||||||
android:paddingEnd="10dp">
|
android:paddingEnd="10dp">
|
||||||
|
|
||||||
@ -90,8 +91,9 @@
|
|||||||
android:id="@+id/advanced_options"
|
android:id="@+id/advanced_options"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_gravity="right"
|
android:layout_gravity="end"
|
||||||
android:layout_marginTop="-10dp"
|
android:layout_marginEnd="3dp"
|
||||||
|
android:layout_marginTop="-12dp"
|
||||||
android:orientation="horizontal"
|
android:orientation="horizontal"
|
||||||
android:visibility="gone">
|
android:visibility="gone">
|
||||||
|
|
||||||
|
@ -379,7 +379,8 @@
|
|||||||
android:id="@+id/doubleTapOverlayLL"
|
android:id="@+id/doubleTapOverlayLL"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent"
|
android:layout_height="match_parent"
|
||||||
android:layout_marginVertical="60dp">
|
android:layout_marginTop="70dp"
|
||||||
|
android:layout_marginBottom="60dp">
|
||||||
|
|
||||||
<!-- double tap rewind btn -->
|
<!-- double tap rewind btn -->
|
||||||
<FrameLayout
|
<FrameLayout
|
||||||
|
Loading…
Reference in New Issue
Block a user