Added loading placeholders to artists page

This commit is contained in:
antonio 2023-03-14 11:09:09 +01:00
parent 40cfbef4d7
commit 47be372399
5 changed files with 233 additions and 26 deletions

View file

@ -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<ArtistInfo2> getArtistFullInfo(String id) {
MutableLiveData<ArtistInfo2> artistFullInfo = new MutableLiveData<>();
MutableLiveData<ArtistInfo2> artistFullInfo = new MutableLiveData<>(null);
App.getSubsonicClientInstance(false)
.getBrowsingClient()

View file

@ -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();

View file

@ -146,6 +146,11 @@
android:paddingBottom="8dp" />
</LinearLayout>
<include
android:id="@+id/artist_page_bio_placeholder"
layout="@layout/item_placehoder_biography"
android:visibility="gone" />
<!-- Label and button -->
<LinearLayout
android:id="@+id/artist_page_top_songs_sector"
@ -187,6 +192,11 @@
android:paddingTop="8dp" />
</LinearLayout>
<include
android:id="@+id/artist_page_top_tracks_placeholder"
layout="@layout/item_placeholder_horizontal"
android:visibility="gone" />
<LinearLayout
android:id="@+id/artist_page_albums_sector"
android:layout_width="match_parent"
@ -215,6 +225,11 @@
android:paddingBottom="8dp" />
</LinearLayout>
<include
android:id="@+id/artist_page_album_placeholder"
layout="@layout/item_placeholder_album"
android:visibility="gone" />
<LinearLayout
android:id="@+id/similar_artist_sector"
android:layout_width="match_parent"
@ -243,6 +258,12 @@
android:paddingBottom="8dp" />
</LinearLayout>
<include
android:id="@+id/artist_page_similar_artist_placeholder"
layout="@layout/item_placeholder_album"
android:visibility="gone" />
</LinearLayout>
</androidx.core.widget.NestedScrollView>
</androidx.coordinatorlayout.widget.CoordinatorLayout>

View file

@ -0,0 +1,43 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/placeholder"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:paddingStart="8dp"
android:paddingTop="8dp"
android:paddingEnd="8dp">
<ImageView
android:layout_width="12dp"
android:layout_height="24dp"
android:layout_marginStart="8dp"
android:layout_marginTop="12dp"
android:layout_marginEnd="8dp"
android:layout_weight="9"
android:background="?attr/colorSurface" />
<ImageView
android:layout_width="12dp"
android:layout_height="24dp"
android:layout_marginStart="8dp"
android:layout_marginTop="12dp"
android:layout_marginEnd="8dp"
android:layout_weight="1"
android:background="?attr/colorSurface" />
</LinearLayout>
<ImageView
android:layout_width="match_parent"
android:layout_height="156dp"
android:layout_marginStart="16dp"
android:layout_marginTop="16dp"
android:layout_marginEnd="16dp"
android:layout_marginBottom="8dp"
android:background="?attr/colorSurface" />
</LinearLayout>

View file

@ -0,0 +1,120 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/placeholder"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:paddingStart="8dp"
android:paddingTop="8dp"
android:paddingEnd="8dp">
<ImageView
android:layout_width="12dp"
android:layout_height="24dp"
android:layout_marginStart="8dp"
android:layout_marginTop="12dp"
android:layout_marginEnd="8dp"
android:layout_weight="8"
android:background="?attr/colorSurface" />
<ImageView
android:layout_width="12dp"
android:layout_height="14dp"
android:layout_marginStart="8dp"
android:layout_marginTop="22dp"
android:layout_marginEnd="8dp"
android:layout_weight="2"
android:background="?attr/colorSurface" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:layout_marginBottom="8dp"
android:clipToPadding="false"
android:orientation="horizontal"
android:paddingTop="8dp"
android:paddingBottom="8dp">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
android:paddingStart="16dp"
android:paddingEnd="8dp">
<ImageView
android:layout_width="172dp"
android:layout_height="172dp"
android:layout_gravity="center"
android:background="?attr/colorSurface" />
<ImageView
android:layout_width="124dp"
android:layout_height="14dp"
android:layout_marginTop="8dp"
android:background="?attr/colorSurface" />
<ImageView
android:layout_width="112dp"
android:layout_height="12dp"
android:layout_marginTop="4dp"
android:background="?attr/colorSurface" />
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
android:paddingEnd="8dp">
<ImageView
android:layout_width="172dp"
android:layout_height="172dp"
android:layout_gravity="center"
android:background="?attr/colorSurface" />
<ImageView
android:layout_width="124dp"
android:layout_height="14dp"
android:layout_marginTop="8dp"
android:background="?attr/colorSurface" />
<ImageView
android:layout_width="112dp"
android:layout_height="12dp"
android:layout_marginTop="4dp"
android:background="?attr/colorSurface" />
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical">
<ImageView
android:layout_width="172dp"
android:layout_height="172dp"
android:layout_gravity="center"
android:background="?attr/colorSurface" />
<ImageView
android:layout_width="124dp"
android:layout_height="14dp"
android:layout_marginTop="8dp"
android:background="?attr/colorSurface" />
<ImageView
android:layout_width="112dp"
android:layout_height="12dp"
android:layout_marginTop="4dp"
android:background="?attr/colorSurface" />
</LinearLayout>
</LinearLayout>
</LinearLayout>