mirror of
https://github.com/libre-tube/LibreTube.git
synced 2024-12-13 22:00:30 +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)
|
||||
return null
|
||||
}
|
||||
Log.e("created pl", response.playlistId.toString())
|
||||
if (response.playlistId != null) {
|
||||
appContext.toastFromMainThread(R.string.playlistCreated)
|
||||
return response.playlistId!!
|
||||
|
@ -4,12 +4,15 @@ import android.app.Dialog
|
||||
import android.os.Bundle
|
||||
import android.widget.Toast
|
||||
import androidx.fragment.app.DialogFragment
|
||||
import androidx.lifecycle.lifecycleScope
|
||||
import com.github.libretube.R
|
||||
import com.github.libretube.api.PlaylistsHelper
|
||||
import com.github.libretube.databinding.DialogCreatePlaylistBinding
|
||||
import com.github.libretube.util.TextUtils
|
||||
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(
|
||||
private val onSuccess: () -> Unit = {}
|
||||
@ -26,6 +29,7 @@ class CreatePlaylistDialog(
|
||||
return@setOnClickListener
|
||||
}
|
||||
PlaylistsHelper.clonePlaylist(requireContext().applicationContext, playlistUrl)
|
||||
dismiss()
|
||||
}
|
||||
|
||||
binding.cancelButton.setOnClickListener {
|
||||
@ -37,11 +41,16 @@ class CreatePlaylistDialog(
|
||||
binding.createNewPlaylist.setOnClickListener(null)
|
||||
val listName = binding.playlistName.text.toString()
|
||||
if (listName != "") {
|
||||
lifecycleScope.launchWhenCreated {
|
||||
PlaylistsHelper.createPlaylist(listName, requireContext().applicationContext)
|
||||
onSuccess.invoke()
|
||||
dismiss()
|
||||
CoroutineScope(Dispatchers.IO).launch {
|
||||
val playlistId = PlaylistsHelper.createPlaylist(
|
||||
listName,
|
||||
requireContext().applicationContext
|
||||
)
|
||||
withContext(Dispatchers.Main) {
|
||||
if (playlistId != null) onSuccess.invoke()
|
||||
}
|
||||
}
|
||||
dismiss()
|
||||
} else {
|
||||
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.util.ImageHelper
|
||||
import com.github.libretube.util.NavigationHelper
|
||||
import com.github.libretube.util.PlayingQueue
|
||||
import com.github.libretube.util.TextUtils
|
||||
import java.io.IOException
|
||||
import retrofit2.HttpException
|
||||
@ -146,27 +147,43 @@ class PlaylistFragment : BaseFragment() {
|
||||
)
|
||||
}
|
||||
|
||||
if (playlistType != PlaylistType.PUBLIC) binding.bookmark.visibility = View.GONE
|
||||
|
||||
binding.bookmark.setOnClickListener {
|
||||
isBookmarked = !isBookmarked
|
||||
updateBookmarkRes()
|
||||
query {
|
||||
if (!isBookmarked) {
|
||||
DatabaseHolder.Database.playlistBookmarkDao().deleteById(playlistId!!)
|
||||
} else {
|
||||
DatabaseHolder.Database.playlistBookmarkDao().insertAll(
|
||||
PlaylistBookmark(
|
||||
playlistId = playlistId!!,
|
||||
playlistName = response.name,
|
||||
thumbnailUrl = response.thumbnailUrl,
|
||||
uploader = response.uploader,
|
||||
uploaderAvatar = response.uploaderAvatar,
|
||||
uploaderUrl = response.uploaderUrl
|
||||
if (playlistType == PlaylistType.PUBLIC) {
|
||||
binding.bookmark.setOnClickListener {
|
||||
isBookmarked = !isBookmarked
|
||||
updateBookmarkRes()
|
||||
query {
|
||||
if (!isBookmarked) {
|
||||
DatabaseHolder.Database.playlistBookmarkDao()
|
||||
.deleteById(playlistId!!)
|
||||
} else {
|
||||
DatabaseHolder.Database.playlistBookmarkDao().insertAll(
|
||||
PlaylistBookmark(
|
||||
playlistId = playlistId!!,
|
||||
playlistName = response.name,
|
||||
thumbnailUrl = response.thumbnailUrl,
|
||||
uploader = response.uploader,
|
||||
uploaderAvatar = response.uploaderAvatar,
|
||||
uploaderUrl = response.uploaderUrl
|
||||
)
|
||||
)
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
} 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(
|
||||
|
@ -89,7 +89,11 @@ class WatchHistoryFragment : BaseFragment() {
|
||||
)
|
||||
}.toTypedArray()
|
||||
)
|
||||
NavigationHelper.navigateVideo(requireContext(), watchHistory.last().videoId, keepQueue = true)
|
||||
NavigationHelper.navigateVideo(
|
||||
requireContext(),
|
||||
watchHistory.last().videoId,
|
||||
keepQueue = true
|
||||
)
|
||||
}
|
||||
|
||||
// reversed order
|
||||
@ -128,14 +132,14 @@ class WatchHistoryFragment : BaseFragment() {
|
||||
|
||||
// observe changes
|
||||
watchHistoryAdapter.registerAdapterDataObserver(object :
|
||||
RecyclerView.AdapterDataObserver() {
|
||||
override fun onItemRangeRemoved(positionStart: Int, itemCount: Int) {
|
||||
if (watchHistoryAdapter.itemCount == 0) {
|
||||
binding.historyScrollView.visibility = View.GONE
|
||||
binding.historyEmpty.visibility = View.VISIBLE
|
||||
}
|
||||
RecyclerView.AdapterDataObserver() {
|
||||
override fun onItemRangeRemoved(positionStart: Int, itemCount: Int) {
|
||||
if (watchHistoryAdapter.itemCount == 0) {
|
||||
binding.historyScrollView.visibility = View.GONE
|
||||
binding.historyEmpty.visibility = View.VISIBLE
|
||||
}
|
||||
})
|
||||
}
|
||||
})
|
||||
|
||||
binding.watchHistoryRecView.adapter = watchHistoryAdapter
|
||||
binding.historyEmpty.visibility = View.GONE
|
||||
|
@ -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="playlistUrl">Playlist URL</string>
|
||||
<string name="pause_on_quit">Pause on quit</string>
|
||||
<string name="shuffle">Shuffle</string>
|
||||
|
||||
<!-- Notification channel strings -->
|
||||
<string name="download_channel_name">Download Service</string>
|
||||
|
Loading…
Reference in New Issue
Block a user