mirror of
https://github.com/libre-tube/LibreTube.git
synced 2024-12-14 22:30:30 +05:30
Option to add newly opened links to queue
This commit is contained in:
parent
ab24d95b8d
commit
2f10b7ba23
@ -47,6 +47,21 @@
|
||||
android:name=".ui.activities.CommunityActivity"
|
||||
android:label="@string/settings" />
|
||||
|
||||
<activity
|
||||
android:name=".ui.activities.AddToQueueActivity"
|
||||
android:enabled="true"
|
||||
android:launchMode="singleTop"
|
||||
android:exported="true"
|
||||
android:label="@string/add_to_queue">
|
||||
|
||||
<intent-filter android:label="@string/add_to_queue">
|
||||
<action android:name="android.intent.action.SEND" />
|
||||
<category android:name="android.intent.category.DEFAULT" />
|
||||
<data android:mimeType="text/plain" />
|
||||
</intent-filter>
|
||||
|
||||
</activity>
|
||||
|
||||
<activity
|
||||
android:name=".ui.activities.OfflinePlayerActivity"
|
||||
android:configChanges="screenSize|smallestScreenSize|screenLayout|orientation"
|
||||
@ -251,7 +266,7 @@
|
||||
android:exported="true"
|
||||
android:launchMode="singleInstance">
|
||||
|
||||
<intent-filter>
|
||||
<intent-filter android:label="@string/open">
|
||||
<action android:name="android.intent.action.SEND" />
|
||||
<category android:name="android.intent.category.DEFAULT" />
|
||||
<data android:mimeType="text/plain" />
|
||||
|
@ -0,0 +1,39 @@
|
||||
package com.github.libretube.ui.activities
|
||||
|
||||
import android.content.Intent
|
||||
import android.net.Uri
|
||||
import android.os.Bundle
|
||||
import com.github.libretube.ui.base.BaseActivity
|
||||
import com.github.libretube.util.PlayingQueue
|
||||
|
||||
/**
|
||||
* Receives a text by the intent and attempts to add it to the playing queue
|
||||
* If no video is playing currently, the queue will be left unchanged and the the main activity is being resumed
|
||||
*/
|
||||
class AddToQueueActivity : BaseActivity() {
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
|
||||
val uri = Uri.parse(intent.getStringExtra(Intent.EXTRA_TEXT)!!)
|
||||
var videoId: String? = null
|
||||
listOf("/shorts/", "/v/", "/embed/").forEach {
|
||||
if (uri.path!!.contains(it)) {
|
||||
videoId = uri.path!!.replace(it, "")
|
||||
}
|
||||
}
|
||||
if (
|
||||
uri.path!!.contains("/watch") && uri.query != null
|
||||
) {
|
||||
videoId = uri.getQueryParameter("v")
|
||||
}
|
||||
|
||||
if (videoId == null) videoId = uri.path!!.replace("/", "")
|
||||
|
||||
// if playing a video currently, the playing queue is not empty
|
||||
if (PlayingQueue.isNotEmpty()) PlayingQueue.insertByVideoId(videoId!!)
|
||||
|
||||
val intent = packageManager.getLaunchIntentForPackage(packageName)
|
||||
startActivity(intent)
|
||||
finishAndRemoveTask()
|
||||
}
|
||||
}
|
@ -84,10 +84,8 @@ class RouterActivity : BaseActivity() {
|
||||
val pm: PackageManager = this.packageManager
|
||||
val intent = pm.getLaunchIntentForPackage(this.packageName)
|
||||
intent?.flags = Intent.FLAG_ACTIVITY_CLEAR_TASK
|
||||
this.startActivity(
|
||||
resolveType(intent!!, uri)
|
||||
)
|
||||
this.finishAndRemoveTask()
|
||||
startActivity(resolveType(intent!!, uri))
|
||||
finishAndRemoveTask()
|
||||
}
|
||||
|
||||
private fun parseTimestamp(t: String): Long? {
|
||||
|
@ -6,6 +6,7 @@ import com.github.libretube.api.RetrofitInstance
|
||||
import com.github.libretube.api.obj.StreamItem
|
||||
import com.github.libretube.extensions.move
|
||||
import com.github.libretube.extensions.toID
|
||||
import com.github.libretube.extensions.toStreamItem
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.launch
|
||||
@ -13,6 +14,7 @@ import kotlinx.coroutines.launch
|
||||
object PlayingQueue {
|
||||
private val queue = mutableListOf<StreamItem>()
|
||||
private var currentStream: StreamItem? = null
|
||||
private val scope = CoroutineScope(Dispatchers.IO)
|
||||
|
||||
/**
|
||||
* Listener that gets called when the user selects an item from the queue
|
||||
@ -111,7 +113,7 @@ object PlayingQueue {
|
||||
|
||||
private fun fetchMoreFromPlaylist(playlistId: String, nextPage: String?) {
|
||||
var playlistNextPage: String? = nextPage
|
||||
CoroutineScope(Dispatchers.IO).launch {
|
||||
scope.launch {
|
||||
while (playlistNextPage != null) {
|
||||
RetrofitInstance.authApi.getPlaylistNextPage(
|
||||
playlistId,
|
||||
@ -127,7 +129,7 @@ object PlayingQueue {
|
||||
}
|
||||
|
||||
fun insertPlaylist(playlistId: String, newCurrentStream: StreamItem) {
|
||||
CoroutineScope(Dispatchers.IO).launch {
|
||||
scope.launch {
|
||||
try {
|
||||
val playlist = PlaylistsHelper.getPlaylist(playlistId)
|
||||
add(*playlist.relatedStreams.orEmpty().toTypedArray())
|
||||
@ -142,7 +144,7 @@ object PlayingQueue {
|
||||
|
||||
private fun fetchMoreFromChannel(channelId: String, nextPage: String?) {
|
||||
var channelNextPage: String? = nextPage
|
||||
CoroutineScope(Dispatchers.IO).launch {
|
||||
scope.launch {
|
||||
while (channelNextPage != null) {
|
||||
RetrofitInstance.api.getChannelNextPage(channelId, nextPage!!).apply {
|
||||
add(*relatedStreams.orEmpty().toTypedArray())
|
||||
@ -153,15 +155,22 @@ object PlayingQueue {
|
||||
}
|
||||
|
||||
fun insertChannel(channelId: String, newCurrentStream: StreamItem) {
|
||||
CoroutineScope(Dispatchers.IO).launch {
|
||||
try {
|
||||
scope.launch {
|
||||
runCatching {
|
||||
val channel = RetrofitInstance.api.getChannel(channelId)
|
||||
add(*channel.relatedStreams.orEmpty().toTypedArray())
|
||||
updateCurrent(newCurrentStream)
|
||||
if (channel.nextpage == null) return@launch
|
||||
fetchMoreFromChannel(channelId, channel.nextpage)
|
||||
} catch (e: Exception) {
|
||||
e.printStackTrace()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun insertByVideoId(videoId: String) {
|
||||
scope.launch {
|
||||
runCatching {
|
||||
val streams = RetrofitInstance.api.getStreams(videoId.toID())
|
||||
add(streams.toStreamItem(videoId))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user