From ed67d0977974c428a1ae13d63dd4cc30d9b29c06 Mon Sep 17 00:00:00 2001 From: Bnyro Date: Mon, 10 Apr 2023 13:38:48 +0200 Subject: [PATCH] Fix crash when adding to playlist while instance down --- .../com/github/libretube/ui/dialogs/AddToPlaylistDialog.kt | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/com/github/libretube/ui/dialogs/AddToPlaylistDialog.kt b/app/src/main/java/com/github/libretube/ui/dialogs/AddToPlaylistDialog.kt index 2be47250c..2c56bcb7b 100644 --- a/app/src/main/java/com/github/libretube/ui/dialogs/AddToPlaylistDialog.kt +++ b/app/src/main/java/com/github/libretube/ui/dialogs/AddToPlaylistDialog.kt @@ -80,13 +80,16 @@ class AddToPlaylistDialog( private suspend fun addToPlaylist(playlistId: String) { val appContext = context?.applicationContext ?: return val streams = when { - videoId != null -> listOf( - RetrofitInstance.api.getStreams(videoId).toStreamItem(videoId) + videoId != null -> listOfNotNull( + runCatching { + RetrofitInstance.api.getStreams(videoId!!).toStreamItem(videoId) + }.getOrNull() ) else -> PlayingQueue.getStreams() } val success = try { + if (streams.isEmpty()) throw IllegalArgumentException() PlaylistsHelper.addToPlaylist(playlistId, *streams.toTypedArray()) } catch (e: Exception) { Log.e(TAG(), e.toString())