Hide sector in home and library if there are no elements to show

This commit is contained in:
CappielloAntonio 2021-04-19 17:16:05 +02:00
parent bdfa4a6f64
commit 93e7550e74
4 changed files with 22 additions and 4 deletions

View file

@ -138,7 +138,10 @@ public class HomeFragment extends Fragment {
favoriteSongAdapter = new SongResultSearchAdapter(activity, requireContext(), getChildFragmentManager());
bind.favoritesTracksRecyclerView.setAdapter(favoriteSongAdapter);
homeViewModel.getFavorites().observe(requireActivity(), songs -> favoriteSongAdapter.setItems(songs));
homeViewModel.getFavorites().observe(requireActivity(), songs -> {
bind.homeFavoriteTracksSector.setVisibility(songs.size() > 0 ? View.VISIBLE : View.GONE);
favoriteSongAdapter.setItems(songs);
});
PagerSnapHelper pagerSnapHelper = new PagerSnapHelper();
pagerSnapHelper.attachToRecyclerView(bind.favoritesTracksRecyclerView);
@ -150,7 +153,10 @@ public class HomeFragment extends Fragment {
mostPlayedMusicAdapter = new RecentMusicAdapter(activity, requireContext(), getChildFragmentManager());
bind.mostPlayedTracksRecyclerView.setAdapter(mostPlayedMusicAdapter);
homeViewModel.getMostPlayedSongList().observe(requireActivity(), songs -> mostPlayedMusicAdapter.setItems(songs));
homeViewModel.getMostPlayedSongList().observe(requireActivity(), songs -> {
bind.homeMostPlayedTracksSector.setVisibility(songs.size() > 0 ? View.VISIBLE : View.GONE);
mostPlayedMusicAdapter.setItems(songs);
});
}
private void initRecentPlayedSongView() {
@ -159,7 +165,10 @@ public class HomeFragment extends Fragment {
recentlyPlayedMusicAdapter = new RecentMusicAdapter(activity, requireContext(), getChildFragmentManager());
bind.recentlyPlayedTracksRecyclerView.setAdapter(recentlyPlayedMusicAdapter);
homeViewModel.getRecentlyPlayedSongList().observe(requireActivity(), songs -> recentlyPlayedMusicAdapter.setItems(songs));
homeViewModel.getRecentlyPlayedSongList().observe(requireActivity(), songs -> {
bind.homeRecentlyPlayedTracksSector.setVisibility(songs.size() > 0 ? View.VISIBLE : View.GONE);
recentlyPlayedMusicAdapter.setItems(songs);
});
}
private void setDiscoverSongSlideViewOffset(float pageOffset, float pageMargin) {

View file

@ -113,7 +113,10 @@ public class LibraryFragment extends Fragment {
playlistAdapter = new PlaylistAdapter(requireContext());
bind.playlistRecyclerView.setAdapter(playlistAdapter);
libraryViewModel.getPlaylistList().observe(requireActivity(), playlists -> playlistAdapter.setItems(playlists));
libraryViewModel.getPlaylistList().observe(requireActivity(), playlists -> {
bind.libraryPlaylistSector.setVisibility(playlists.size() > 0 ? View.VISIBLE : View.GONE);
playlistAdapter.setItems(playlists);
});
}
private void initCatalogueSyncCheck() {

View file

@ -42,6 +42,7 @@
<!-- Recently added tracks -->
<LinearLayout
android:id="@+id/home_recently_added_tracks_sector"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
@ -98,6 +99,7 @@
<!-- Fashback -->
<LinearLayout
android:id="@+id/home_flashback_sector"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
@ -130,6 +132,7 @@
<!-- Favorites -->
<LinearLayout
android:id="@+id/home_favorite_tracks_sector"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
@ -184,6 +187,7 @@
<!-- Most played tracks -->
<LinearLayout
android:id="@+id/home_most_played_tracks_sector"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
@ -240,6 +244,7 @@
<!-- Recently played tracks -->
<LinearLayout
android:id="@+id/home_recently_played_tracks_sector"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">

View file

@ -201,6 +201,7 @@
</LinearLayout>
<LinearLayout
android:id="@+id/library_playlist_sector"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"