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
|
||||
// check whether an URI got submitted over the intent data
|
||||
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)
|
||||
loadIntentData(intentData)
|
||||
}
|
||||
}
|
||||
|
||||
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("/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.channelFragment, bundle)
|
||||
} else if (data.path!!.contains("/playlist")) {
|
||||
Log.i(TAG, "URI Type: Playlist")
|
||||
var playlist = data.query!!
|
||||
if (playlist.contains("&")) {
|
||||
val 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/")
|
||||
val channelName = data.path!!
|
||||
.replace("/c/", "")
|
||||
.replace("/user/", "")
|
||||
|
||||
loadChannel(channelName = channelName)
|
||||
} else if (
|
||||
data.path!!.contains("/playlist")
|
||||
) {
|
||||
Log.i(TAG, "URI Type: Video")
|
||||
val watch = data.path!!
|
||||
.replace("/shorts/", "")
|
||||
.replace("/v/", "")
|
||||
.replace("/embed/", "")
|
||||
val bundle = Bundle()
|
||||
bundle.putString("videoId", watch)
|
||||
// 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) {
|
||||
Log.d("dafaq", data.query!!)
|
||||
var watch = data.query!!
|
||||
if (watch.contains("&")) {
|
||||
val watches = watch.split("&")
|
||||
for (v in watches) {
|
||||
if (v.contains("v=")) {
|
||||
watch = v
|
||||
var playlistId = data.query!!
|
||||
if (playlistId.contains("&")) {
|
||||
for (v in playlistId.split("&")) {
|
||||
if (v.contains("list=")) {
|
||||
playlistId = v.replace("list=", "")
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
val bundle = Bundle()
|
||||
bundle.putString("videoId", watch.replace("v=", ""))
|
||||
// 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 {
|
||||
val watch = data.path!!.replace("/", "")
|
||||
val bundle = Bundle()
|
||||
bundle.putString("videoId", watch)
|
||||
// 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) {
|
||||
loadPlaylist(playlistId)
|
||||
} else if (
|
||||
data.path!!.contains("/shorts/") ||
|
||||
data.path!!.contains("/embed/") ||
|
||||
data.path!!.contains("/v/")
|
||||
) {
|
||||
val videoId = data.path!!
|
||||
.replace("/shorts/", "")
|
||||
.replace("/v/", "")
|
||||
.replace("/embed/", "")
|
||||
|
||||
loadVideo(videoId, data.query)
|
||||
} else if (data.path!!.contains("/watch") && data.query != null) {
|
||||
var videoId = data.query!!
|
||||
|
||||
if (videoId.contains("&")) {
|
||||
val watches = videoId.split("&")
|
||||
for (v in watches) {
|
||||
if (v.contains("v=")) {
|
||||
videoId = v.replace("v=", "")
|
||||
break
|
||||
}
|
||||
}
|
||||
} else {
|
||||
videoId = videoId
|
||||
.replace("v=", "")
|
||||
}
|
||||
|
||||
loadVideo(videoId, data.query)
|
||||
} else {
|
||||
val videoId = data.path!!.replace("/", "")
|
||||
|
||||
loadVideo(videoId, data.query)
|
||||
}
|
||||
}
|
||||
|
||||
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()
|
||||
frag.arguments = bundle
|
||||
|
||||
supportFragmentManager.beginTransaction()
|
||||
.remove(PlayerFragment())
|
||||
.commit()
|
||||
@ -268,6 +269,24 @@ class MainActivity : AppCompatActivity() {
|
||||
}, 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() {
|
||||
if (binding.mainMotionLayout.progress == 0F) {
|
||||
try {
|
||||
|
@ -25,6 +25,8 @@ class ChannelFragment : Fragment() {
|
||||
private lateinit var binding: FragmentChannelBinding
|
||||
|
||||
private var channelId: String? = null
|
||||
private var channelName: String? = null
|
||||
|
||||
var nextPage: String? = null
|
||||
private var channelAdapter: ChannelAdapter? = null
|
||||
private var isLoading = true
|
||||
@ -33,7 +35,10 @@ class ChannelFragment : Fragment() {
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
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?) {
|
||||
super.onViewCreated(view, savedInstanceState)
|
||||
|
||||
channelId = channelId!!.replace("/channel/", "")
|
||||
binding.channelName.text = channelId
|
||||
binding.channelRecView.layoutManager = LinearLayoutManager(context)
|
||||
|
||||
@ -159,7 +163,8 @@ class ChannelFragment : Fragment() {
|
||||
fun run() {
|
||||
lifecycleScope.launchWhenCreated {
|
||||
val response = try {
|
||||
RetrofitInstance.api.getChannel(channelId!!)
|
||||
if (channelId != null) RetrofitInstance.api.getChannel(channelId!!)
|
||||
else RetrofitInstance.api.getChannelByName(channelName!!)
|
||||
} catch (e: IOException) {
|
||||
binding.channelRefresh.isRefreshing = false
|
||||
println(e)
|
||||
@ -196,6 +201,8 @@ class ChannelFragment : Fragment() {
|
||||
|
||||
ConnectionHelper.loadImage(response.bannerUrl, binding.channelBanner)
|
||||
ConnectionHelper.loadImage(response.avatarUrl, binding.channelImage)
|
||||
|
||||
// recyclerview of the videos by the channel
|
||||
channelAdapter = ChannelAdapter(
|
||||
response.relatedStreams!!.toMutableList(),
|
||||
childFragmentManager
|
||||
|
@ -1079,7 +1079,7 @@ class PlayerFragment : Fragment() {
|
||||
}
|
||||
|
||||
override fun onSingleTapConfirmed(e: MotionEvent?): Boolean {
|
||||
toggleController()
|
||||
binding.player.performClick()
|
||||
return super.onSingleTapConfirmed(e)
|
||||
}
|
||||
}
|
||||
@ -1108,7 +1108,7 @@ class PlayerFragment : Fragment() {
|
||||
}
|
||||
|
||||
override fun onSingleTapConfirmed(e: MotionEvent?): Boolean {
|
||||
toggleController()
|
||||
binding.player.performClick()
|
||||
return super.onSingleTapConfirmed(e)
|
||||
}
|
||||
}
|
||||
@ -1130,12 +1130,6 @@ class PlayerFragment : Fragment() {
|
||||
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
|
||||
private fun enableSeekbarPreview() {
|
||||
playerBinding.exoProgress.addListener(object : TimeBar.OnScrubListener {
|
||||
|
@ -24,7 +24,7 @@ object PreferenceHelper {
|
||||
fun setContext(context: Context) {
|
||||
prefContext = context
|
||||
settings = getDefaultSharedPreferences(prefContext)
|
||||
editor = getDefaultSharedPreferencesEditor(prefContext)
|
||||
editor = settings.edit()
|
||||
}
|
||||
|
||||
fun setString(key: String?, value: String?) {
|
||||
@ -215,8 +215,4 @@ object PreferenceHelper {
|
||||
private fun getDefaultSharedPreferences(context: Context): SharedPreferences {
|
||||
return PreferenceManager.getDefaultSharedPreferences(context)
|
||||
}
|
||||
|
||||
private fun getDefaultSharedPreferencesEditor(context: Context): SharedPreferences.Editor {
|
||||
return getDefaultSharedPreferences(context).edit()
|
||||
}
|
||||
}
|
||||
|
@ -66,6 +66,9 @@ interface PipedApi {
|
||||
@GET("channel/{channelId}")
|
||||
suspend fun getChannel(@Path("channelId") channelId: String): Channel
|
||||
|
||||
@GET("user/{name}")
|
||||
suspend fun getChannelByName(@Path("name") channelName: String): Channel
|
||||
|
||||
@GET("nextpage/channel/{channelId}")
|
||||
suspend fun getChannelNextPage(
|
||||
@Path("channelId") channelId: String,
|
||||
|
@ -15,6 +15,7 @@
|
||||
android:layout_gravity="top"
|
||||
android:animateLayoutChanges="true"
|
||||
android:orientation="vertical"
|
||||
android:paddingTop="5dp"
|
||||
android:paddingStart="5dp"
|
||||
android:paddingEnd="10dp">
|
||||
|
||||
@ -90,8 +91,9 @@
|
||||
android:id="@+id/advanced_options"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="right"
|
||||
android:layout_marginTop="-10dp"
|
||||
android:layout_gravity="end"
|
||||
android:layout_marginEnd="3dp"
|
||||
android:layout_marginTop="-12dp"
|
||||
android:orientation="horizontal"
|
||||
android:visibility="gone">
|
||||
|
||||
|
@ -379,7 +379,8 @@
|
||||
android:id="@+id/doubleTapOverlayLL"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_marginVertical="60dp">
|
||||
android:layout_marginTop="70dp"
|
||||
android:layout_marginBottom="60dp">
|
||||
|
||||
<!-- double tap rewind btn -->
|
||||
<FrameLayout
|
||||
|
Loading…
Reference in New Issue
Block a user