Fix crash when adding to playlist while instance down

This commit is contained in:
Bnyro 2023-04-10 13:38:48 +02:00
parent 5b2d502f89
commit ed67d09779

View File

@ -80,13 +80,16 @@ class AddToPlaylistDialog(
private suspend fun addToPlaylist(playlistId: String) { private suspend fun addToPlaylist(playlistId: String) {
val appContext = context?.applicationContext ?: return val appContext = context?.applicationContext ?: return
val streams = when { val streams = when {
videoId != null -> listOf( videoId != null -> listOfNotNull(
RetrofitInstance.api.getStreams(videoId).toStreamItem(videoId) runCatching {
RetrofitInstance.api.getStreams(videoId!!).toStreamItem(videoId)
}.getOrNull()
) )
else -> PlayingQueue.getStreams() else -> PlayingQueue.getStreams()
} }
val success = try { val success = try {
if (streams.isEmpty()) throw IllegalArgumentException()
PlaylistsHelper.addToPlaylist(playlistId, *streams.toTypedArray()) PlaylistsHelper.addToPlaylist(playlistId, *streams.toTypedArray())
} catch (e: Exception) { } catch (e: Exception) {
Log.e(TAG(), e.toString()) Log.e(TAG(), e.toString())