Fix null checking

This commit is contained in:
CappielloAntonio 2021-08-20 11:25:20 +02:00
parent aa10a68a86
commit 3801b55abf
2 changed files with 6 additions and 8 deletions

View file

@ -69,11 +69,10 @@ public class ArtistRepository {
artists.addAll(MappingUtil.mapArtist(index.getArtists())); artists.addAll(MappingUtil.mapArtist(index.getArtists()));
} }
if(random) { if (random) {
Collections.shuffle(artists); Collections.shuffle(artists);
getArtistInfo(artists.subList(0, artists.size() / size > 0 ? size : artists.size()), listLiveArtists); getArtistInfo(artists.subList(0, artists.size() / size > 0 ? size : artists.size()), listLiveArtists);
} } else {
else {
listLiveArtists.setValue(artists); listLiveArtists.setValue(artists);
} }
} }
@ -92,7 +91,7 @@ public class ArtistRepository {
*/ */
public void getArtistInfo(List<Artist> artists, MutableLiveData<List<Artist>> list) { public void getArtistInfo(List<Artist> artists, MutableLiveData<List<Artist>> list) {
List<Artist> liveArtists = list.getValue(); List<Artist> liveArtists = list.getValue();
if(liveArtists == null) liveArtists = new ArrayList<>(); if (liveArtists == null) liveArtists = new ArrayList<>();
list.setValue(liveArtists); list.setValue(liveArtists);
for (Artist artist : artists) { for (Artist artist : artists) {
@ -146,7 +145,7 @@ public class ArtistRepository {
.enqueue(new Callback<SubsonicResponse>() { .enqueue(new Callback<SubsonicResponse>() {
@Override @Override
public void onResponse(Call<SubsonicResponse> call, Response<SubsonicResponse> response) { public void onResponse(Call<SubsonicResponse> call, Response<SubsonicResponse> response) {
artistFullInfo.setValue(MappingUtil.mapArtist(response.body().getArtistInfo2())); if (response.body().getArtistInfo2() != null) artistFullInfo.setValue(MappingUtil.mapArtist(response.body().getArtistInfo2()));
} }
@Override @Override
@ -270,7 +269,7 @@ public class ArtistRepository {
for (int index = 0; index < albums.size(); index++) { for (int index = 0; index < albums.size(); index++) {
albumRepository.getAlbumTracks(albums.get(index).getId()).observe(fragmentActivity, songs -> { albumRepository.getAlbumTracks(albums.get(index).getId()).observe(fragmentActivity, songs -> {
ArrayList<Song> liveSongs = randomSongs.getValue(); ArrayList<Song> liveSongs = randomSongs.getValue();
if(liveSongs == null) liveSongs = new ArrayList<>(); if (liveSongs == null) liveSongs = new ArrayList<>();
Collections.shuffle(liveSongs); Collections.shuffle(liveSongs);
liveSongs.addAll(songs); liveSongs.addAll(songs);
randomSongs.setValue(liveSongs); randomSongs.setValue(liveSongs);

View file

@ -113,13 +113,12 @@ public class ArtistPageFragment extends Fragment {
} }
private void initArtistInfo() { private void initArtistInfo() {
artistPageViewModel.getArtistInfo(artistPageViewModel.getArtist().getId()).observe(requireActivity(), artist -> { artistPageViewModel.getArtistInfo(artistPageViewModel.getArtist().getId()).observe(requireActivity(), artist -> {
if (bind != null) bind.artistPageBioSector.setVisibility(artist.getBio() != null ? View.VISIBLE : View.GONE); if (bind != null) bind.artistPageBioSector.setVisibility(artist.getBio() != null ? View.VISIBLE : View.GONE);
if (bind != null) bind.bioMoreTextViewClickable.setVisibility(artist.getLastfm() != null ? View.VISIBLE : View.GONE); if (bind != null) bind.bioMoreTextViewClickable.setVisibility(artist.getLastfm() != null ? View.VISIBLE : View.GONE);
CustomGlideRequest.Builder CustomGlideRequest.Builder
.from(requireContext(), null, CustomGlideRequest.ARTIST_PIC, artist.getImageUrl()) .from(requireContext(), /*artistPageViewModel.getArtist().getId()*/ null, CustomGlideRequest.ARTIST_PIC, artist.getImageUrl())
.build() .build()
.into(bind.artistBackdropImageView); .into(bind.artistBackdropImageView);