fix: null checking

This commit is contained in:
antonio 2023-05-27 11:58:41 +02:00
parent 24d2d201ad
commit c7151a95a8
3 changed files with 18 additions and 13 deletions

View file

@ -58,6 +58,7 @@ public class AlbumRepository {
if (response.isSuccessful() && response.body() != null && response.body().getSubsonicResponse().getStarred2() != null) { if (response.isSuccessful() && response.body() != null && response.body().getSubsonicResponse().getStarred2() != null) {
List<AlbumID3> albums = response.body().getSubsonicResponse().getStarred2().getAlbums(); List<AlbumID3> albums = response.body().getSubsonicResponse().getStarred2().getAlbums();
if (albums != null) {
if (random) { if (random) {
Collections.shuffle(albums); Collections.shuffle(albums);
starredAlbums.setValue(albums.subList(0, Math.min(size, albums.size()))); starredAlbums.setValue(albums.subList(0, Math.min(size, albums.size())));
@ -66,6 +67,7 @@ public class AlbumRepository {
} }
} }
} }
}
@Override @Override
public void onFailure(@NonNull Call<ApiResponse> call, @NonNull Throwable t) { public void onFailure(@NonNull Call<ApiResponse> call, @NonNull Throwable t) {

View file

@ -31,6 +31,7 @@ public class ArtistRepository {
if (response.isSuccessful() && response.body() != null && response.body().getSubsonicResponse().getStarred2() != null) { if (response.isSuccessful() && response.body() != null && response.body().getSubsonicResponse().getStarred2() != null) {
List<ArtistID3> artists = response.body().getSubsonicResponse().getStarred2().getArtists(); List<ArtistID3> artists = response.body().getSubsonicResponse().getStarred2().getArtists();
if (artists != null) {
if (!random) { if (!random) {
getArtistInfo(artists, starredArtists); getArtistInfo(artists, starredArtists);
} else { } else {
@ -39,6 +40,7 @@ public class ArtistRepository {
} }
} }
} }
}
@Override @Override
public void onFailure(@NonNull Call<ApiResponse> call, @NonNull Throwable t) { public void onFailure(@NonNull Call<ApiResponse> call, @NonNull Throwable t) {

View file

@ -17,7 +17,6 @@ import com.cappielloantonio.play.repository.SongRepository;
import com.cappielloantonio.play.subsonic.models.AlbumID3; import com.cappielloantonio.play.subsonic.models.AlbumID3;
import com.cappielloantonio.play.subsonic.models.ArtistID3; import com.cappielloantonio.play.subsonic.models.ArtistID3;
import com.cappielloantonio.play.subsonic.models.Child; import com.cappielloantonio.play.subsonic.models.Child;
import com.cappielloantonio.play.subsonic.models.PodcastEpisode;
import com.cappielloantonio.play.util.Preferences; import com.cappielloantonio.play.util.Preferences;
import java.util.Calendar; import java.util.Calendar;
@ -81,8 +80,10 @@ public class HomeViewModel extends AndroidViewModel {
int currentYear = Calendar.getInstance().get(Calendar.YEAR); int currentYear = Calendar.getInstance().get(Calendar.YEAR);
albumRepository.getAlbums("byYear", 500, currentYear, currentYear).observe(owner, albums -> { albumRepository.getAlbums("byYear", 500, currentYear, currentYear).observe(owner, albums -> {
if (albums != null) {
albums.sort(Comparator.comparing(AlbumID3::getCreated).reversed()); albums.sort(Comparator.comparing(AlbumID3::getCreated).reversed());
newReleasedAlbum.postValue(albums.subList(0, Math.min(20, albums.size()))); newReleasedAlbum.postValue(albums.subList(0, Math.min(20, albums.size())));
}
}); });
} }