From c29e36c697ef2affe81ec2cacf409dde7135413a Mon Sep 17 00:00:00 2001
From: Mouath Ibrahim <funkwhale-gitlab@mouath.com>
Date: Fri, 25 Feb 2022 09:35:01 +0000
Subject: [PATCH] Bugfix/113 fix invalid null handling playlist

---
 .../ffa/repositories/PlaylistsRepository.kt          | 12 +++++++-----
 changes/changelog.d/113.bugfix                       |  1 +
 2 files changed, 8 insertions(+), 5 deletions(-)
 create mode 100644 changes/changelog.d/113.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 daf119a6..0dca88df 100644
--- a/app/src/main/java/audio/funkwhale/ffa/repositories/PlaylistsRepository.kt
+++ b/app/src/main/java/audio/funkwhale/ffa/repositories/PlaylistsRepository.kt
@@ -108,7 +108,7 @@ class ManagementPlaylistsRepository(override val context: Context?) :
   }
 
   suspend fun remove(albumId: Int, index: Int) {
-    context?.let {
+    if (context != null) {
       val body = mapOf("index" to index)
 
       val request = Fuel.post(mustNormalizeUrl("/api/v1/playlists/$albumId/remove/")).apply {
@@ -122,12 +122,13 @@ class ManagementPlaylistsRepository(override val context: Context?) :
         .header("Content-Type", "application/json")
         .body(Gson().toJson(body))
         .awaitByteArrayResponseResult()
-    }
-    throw IllegalStateException("Illegal state: context is null")
+    } else {
+      throw IllegalStateException("Illegal state: context is null")
+   }
   }
 
   fun move(id: Int, from: Int, to: Int) {
-    context?.let {
+    if (context != null) {
       val body = mapOf("from" to from, "to" to to)
 
       val request = Fuel.post(mustNormalizeUrl("/api/v1/playlists/$id/move/")).apply {
@@ -143,7 +144,8 @@ 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")
   }
 }
diff --git a/changes/changelog.d/113.bugfix b/changes/changelog.d/113.bugfix
new file mode 100644
index 00000000..db684330
--- /dev/null
+++ b/changes/changelog.d/113.bugfix
@@ -0,0 +1 @@
+Fix App crashes when interacting with playlist
-- 
GitLab