From 1209a0a5dc3fffe0fc0904055765e94e7ab95a22 Mon Sep 17 00:00:00 2001 From: Ryan Harg <3821-ryan_harg@users.noreply.dev.funkwhale.audio> Date: Thu, 26 Aug 2021 06:44:59 +0000 Subject: [PATCH] #83: Fix invalid null handling for add to playlist --- .../audio/funkwhale/ffa/repositories/PlaylistsRepository.kt | 5 +++-- changes/changelog.d/83.bugfix | 1 + 2 files changed, 4 insertions(+), 2 deletions(-) create mode 100644 changes/changelog.d/83.bugfix diff --git a/app/src/main/java/audio/funkwhale/ffa/repositories/PlaylistsRepository.kt b/app/src/main/java/audio/funkwhale/ffa/repositories/PlaylistsRepository.kt index a496447..951f293 100644 --- a/app/src/main/java/audio/funkwhale/ffa/repositories/PlaylistsRepository.kt +++ b/app/src/main/java/audio/funkwhale/ffa/repositories/PlaylistsRepository.kt @@ -82,7 +82,7 @@ class ManagementPlaylistsRepository(override val context: Context?) : } fun add(id: Int, tracks: List) { - context?.let { + if (context != null) { val body = PlaylistAdd(tracks.map { it.id }, false) val request = Fuel.post(mustNormalizeUrl("/api/v1/playlists/$id/add/")).apply { @@ -98,8 +98,9 @@ class ManagementPlaylistsRepository(override val context: Context?) : .body(Gson().toJson(body)) .awaitByteArrayResponseResult() } + } else { + throw IllegalStateException("Illegal state: context is null") } - throw IllegalStateException("Illegal state: context is null") } suspend fun remove(id: Int, track: Track, index: Int) { diff --git a/changes/changelog.d/83.bugfix b/changes/changelog.d/83.bugfix new file mode 100644 index 0000000..0869be8 --- /dev/null +++ b/changes/changelog.d/83.bugfix @@ -0,0 +1 @@ +Fix application crash when adding song to playlist (#83) \ No newline at end of file