mirror of
https://github.com/libre-tube/LibreTube.git
synced 2025-04-29 16:30:31 +05:30
Fix adding videos to a playlist
This commit is contained in:
parent
10d6ad7633
commit
f5f6bb2356
@ -18,7 +18,6 @@ import com.github.libretube.extensions.toastFromMainThread
|
||||
import com.github.libretube.ui.models.PlaylistViewModel
|
||||
import com.github.libretube.util.PlayingQueue
|
||||
import com.google.android.material.dialog.MaterialAlertDialogBuilder
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.launch
|
||||
|
||||
/**
|
||||
@ -75,16 +74,18 @@ class AddToPlaylistDialog(
|
||||
binding.addToPlaylist.setOnClickListener {
|
||||
val index = binding.playlistsSpinner.selectedItemPosition
|
||||
viewModel.lastSelectedPlaylistId = response[index].id!!
|
||||
dialog?.hide()
|
||||
lifecycleScope.launch {
|
||||
addToPlaylist(response[index].id!!)
|
||||
dialog?.dismiss()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun addToPlaylist(playlistId: String) {
|
||||
private suspend fun addToPlaylist(playlistId: String) {
|
||||
val appContext = context?.applicationContext ?: return
|
||||
lifecycleScope.launch(Dispatchers.IO) {
|
||||
val streams = when {
|
||||
videoId != null -> listOf(
|
||||
RetrofitInstance.api.getStreams(videoId).toStreamItem(videoId)
|
||||
@ -97,13 +98,12 @@ class AddToPlaylistDialog(
|
||||
} catch (e: Exception) {
|
||||
Log.e(TAG(), e.toString())
|
||||
appContext.toastFromMainThread(R.string.unknown_error)
|
||||
return@launch
|
||||
return
|
||||
}
|
||||
appContext.toastFromMainThread(
|
||||
if (success) R.string.added_to_playlist else R.string.fail
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
private fun Fragment?.runOnUiThread(action: () -> Unit) {
|
||||
this ?: return
|
||||
|
Loading…
x
Reference in New Issue
Block a user