diff --git a/app/src/main/java/com/cappielloantonio/tempo/repository/SongRepository.java b/app/src/main/java/com/cappielloantonio/tempo/repository/SongRepository.java index 25990236..692d1e15 100644 --- a/app/src/main/java/com/cappielloantonio/tempo/repository/SongRepository.java +++ b/app/src/main/java/com/cappielloantonio/tempo/repository/SongRepository.java @@ -288,7 +288,10 @@ public class SongRepository { @Override public void onResponse(@NonNull Call call, @NonNull Response response) { List songs = new ArrayList<>(); if (response.isSuccessful() && response.body() != null && response.body().getSubsonicResponse().getRandomSongs() != null) { - songs.addAll(Objects.requireNonNull(response.body().getSubsonicResponse().getRandomSongs().getSongs())); + List randomSongs = response.body().getSubsonicResponse().getRandomSongs().getSongs(); + if (randomSongs != null) { + songs.addAll(randomSongs); + } } randomSongsSample.setValue(songs); } @@ -303,7 +306,10 @@ public class SongRepository { @Override public void onResponse(@NonNull Call call, @NonNull Response response) { List songs = new ArrayList<>(); if (response.isSuccessful() && response.body() != null && response.body().getSubsonicResponse().getRandomSongs() != null) { - songs.addAll(Objects.requireNonNull(response.body().getSubsonicResponse().getRandomSongs().getSongs())); + List randomSongs = response.body().getSubsonicResponse().getRandomSongs().getSongs(); + if (randomSongs != null) { + songs.addAll(randomSongs); + } } randomSongsSample.setValue(songs); } @@ -343,13 +349,16 @@ public class SongRepository { MutableLiveData> songsByGenre = new MutableLiveData<>(); for (String id : genresId) { App.getSubsonicClientInstance(false).getAlbumSongListClient().getSongsByGenre(id, 500, 0).enqueue(new Callback() { - @Override public void onResponse(@NonNull Call call, @NonNull Response response) { - List songs = new ArrayList<>(); - if (response.isSuccessful() && response.body() != null && response.body().getSubsonicResponse().getSongsByGenre() != null) { - songs.addAll(Objects.requireNonNull(response.body().getSubsonicResponse().getSongsByGenre().getSongs())); + @Override public void onResponse(@NonNull Call call, @NonNull Response response) { + List songs = new ArrayList<>(); + if (response.isSuccessful() && response.body() != null && response.body().getSubsonicResponse().getSongsByGenre() != null) { + List genreSongs = response.body().getSubsonicResponse().getSongsByGenre().getSongs(); + if (genreSongs != null) { + songs.addAll(genreSongs); } - songsByGenre.setValue(songs); } + songsByGenre.setValue(songs); + } @Override public void onFailure(@NonNull Call call, @NonNull Throwable t) {} }); }