From 47be372399253acffd5652f58fac2d2fad44f044 Mon Sep 17 00:00:00 2001 From: antonio Date: Tue, 14 Mar 2023 11:09:09 +0100 Subject: [PATCH] Added loading placeholders to artists page --- .../play/repository/ArtistRepository.java | 2 +- .../play/ui/fragment/ArtistPageFragment.java | 73 +++++++---- .../main/res/layout/fragment_artist_page.xml | 21 +++ .../res/layout/item_placehoder_biography.xml | 43 +++++++ .../layout/item_placeholder_large_album.xml | 120 ++++++++++++++++++ 5 files changed, 233 insertions(+), 26 deletions(-) create mode 100644 app/src/main/res/layout/item_placehoder_biography.xml create mode 100644 app/src/main/res/layout/item_placeholder_large_album.xml diff --git a/app/src/main/java/com/cappielloantonio/play/repository/ArtistRepository.java b/app/src/main/java/com/cappielloantonio/play/repository/ArtistRepository.java index 2ad1b346..03b1e02a 100644 --- a/app/src/main/java/com/cappielloantonio/play/repository/ArtistRepository.java +++ b/app/src/main/java/com/cappielloantonio/play/repository/ArtistRepository.java @@ -137,7 +137,7 @@ public class ArtistRepository { * Metodo che mi restituisce le informazioni complete dell'artista (bio, immagini prese da last.fm, artisti simili...) */ public MutableLiveData getArtistFullInfo(String id) { - MutableLiveData artistFullInfo = new MutableLiveData<>(); + MutableLiveData artistFullInfo = new MutableLiveData<>(null); App.getSubsonicClientInstance(false) .getBrowsingClient() diff --git a/app/src/main/java/com/cappielloantonio/play/ui/fragment/ArtistPageFragment.java b/app/src/main/java/com/cappielloantonio/play/ui/fragment/ArtistPageFragment.java index b9ff6ea3..4a9c5d00 100644 --- a/app/src/main/java/com/cappielloantonio/play/ui/fragment/ArtistPageFragment.java +++ b/app/src/main/java/com/cappielloantonio/play/ui/fragment/ArtistPageFragment.java @@ -108,26 +108,34 @@ public class ArtistPageFragment extends Fragment implements ClickCallback { private void initArtistInfo() { artistPageViewModel.getArtistInfo(artistPageViewModel.getArtist().getId()).observe(getViewLifecycleOwner(), artistInfo -> { - String normalizedBio = MusicUtil.forceReadableString(artistInfo.getBiography()); + if(artistInfo == null) { + if (bind != null) bind.artistPageBioPlaceholder.placeholder.setVisibility(View.VISIBLE); + if (bind != null) bind.artistPageBioSector.setVisibility(View.GONE); + } else { + String normalizedBio = MusicUtil.forceReadableString(artistInfo.getBiography()); - if (bind != null) - bind.artistPageBioSector.setVisibility(!normalizedBio.trim().isEmpty() ? View.VISIBLE : View.GONE); - if (bind != null) - bind.bioMoreTextViewClickable.setVisibility(artistInfo.getLastFmUrl() != null ? View.VISIBLE : View.GONE); + if (bind != null) + bind.artistPageBioSector.setVisibility(!normalizedBio.trim().isEmpty() ? View.VISIBLE : View.GONE); + if (bind != null) + bind.bioMoreTextViewClickable.setVisibility(artistInfo.getLastFmUrl() != null ? View.VISIBLE : View.GONE); - if (getContext() != null && bind != null) CustomGlideRequest.Builder - .from(requireContext(), artistPageViewModel.getArtist().getId()) - .build() - .transition(DrawableTransitionOptions.withCrossFade()) - .into(bind.artistBackdropImageView); + if (getContext() != null && bind != null) CustomGlideRequest.Builder + .from(requireContext(), artistPageViewModel.getArtist().getId()) + .build() + .transition(DrawableTransitionOptions.withCrossFade()) + .into(bind.artistBackdropImageView); - if (bind != null) bind.bioTextView.setText(normalizedBio); + if (bind != null) bind.bioTextView.setText(normalizedBio); - if (bind != null) bind.bioMoreTextViewClickable.setOnClickListener(v -> { - Intent intent = new Intent(Intent.ACTION_VIEW); - intent.setData(Uri.parse(artistInfo.getLastFmUrl())); - startActivity(intent); - }); + if (bind != null) bind.bioMoreTextViewClickable.setOnClickListener(v -> { + Intent intent = new Intent(Intent.ACTION_VIEW); + intent.setData(Uri.parse(artistInfo.getLastFmUrl())); + startActivity(intent); + }); + + if (bind != null) bind.artistPageBioPlaceholder.placeholder.setVisibility(View.GONE); + if (bind != null) bind.artistPageBioSector.setVisibility(View.VISIBLE); + } }); } @@ -161,9 +169,14 @@ public class ArtistPageFragment extends Fragment implements ClickCallback { songHorizontalAdapter = new SongHorizontalAdapter(this, true); bind.mostStreamedSongRecyclerView.setAdapter(songHorizontalAdapter); artistPageViewModel.getArtistTopSongList().observe(getViewLifecycleOwner(), songs -> { - if (bind != null) - bind.artistPageTopSongsSector.setVisibility(!songs.isEmpty() ? View.VISIBLE : View.GONE); - songHorizontalAdapter.setItems(songs); + if (songs == null) { + if (bind != null) bind.artistPageTopTracksPlaceholder.placeholder.setVisibility(View.VISIBLE); + if (bind != null) bind.artistPageTopSongsSector.setVisibility(View.GONE); + } else { + if (bind != null) bind.artistPageTopTracksPlaceholder.placeholder.setVisibility(View.GONE); + if (bind != null) bind.artistPageTopSongsSector.setVisibility(!songs.isEmpty() ? View.VISIBLE : View.GONE); + songHorizontalAdapter.setItems(songs); + } }); } @@ -173,9 +186,14 @@ public class ArtistPageFragment extends Fragment implements ClickCallback { albumArtistPageOrSimilarAdapter = new AlbumArtistPageOrSimilarAdapter(this); bind.albumsRecyclerView.setAdapter(albumArtistPageOrSimilarAdapter); artistPageViewModel.getAlbumList().observe(getViewLifecycleOwner(), albums -> { - if (bind != null) - bind.artistPageAlbumsSector.setVisibility(!albums.isEmpty() ? View.VISIBLE : View.GONE); - albumArtistPageOrSimilarAdapter.setItems(albums); + if (albums == null) { + if (bind != null) bind.artistPageAlbumPlaceholder.placeholder.setVisibility(View.VISIBLE); + if (bind != null) bind.artistPageAlbumsSector.setVisibility(View.GONE); + } else { + if (bind != null) bind.artistPageAlbumPlaceholder.placeholder.setVisibility(View.GONE); + if (bind != null) bind.artistPageAlbumsSector.setVisibility(!albums.isEmpty() ? View.VISIBLE : View.GONE); + albumArtistPageOrSimilarAdapter.setItems(albums); + } }); CustomLinearSnapHelper albumSnapHelper = new CustomLinearSnapHelper(); @@ -189,9 +207,14 @@ public class ArtistPageFragment extends Fragment implements ClickCallback { artistSimilarAdapter = new ArtistSimilarAdapter(this); bind.similarArtistsRecyclerView.setAdapter(artistSimilarAdapter); artistPageViewModel.getArtistInfo(artistPageViewModel.getArtist().getId()).observe(getViewLifecycleOwner(), artist -> { - if (bind != null) - bind.similarArtistSector.setVisibility(!artist.getSimilarArtists().isEmpty() ? View.VISIBLE : View.GONE); - artistSimilarAdapter.setItems(artist.getSimilarArtists()); + if (artist == null) { + if (bind != null) bind.artistPageSimilarArtistPlaceholder.placeholder.setVisibility(View.VISIBLE); + if (bind != null) bind.similarArtistSector.setVisibility(View.GONE); + } else { + if (bind != null) bind.artistPageSimilarArtistPlaceholder.placeholder.setVisibility(View.GONE); + if (bind != null) bind.similarArtistSector.setVisibility(!artist.getSimilarArtists().isEmpty() ? View.VISIBLE : View.GONE); + artistSimilarAdapter.setItems(artist.getSimilarArtists()); + } }); CustomLinearSnapHelper similarArtistSnapHelper = new CustomLinearSnapHelper(); diff --git a/app/src/main/res/layout/fragment_artist_page.xml b/app/src/main/res/layout/fragment_artist_page.xml index c36356eb..7911cab7 100644 --- a/app/src/main/res/layout/fragment_artist_page.xml +++ b/app/src/main/res/layout/fragment_artist_page.xml @@ -146,6 +146,11 @@ android:paddingBottom="8dp" /> + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/item_placehoder_biography.xml b/app/src/main/res/layout/item_placehoder_biography.xml new file mode 100644 index 00000000..ee96f095 --- /dev/null +++ b/app/src/main/res/layout/item_placehoder_biography.xml @@ -0,0 +1,43 @@ + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/item_placeholder_large_album.xml b/app/src/main/res/layout/item_placeholder_large_album.xml new file mode 100644 index 00000000..120f0442 --- /dev/null +++ b/app/src/main/res/layout/item_placeholder_large_album.xml @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file