fix: return an empty list instead of null

This commit is contained in:
antonio 2023-06-04 18:38:11 +02:00
parent a57487d38d
commit 86713eb0fd
2 changed files with 6 additions and 4 deletions

View file

@ -10,6 +10,7 @@ import com.cappielloantonio.play.subsonic.base.ApiResponse;
import com.cappielloantonio.play.subsonic.models.PodcastChannel;
import com.cappielloantonio.play.subsonic.models.PodcastEpisode;
import java.util.ArrayList;
import java.util.List;
import retrofit2.Call;
@ -20,7 +21,7 @@ public class PodcastRepository {
private static final String TAG = "PodcastRepository";
public MutableLiveData<List<PodcastChannel>> getPodcastChannels(boolean includeEpisodes, String channelId) {
MutableLiveData<List<PodcastChannel>> livePodcastChannel = new MutableLiveData<>();
MutableLiveData<List<PodcastChannel>> livePodcastChannel = new MutableLiveData<>(new ArrayList<>());
App.getSubsonicClientInstance(false)
.getPodcastClient()
@ -43,7 +44,7 @@ public class PodcastRepository {
}
public MutableLiveData<List<PodcastEpisode>> getNewestPodcastEpisodes(int count) {
MutableLiveData<List<PodcastEpisode>> liveNewestPodcastEpisodes = new MutableLiveData<>();
MutableLiveData<List<PodcastEpisode>> liveNewestPodcastEpisodes = new MutableLiveData<>(new ArrayList<>());
App.getSubsonicClientInstance(false)
.getPodcastClient()

View file

@ -7,6 +7,7 @@ import com.cappielloantonio.play.App;
import com.cappielloantonio.play.subsonic.base.ApiResponse;
import com.cappielloantonio.play.subsonic.models.InternetRadioStation;
import java.util.ArrayList;
import java.util.List;
import retrofit2.Call;
@ -15,7 +16,7 @@ import retrofit2.Response;
public class RadioRepository {
public MutableLiveData<List<InternetRadioStation>> getInternetRadioStations() {
MutableLiveData<List<InternetRadioStation>> radioStation = new MutableLiveData<>();
MutableLiveData<List<InternetRadioStation>> radioStation = new MutableLiveData<>(new ArrayList<>());
App.getSubsonicClientInstance(false)
.getInternetRadioClient()
@ -23,7 +24,7 @@ public class RadioRepository {
.enqueue(new Callback<ApiResponse>() {
@Override
public void onResponse(@NonNull Call<ApiResponse> call, @NonNull Response<ApiResponse> response) {
if (response.isSuccessful() && response.body() != null && response.body().getSubsonicResponse().getInternetRadioStations() != null) {
if (response.isSuccessful() && response.body() != null && response.body().getSubsonicResponse().getInternetRadioStations() != null && response.body().getSubsonicResponse().getInternetRadioStations().getInternetRadioStations() != null) {
radioStation.setValue(response.body().getSubsonicResponse().getInternetRadioStations().getInternetRadioStations());
}
}