mirror of
https://github.com/libre-tube/LibreTube.git
synced 2024-12-14 06:10:31 +05:30
Add shuffle button to owned playlists
This commit is contained in:
parent
1e7b38e209
commit
b6056b8610
@ -105,6 +105,7 @@ object PlaylistsHelper {
|
|||||||
appContext.toastFromMainThread(R.string.server_error)
|
appContext.toastFromMainThread(R.string.server_error)
|
||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
|
Log.e("created pl", response.playlistId.toString())
|
||||||
if (response.playlistId != null) {
|
if (response.playlistId != null) {
|
||||||
appContext.toastFromMainThread(R.string.playlistCreated)
|
appContext.toastFromMainThread(R.string.playlistCreated)
|
||||||
return response.playlistId!!
|
return response.playlistId!!
|
||||||
|
@ -4,12 +4,15 @@ import android.app.Dialog
|
|||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
import android.widget.Toast
|
import android.widget.Toast
|
||||||
import androidx.fragment.app.DialogFragment
|
import androidx.fragment.app.DialogFragment
|
||||||
import androidx.lifecycle.lifecycleScope
|
|
||||||
import com.github.libretube.R
|
import com.github.libretube.R
|
||||||
import com.github.libretube.api.PlaylistsHelper
|
import com.github.libretube.api.PlaylistsHelper
|
||||||
import com.github.libretube.databinding.DialogCreatePlaylistBinding
|
import com.github.libretube.databinding.DialogCreatePlaylistBinding
|
||||||
import com.github.libretube.util.TextUtils
|
import com.github.libretube.util.TextUtils
|
||||||
import com.google.android.material.dialog.MaterialAlertDialogBuilder
|
import com.google.android.material.dialog.MaterialAlertDialogBuilder
|
||||||
|
import kotlinx.coroutines.CoroutineScope
|
||||||
|
import kotlinx.coroutines.Dispatchers
|
||||||
|
import kotlinx.coroutines.launch
|
||||||
|
import kotlinx.coroutines.withContext
|
||||||
|
|
||||||
class CreatePlaylistDialog(
|
class CreatePlaylistDialog(
|
||||||
private val onSuccess: () -> Unit = {}
|
private val onSuccess: () -> Unit = {}
|
||||||
@ -26,6 +29,7 @@ class CreatePlaylistDialog(
|
|||||||
return@setOnClickListener
|
return@setOnClickListener
|
||||||
}
|
}
|
||||||
PlaylistsHelper.clonePlaylist(requireContext().applicationContext, playlistUrl)
|
PlaylistsHelper.clonePlaylist(requireContext().applicationContext, playlistUrl)
|
||||||
|
dismiss()
|
||||||
}
|
}
|
||||||
|
|
||||||
binding.cancelButton.setOnClickListener {
|
binding.cancelButton.setOnClickListener {
|
||||||
@ -37,11 +41,16 @@ class CreatePlaylistDialog(
|
|||||||
binding.createNewPlaylist.setOnClickListener(null)
|
binding.createNewPlaylist.setOnClickListener(null)
|
||||||
val listName = binding.playlistName.text.toString()
|
val listName = binding.playlistName.text.toString()
|
||||||
if (listName != "") {
|
if (listName != "") {
|
||||||
lifecycleScope.launchWhenCreated {
|
CoroutineScope(Dispatchers.IO).launch {
|
||||||
PlaylistsHelper.createPlaylist(listName, requireContext().applicationContext)
|
val playlistId = PlaylistsHelper.createPlaylist(
|
||||||
onSuccess.invoke()
|
listName,
|
||||||
dismiss()
|
requireContext().applicationContext
|
||||||
|
)
|
||||||
|
withContext(Dispatchers.Main) {
|
||||||
|
if (playlistId != null) onSuccess.invoke()
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
dismiss()
|
||||||
} else {
|
} else {
|
||||||
Toast.makeText(context, R.string.emptyPlaylistName, Toast.LENGTH_LONG).show()
|
Toast.makeText(context, R.string.emptyPlaylistName, Toast.LENGTH_LONG).show()
|
||||||
}
|
}
|
||||||
|
@ -33,6 +33,7 @@ import com.github.libretube.ui.models.PlayerViewModel
|
|||||||
import com.github.libretube.ui.sheets.PlaylistOptionsBottomSheet
|
import com.github.libretube.ui.sheets.PlaylistOptionsBottomSheet
|
||||||
import com.github.libretube.util.ImageHelper
|
import com.github.libretube.util.ImageHelper
|
||||||
import com.github.libretube.util.NavigationHelper
|
import com.github.libretube.util.NavigationHelper
|
||||||
|
import com.github.libretube.util.PlayingQueue
|
||||||
import com.github.libretube.util.TextUtils
|
import com.github.libretube.util.TextUtils
|
||||||
import java.io.IOException
|
import java.io.IOException
|
||||||
import retrofit2.HttpException
|
import retrofit2.HttpException
|
||||||
@ -146,14 +147,14 @@ class PlaylistFragment : BaseFragment() {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (playlistType != PlaylistType.PUBLIC) binding.bookmark.visibility = View.GONE
|
if (playlistType == PlaylistType.PUBLIC) {
|
||||||
|
|
||||||
binding.bookmark.setOnClickListener {
|
binding.bookmark.setOnClickListener {
|
||||||
isBookmarked = !isBookmarked
|
isBookmarked = !isBookmarked
|
||||||
updateBookmarkRes()
|
updateBookmarkRes()
|
||||||
query {
|
query {
|
||||||
if (!isBookmarked) {
|
if (!isBookmarked) {
|
||||||
DatabaseHolder.Database.playlistBookmarkDao().deleteById(playlistId!!)
|
DatabaseHolder.Database.playlistBookmarkDao()
|
||||||
|
.deleteById(playlistId!!)
|
||||||
} else {
|
} else {
|
||||||
DatabaseHolder.Database.playlistBookmarkDao().insertAll(
|
DatabaseHolder.Database.playlistBookmarkDao().insertAll(
|
||||||
PlaylistBookmark(
|
PlaylistBookmark(
|
||||||
@ -168,6 +169,22 @@ class PlaylistFragment : BaseFragment() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
// private playlist, means shuffle is possible because all videos are received at once
|
||||||
|
binding.bookmark.setIconResource(R.drawable.ic_shuffle)
|
||||||
|
binding.bookmark.text = getString(R.string.shuffle)
|
||||||
|
binding.bookmark.setOnClickListener {
|
||||||
|
val queue = playlistFeed.shuffled()
|
||||||
|
PlayingQueue.resetToDefaults()
|
||||||
|
PlayingQueue.add(*queue.toTypedArray())
|
||||||
|
NavigationHelper.navigateVideo(
|
||||||
|
requireContext(),
|
||||||
|
queue.first().url?.toID(),
|
||||||
|
playlistId = playlistId,
|
||||||
|
keepQueue = true
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
playlistAdapter = PlaylistAdapter(
|
playlistAdapter = PlaylistAdapter(
|
||||||
playlistFeed,
|
playlistFeed,
|
||||||
|
@ -89,7 +89,11 @@ class WatchHistoryFragment : BaseFragment() {
|
|||||||
)
|
)
|
||||||
}.toTypedArray()
|
}.toTypedArray()
|
||||||
)
|
)
|
||||||
NavigationHelper.navigateVideo(requireContext(), watchHistory.last().videoId, keepQueue = true)
|
NavigationHelper.navigateVideo(
|
||||||
|
requireContext(),
|
||||||
|
watchHistory.last().videoId,
|
||||||
|
keepQueue = true
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
// reversed order
|
// reversed order
|
||||||
|
@ -422,6 +422,7 @@
|
|||||||
<string name="hide_watched_from_feed_summary">Don\'t show videos being watched more than 90% in the subscriptions tab.</string>
|
<string name="hide_watched_from_feed_summary">Don\'t show videos being watched more than 90% in the subscriptions tab.</string>
|
||||||
<string name="playlistUrl">Playlist URL</string>
|
<string name="playlistUrl">Playlist URL</string>
|
||||||
<string name="pause_on_quit">Pause on quit</string>
|
<string name="pause_on_quit">Pause on quit</string>
|
||||||
|
<string name="shuffle">Shuffle</string>
|
||||||
|
|
||||||
<!-- Notification channel strings -->
|
<!-- Notification channel strings -->
|
||||||
<string name="download_channel_name">Download Service</string>
|
<string name="download_channel_name">Download Service</string>
|
||||||
|
Loading…
Reference in New Issue
Block a user