From 206f2562f556405302187f2acb9a696fa9d77174 Mon Sep 17 00:00:00 2001 From: CappielloAntonio Date: Mon, 17 Jan 2022 17:32:59 +0100 Subject: [PATCH] Report the favorite elements in the home and divided the layout into sections of interest --- .../play/adapter/AlbumHorizontalAdapter.java | 2 - .../play/adapter/ArtistAdapter.java | 40 ++- .../play/adapter/ArtistHorizontalAdapter.java | 6 +- .../play/ui/fragment/HomeFragment.java | 270 +++++++++++++-- .../play/ui/fragment/LibraryFragment.java | 25 +- .../play/ui/fragment/SearchFragment.java | 2 +- .../play/viewmodel/HomeViewModel.java | 58 ++++ app/src/main/res/layout/fragment_home.xml | 323 ++++++++++++++++-- app/src/main/res/layout/fragment_library.xml | 106 ------ app/src/main/res/navigation/nav_graph.xml | 62 +--- app/src/main/res/values/strings.xml | 3 + 11 files changed, 644 insertions(+), 253 deletions(-) diff --git a/app/src/main/java/com/cappielloantonio/play/adapter/AlbumHorizontalAdapter.java b/app/src/main/java/com/cappielloantonio/play/adapter/AlbumHorizontalAdapter.java index 1f79aab1..09c0881c 100644 --- a/app/src/main/java/com/cappielloantonio/play/adapter/AlbumHorizontalAdapter.java +++ b/app/src/main/java/com/cappielloantonio/play/adapter/AlbumHorizontalAdapter.java @@ -108,8 +108,6 @@ public class AlbumHorizontalAdapter extends RecyclerView.Adapter artists; - public ArtistAdapter(Context context) { + private ListenableFuture mediaBrowserListenableFuture; + + public ArtistAdapter(MainActivity mainActivity, Context context) { + this.mainActivity = mainActivity; this.context = context; this.inflater = LayoutInflater.from(context); this.artists = new ArrayList<>(); @@ -70,6 +84,10 @@ public class ArtistAdapter extends RecyclerView.Adapter mediaBrowserListenableFuture) { + this.mediaBrowserListenableFuture = mediaBrowserListenableFuture; + } + public class ViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener, View.OnLongClickListener { TextView textArtistName; ImageView cover; @@ -95,6 +113,26 @@ public class ArtistAdapter extends RecyclerView.Adapter media) { + if (media.size() > 0) { + MediaManager.startQueue(mediaBrowserListenableFuture, context, (ArrayList) media, 0); + mainActivity.setBottomSheetInPeek(true); + } else { + Toast.makeText(context, context.getString(R.string.artist_error_retrieving_radio), Toast.LENGTH_SHORT).show(); + } + } + }); + } } } diff --git a/app/src/main/java/com/cappielloantonio/play/adapter/ArtistHorizontalAdapter.java b/app/src/main/java/com/cappielloantonio/play/adapter/ArtistHorizontalAdapter.java index 083c3fed..c8f97d42 100644 --- a/app/src/main/java/com/cappielloantonio/play/adapter/ArtistHorizontalAdapter.java +++ b/app/src/main/java/com/cappielloantonio/play/adapter/ArtistHorizontalAdapter.java @@ -110,13 +110,13 @@ public class ArtistHorizontalAdapter extends RecyclerView.Adapter mediaBrowserListenableFuture; @@ -97,8 +106,13 @@ public class HomeFragment extends Fragment { initAppBar(); initDiscoverSongSlideView(); initSimilarSongView(); + initArtistRadio(); + initStarredTracksView(); + initStarredAlbumsView(); + initStarredArtistsView(); initMostPlayedAlbumView(); initRecentPlayedAlbumView(); + initNewReleasesView(); initYearSongView(); initRecentAddedAlbumView(); initPinnedPlaylistsView(); @@ -146,6 +160,39 @@ public class HomeFragment extends Fragment { } private void init() { + bind.musicDiscoveryTextViewRefreshable.setOnLongClickListener(v -> { + homeViewModel.refreshDiscoverySongSample(requireActivity()); + return true; + }); + + bind.similarTracksTextViewRefreshable.setOnLongClickListener(v -> { + homeViewModel.refreshSimilarSongSample(requireActivity()); + return true; + }); + + bind.recentlyRadioArtistTextViewRefreshable.setOnLongClickListener(v -> { + homeViewModel.refreshRadioArtistSample(requireActivity()); + return true; + }); + + bind.starredTracksTextViewClickable.setOnClickListener(v -> { + Bundle bundle = new Bundle(); + bundle.putString(Song.STARRED, Song.STARRED); + activity.navController.navigate(R.id.action_homeFragment_to_songListPageFragment, bundle); + }); + + bind.starredAlbumsTextViewClickable.setOnClickListener(v -> { + Bundle bundle = new Bundle(); + bundle.putString(Album.STARRED, Album.STARRED); + activity.navController.navigate(R.id.action_homeFragment_to_albumListPageFragment, bundle); + }); + + bind.starredArtistsTextViewClickable.setOnClickListener(v -> { + Bundle bundle = new Bundle(); + bundle.putString(Artist.STARRED, Artist.STARRED); + activity.navController.navigate(R.id.action_homeFragment_to_artistListPageFragment, bundle); + }); + bind.recentlyAddedAlbumsTextViewClickable.setOnClickListener(v -> { Bundle bundle = new Bundle(); bundle.putString(Album.RECENTLY_ADDED, Album.RECENTLY_ADDED); @@ -164,13 +211,18 @@ public class HomeFragment extends Fragment { activity.navController.navigate(R.id.action_homeFragment_to_albumListPageFragment, bundle); }); - bind.musicDiscoveryTextViewRefreshable.setOnLongClickListener(v -> { - homeViewModel.refreshDiscoverySongSample(requireActivity()); + bind.starredTracksTextViewRefreshable.setOnLongClickListener(v -> { + homeViewModel.refreshStarredTracks(requireActivity()); return true; }); - bind.similarTracksTextViewRefreshable.setOnLongClickListener(v -> { - homeViewModel.refreshSimilarSongSample(requireActivity()); + bind.starredAlbumsTextViewRefreshable.setOnLongClickListener(v -> { + homeViewModel.refreshStarredAlbums(requireActivity()); + return true; + }); + + bind.starredArtistsTextViewRefreshable.setOnLongClickListener(v -> { + homeViewModel.refreshStarredArtists(requireActivity()); return true; }); @@ -238,6 +290,184 @@ public class HomeFragment extends Fragment { similarSongSnapHelper.attachToRecyclerView(bind.similarTracksRecyclerView); } + private void initArtistRadio() { + bind.radioArtistRecyclerView.setLayoutManager(new LinearLayoutManager(requireContext(), LinearLayoutManager.HORIZONTAL, false)); + bind.radioArtistRecyclerView.setHasFixedSize(true); + + radioArtistAdapter = new ArtistAdapter((MainActivity) requireActivity(), requireContext()); + bind.radioArtistRecyclerView.setAdapter(radioArtistAdapter); + homeViewModel.getStarredArtistsSample().observe(requireActivity(), artists -> { + if (artists == null) { + if (bind != null) bind.homeRadioArtistPlaceholder.placeholder.setVisibility(View.VISIBLE); + if (bind != null) bind.homeRadioArtistSector.setVisibility(View.GONE); + } else { + if (bind != null) bind.homeRadioArtistPlaceholder.placeholder.setVisibility(View.GONE); + if (bind != null) bind.homeRadioArtistSector.setVisibility(!artists.isEmpty() ? View.VISIBLE : View.GONE); + + radioArtistAdapter.setItems(artists); + } + }); + + CustomLinearSnapHelper artistRadioSnapHelper = new CustomLinearSnapHelper(); + artistRadioSnapHelper.attachToRecyclerView(bind.radioArtistRecyclerView); + } + + private void initStarredTracksView() { + bind.starredTracksRecyclerView.setHasFixedSize(true); + + starredSongAdapter = new SongHorizontalAdapter(activity, requireContext(), true); + bind.starredTracksRecyclerView.setAdapter(starredSongAdapter); + homeViewModel.getStarredTracks(requireActivity()).observe(requireActivity(), songs -> { + if (songs == null) { + if (bind != null) bind.starredTracksPlaceholder.placeholder.setVisibility(View.VISIBLE); + if (bind != null) bind.starredTracksSector.setVisibility(View.GONE); + } else { + if (bind != null) bind.starredTracksPlaceholder.placeholder.setVisibility(View.GONE); + if (bind != null) bind.starredTracksSector.setVisibility(!songs.isEmpty() ? View.VISIBLE : View.GONE); + if (bind != null) + bind.starredTracksRecyclerView.setLayoutManager(new GridLayoutManager(requireContext(), UIUtil.getSpanCount(songs.size(), 5), GridLayoutManager.HORIZONTAL, false)); + + starredSongAdapter.setItems(songs); + } + }); + + SnapHelper starredTrackSnapHelper = new PagerSnapHelper(); + starredTrackSnapHelper.attachToRecyclerView(bind.starredTracksRecyclerView); + + bind.starredTracksRecyclerView.addItemDecoration( + new DotsIndicatorDecoration( + getResources().getDimensionPixelSize(R.dimen.radius), + getResources().getDimensionPixelSize(R.dimen.radius) * 4, + getResources().getDimensionPixelSize(R.dimen.dots_height), + requireContext().getResources().getColor(R.color.titleTextColor, null), + requireContext().getResources().getColor(R.color.titleTextColor, null)) + ); + } + + private void initStarredAlbumsView() { + bind.starredAlbumsRecyclerView.setHasFixedSize(true); + + starredAlbumAdapter = new AlbumHorizontalAdapter(requireContext(), false); + bind.starredAlbumsRecyclerView.setAdapter(starredAlbumAdapter); + homeViewModel.getStarredAlbums(requireActivity()).observe(requireActivity(), albums -> { + if (albums == null) { + if (bind != null) bind.starredAlbumsPlaceholder.placeholder.setVisibility(View.VISIBLE); + if (bind != null) bind.starredAlbumsSector.setVisibility(View.GONE); + } else { + if (bind != null) bind.starredAlbumsPlaceholder.placeholder.setVisibility(View.GONE); + if (bind != null) bind.starredAlbumsSector.setVisibility(!albums.isEmpty() ? View.VISIBLE : View.GONE); + if (bind != null) + bind.starredAlbumsRecyclerView.setLayoutManager(new GridLayoutManager(requireContext(), UIUtil.getSpanCount(albums.size(), 5), GridLayoutManager.HORIZONTAL, false)); + + starredAlbumAdapter.setItems(albums); + } + }); + + SnapHelper starredAlbumSnapHelper = new PagerSnapHelper(); + starredAlbumSnapHelper.attachToRecyclerView(bind.starredAlbumsRecyclerView); + + bind.starredAlbumsRecyclerView.addItemDecoration( + new DotsIndicatorDecoration( + getResources().getDimensionPixelSize(R.dimen.radius), + getResources().getDimensionPixelSize(R.dimen.radius) * 4, + getResources().getDimensionPixelSize(R.dimen.dots_height), + requireContext().getResources().getColor(R.color.titleTextColor, null), + requireContext().getResources().getColor(R.color.titleTextColor, null)) + ); + } + + private void initStarredArtistsView() { + bind.starredArtistsRecyclerView.setHasFixedSize(true); + + starredArtistAdapter = new ArtistHorizontalAdapter(requireContext(), false); + bind.starredArtistsRecyclerView.setAdapter(starredArtistAdapter); + homeViewModel.getStarredArtists(requireActivity()).observe(requireActivity(), artists -> { + if (artists == null) { + if (bind != null) bind.starredArtistsPlaceholder.placeholder.setVisibility(View.VISIBLE); + if (bind != null) bind.starredArtistsSector.setVisibility(View.GONE); + } else { + if (bind != null) bind.starredArtistsPlaceholder.placeholder.setVisibility(View.GONE); + if (bind != null) bind.starredArtistsSector.setVisibility(!artists.isEmpty() ? View.VISIBLE : View.GONE); + if (bind != null) + bind.starredArtistsRecyclerView.setLayoutManager(new GridLayoutManager(requireContext(), UIUtil.getSpanCount(artists.size(), 5), GridLayoutManager.HORIZONTAL, false)); + + starredArtistAdapter.setItems(artists); + } + }); + + SnapHelper starredArtistSnapHelper = new PagerSnapHelper(); + starredArtistSnapHelper.attachToRecyclerView(bind.starredArtistsRecyclerView); + + bind.starredArtistsRecyclerView.addItemDecoration( + new DotsIndicatorDecoration( + getResources().getDimensionPixelSize(R.dimen.radius), + getResources().getDimensionPixelSize(R.dimen.radius) * 4, + getResources().getDimensionPixelSize(R.dimen.dots_height), + requireContext().getResources().getColor(R.color.titleTextColor, null), + requireContext().getResources().getColor(R.color.titleTextColor, null)) + ); + } + + private void initNewReleasesView() { + bind.newReleasesRecyclerView.setHasFixedSize(true); + + newReleasesAlbumAdapter = new AlbumHorizontalAdapter(requireContext(), false); + bind.newReleasesRecyclerView.setAdapter(newReleasesAlbumAdapter); + homeViewModel.getRecentlyReleasedAlbums(requireActivity()).observe(requireActivity(), albums -> { + if (albums == null) { + if (bind != null) bind.homeNewReleasesPlaceholder.placeholder.setVisibility(View.VISIBLE); + if (bind != null) bind.homeNewReleasesSector.setVisibility(View.GONE); + } else { + if (bind != null) bind.homeNewReleasesPlaceholder.placeholder.setVisibility(View.GONE); + if (bind != null) bind.homeNewReleasesSector.setVisibility(!albums.isEmpty() ? View.VISIBLE : View.GONE); + if (bind != null) + bind.newReleasesRecyclerView.setLayoutManager(new GridLayoutManager(requireContext(), UIUtil.getSpanCount(albums.size(), 5), GridLayoutManager.HORIZONTAL, false)); + + newReleasesAlbumAdapter.setItems(albums); + } + }); + + SnapHelper newReleasesSnapHelper = new PagerSnapHelper(); + newReleasesSnapHelper.attachToRecyclerView(bind.newReleasesRecyclerView); + + bind.newReleasesRecyclerView.addItemDecoration( + new DotsIndicatorDecoration( + getResources().getDimensionPixelSize(R.dimen.radius), + getResources().getDimensionPixelSize(R.dimen.radius) * 4, + getResources().getDimensionPixelSize(R.dimen.dots_height), + requireContext().getResources().getColor(R.color.titleTextColor, null), + requireContext().getResources().getColor(R.color.titleTextColor, null)) + ); + } + + private void initYearSongView() { + bind.yearsRecyclerView.setLayoutManager(new LinearLayoutManager(requireContext(), LinearLayoutManager.HORIZONTAL, false)); + bind.yearsRecyclerView.setHasFixedSize(true); + + yearAdapter = new YearAdapter(requireContext()); + yearAdapter.setClickListener((view, position) -> { + Bundle bundle = new Bundle(); + bundle.putString(Song.BY_YEAR, Song.BY_YEAR); + bundle.putInt("year_object", yearAdapter.getItem(position)); + activity.navController.navigate(R.id.action_homeFragment_to_songListPageFragment, bundle); + }); + bind.yearsRecyclerView.setAdapter(yearAdapter); + homeViewModel.getYearList(requireActivity()).observe(requireActivity(), years -> { + if (years == null) { + if (bind != null) bind.homeFlashbackPlaceholder.placeholder.setVisibility(View.VISIBLE); + if (bind != null) bind.homeFlashbackSector.setVisibility(View.GONE); + } else { + if (bind != null) bind.homeFlashbackPlaceholder.placeholder.setVisibility(View.GONE); + if (bind != null) bind.homeFlashbackSector.setVisibility(!years.isEmpty() ? View.VISIBLE : View.GONE); + + yearAdapter.setItems(years); + } + }); + + CustomLinearSnapHelper yearSnapHelper = new CustomLinearSnapHelper(); + yearSnapHelper.attachToRecyclerView(bind.yearsRecyclerView); + } + private void initMostPlayedAlbumView() { bind.mostPlayedAlbumsRecyclerView.setLayoutManager(new LinearLayoutManager(requireContext(), LinearLayoutManager.HORIZONTAL, false)); bind.mostPlayedAlbumsRecyclerView.setHasFixedSize(true); @@ -283,34 +513,6 @@ public class HomeFragment extends Fragment { recentPlayedAlbumSnapHelper.attachToRecyclerView(bind.recentlyPlayedAlbumsRecyclerView); } - private void initYearSongView() { - bind.yearsRecyclerView.setLayoutManager(new LinearLayoutManager(requireContext(), LinearLayoutManager.HORIZONTAL, false)); - bind.yearsRecyclerView.setHasFixedSize(true); - - yearAdapter = new YearAdapter(requireContext()); - yearAdapter.setClickListener((view, position) -> { - Bundle bundle = new Bundle(); - bundle.putString(Song.BY_YEAR, Song.BY_YEAR); - bundle.putInt("year_object", yearAdapter.getItem(position)); - activity.navController.navigate(R.id.action_homeFragment_to_songListPageFragment, bundle); - }); - bind.yearsRecyclerView.setAdapter(yearAdapter); - homeViewModel.getYearList(requireActivity()).observe(requireActivity(), years -> { - if (years == null) { - if (bind != null) bind.homeFlashbackPlaceholder.placeholder.setVisibility(View.VISIBLE); - if (bind != null) bind.homeFlashbackSector.setVisibility(View.GONE); - } else { - if (bind != null) bind.homeFlashbackPlaceholder.placeholder.setVisibility(View.GONE); - if (bind != null) bind.homeFlashbackSector.setVisibility(!years.isEmpty() ? View.VISIBLE : View.GONE); - - yearAdapter.setItems(years); - } - }); - - CustomLinearSnapHelper yearSnapHelper = new CustomLinearSnapHelper(); - yearSnapHelper.attachToRecyclerView(bind.yearsRecyclerView); - } - private void initRecentAddedAlbumView() { bind.recentlyAddedAlbumsRecyclerView.setLayoutManager(new LinearLayoutManager(requireContext(), LinearLayoutManager.HORIZONTAL, false)); bind.recentlyAddedAlbumsRecyclerView.setHasFixedSize(true); @@ -430,5 +632,7 @@ public class HomeFragment extends Fragment { private void setMediaBrowserListenableFuture() { discoverSongAdapter.setMediaBrowserListenableFuture(mediaBrowserListenableFuture); similarMusicAdapter.setMediaBrowserListenableFuture(mediaBrowserListenableFuture); + starredSongAdapter.setMediaBrowserListenableFuture(mediaBrowserListenableFuture); + radioArtistAdapter.setMediaBrowserListenableFuture(mediaBrowserListenableFuture); } } diff --git a/app/src/main/java/com/cappielloantonio/play/ui/fragment/LibraryFragment.java b/app/src/main/java/com/cappielloantonio/play/ui/fragment/LibraryFragment.java index 709d13fe..a4840865 100644 --- a/app/src/main/java/com/cappielloantonio/play/ui/fragment/LibraryFragment.java +++ b/app/src/main/java/com/cappielloantonio/play/ui/fragment/LibraryFragment.java @@ -86,9 +86,6 @@ public class LibraryFragment extends Fragment { super.onViewCreated(view, savedInstanceState); initAppBar(); - initNewReleasesShortcut(); - initStarredShortcut(); - initGenresShortcut(); initAlbumView(); initArtistView(); initGenreView(); @@ -153,26 +150,6 @@ public class LibraryFragment extends Fragment { Objects.requireNonNull(bind.toolbar.getOverflowIcon()).setTint(requireContext().getResources().getColor(R.color.titleTextColor, null)); } - private void initNewReleasesShortcut() { - bind.libraryNewReleasesSector.setOnClickListener(view -> { - Bundle bundle = new Bundle(); - bundle.putString(Album.NEW_RELEASES, Album.NEW_RELEASES); - activity.navController.navigate(R.id.action_libraryFragment_to_albumListPageFragment, bundle); - }); - } - - private void initStarredShortcut() { - bind.libraryStarredSector.setOnClickListener(view -> { - activity.navController.navigate(R.id.action_libraryFragment_to_starredFragment); - }); - } - - private void initGenresShortcut() { - bind.libraryGenresShortcutSector.setOnClickListener(view -> { - activity.navController.navigate(R.id.action_libraryFragment_to_genreCatalogueFragment); - }); - } - private void initAlbumView() { bind.albumRecyclerView.setLayoutManager(new LinearLayoutManager(requireContext(), LinearLayoutManager.HORIZONTAL, false)); bind.albumRecyclerView.setHasFixedSize(true); @@ -199,7 +176,7 @@ public class LibraryFragment extends Fragment { bind.artistRecyclerView.setLayoutManager(new LinearLayoutManager(requireContext(), LinearLayoutManager.HORIZONTAL, false)); bind.artistRecyclerView.setHasFixedSize(true); - artistAdapter = new ArtistAdapter(requireContext()); + artistAdapter = new ArtistAdapter((MainActivity) requireActivity(), requireContext()); bind.artistRecyclerView.setAdapter(artistAdapter); libraryViewModel.getArtistSample().observe(requireActivity(), artists -> { if (artists == null) { diff --git a/app/src/main/java/com/cappielloantonio/play/ui/fragment/SearchFragment.java b/app/src/main/java/com/cappielloantonio/play/ui/fragment/SearchFragment.java index 5ab03d29..8208fbd8 100644 --- a/app/src/main/java/com/cappielloantonio/play/ui/fragment/SearchFragment.java +++ b/app/src/main/java/com/cappielloantonio/play/ui/fragment/SearchFragment.java @@ -91,7 +91,7 @@ public class SearchFragment extends Fragment { bind.searchResultArtistRecyclerView.setLayoutManager(new LinearLayoutManager(requireContext(), LinearLayoutManager.HORIZONTAL, false)); bind.searchResultArtistRecyclerView.setHasFixedSize(true); - artistAdapter = new ArtistAdapter(requireContext()); + artistAdapter = new ArtistAdapter((MainActivity) requireActivity(), requireContext()); bind.searchResultArtistRecyclerView.setAdapter(artistAdapter); CustomLinearSnapHelper artistSnapHelper = new CustomLinearSnapHelper(); diff --git a/app/src/main/java/com/cappielloantonio/play/viewmodel/HomeViewModel.java b/app/src/main/java/com/cappielloantonio/play/viewmodel/HomeViewModel.java index 37f33ef7..5bc628ba 100644 --- a/app/src/main/java/com/cappielloantonio/play/viewmodel/HomeViewModel.java +++ b/app/src/main/java/com/cappielloantonio/play/viewmodel/HomeViewModel.java @@ -10,14 +10,18 @@ import androidx.lifecycle.MutableLiveData; import com.cappielloantonio.play.App; import com.cappielloantonio.play.model.Album; +import com.cappielloantonio.play.model.Artist; import com.cappielloantonio.play.model.Playlist; import com.cappielloantonio.play.model.Song; import com.cappielloantonio.play.repository.AlbumRepository; +import com.cappielloantonio.play.repository.ArtistRepository; import com.cappielloantonio.play.repository.PlaylistRepository; import com.cappielloantonio.play.repository.SongRepository; import com.cappielloantonio.play.util.PreferenceUtil; +import java.util.Calendar; import java.util.Collections; +import java.util.Comparator; import java.util.List; public class HomeViewModel extends AndroidViewModel { @@ -25,10 +29,16 @@ public class HomeViewModel extends AndroidViewModel { private final SongRepository songRepository; private final AlbumRepository albumRepository; + private final ArtistRepository artistRepository; private final PlaylistRepository playlistRepository; private final MutableLiveData> dicoverSongSample = new MutableLiveData<>(null); + private final MutableLiveData> newReleasedAlbum = new MutableLiveData<>(null); private final MutableLiveData> starredTracksSample = new MutableLiveData<>(null); + private final MutableLiveData> starredArtistsSample = new MutableLiveData<>(null); + private final MutableLiveData> starredTracks = new MutableLiveData<>(null); + private final MutableLiveData> starredAlbums = new MutableLiveData<>(null); + private final MutableLiveData> starredArtists = new MutableLiveData<>(null); private final MutableLiveData> mostPlayedAlbumSample = new MutableLiveData<>(null); private final MutableLiveData> recentlyPlayedAlbumSample = new MutableLiveData<>(null); private final MutableLiveData> years = new MutableLiveData<>(null); @@ -40,20 +50,52 @@ public class HomeViewModel extends AndroidViewModel { songRepository = new SongRepository(application); albumRepository = new AlbumRepository(application); + artistRepository = new ArtistRepository(application); playlistRepository = new PlaylistRepository(application); songRepository.getRandomSample(10, null, null).observeForever(dicoverSongSample::postValue); songRepository.getStarredSongs(true, 10).observeForever(starredTracksSample::postValue); + artistRepository.getStarredArtists(true, 10).observeForever(starredArtistsSample::postValue); } public LiveData> getDiscoverSongSample() { return dicoverSongSample; } + public LiveData> getRecentlyReleasedAlbums(LifecycleOwner owner) { + int currentYear = Calendar.getInstance().get(Calendar.YEAR); + + albumRepository.getAlbums("byYear", 500, currentYear, currentYear).observe(owner, albums -> { + albums.sort(Comparator.comparing(Album::getCreated).reversed()); + newReleasedAlbum.postValue(albums.subList(0, Math.min(20, albums.size()))); + }); + + return newReleasedAlbum; + } + public LiveData> getStarredTracksSample() { return starredTracksSample; } + public LiveData> getStarredArtistsSample() { + return starredArtistsSample; + } + + public LiveData> getStarredTracks(LifecycleOwner owner) { + songRepository.getStarredSongs(true, 20).observe(owner, starredTracks::postValue); + return starredTracks; + } + + public LiveData> getStarredAlbums(LifecycleOwner owner) { + albumRepository.getStarredAlbums(true, 20).observe(owner, starredAlbums::postValue); + return starredAlbums; + } + + public LiveData> getStarredArtists(LifecycleOwner owner) { + artistRepository.getStarredArtists(true, 20).observe(owner, starredArtists::postValue); + return starredArtists; + } + public LiveData> getYearList(LifecycleOwner owner) { albumRepository.getDecades().observe(owner, years::postValue); return years; @@ -95,6 +137,22 @@ public class HomeViewModel extends AndroidViewModel { songRepository.getStarredSongs(true, 10).observe(owner, starredTracksSample::postValue); } + public void refreshRadioArtistSample(LifecycleOwner owner) { + artistRepository.getStarredArtists(true, 10).observe(owner, starredArtistsSample::postValue); + } + + public void refreshStarredTracks(LifecycleOwner owner) { + songRepository.getStarredSongs(true, 20).observe(owner, starredTracks::postValue); + } + + public void refreshStarredAlbums(LifecycleOwner owner) { + albumRepository.getStarredAlbums(true, 20).observe(owner, starredAlbums::postValue); + } + + public void refreshStarredArtists(LifecycleOwner owner) { + artistRepository.getStarredArtists(true, 20).observe(owner, starredArtists::postValue); + } + public void refreshMostPlayedAlbums(LifecycleOwner owner) { albumRepository.getAlbums("frequent", 20, null, null).observe(owner, mostPlayedAlbumSample::postValue); } diff --git a/app/src/main/res/layout/fragment_home.xml b/app/src/main/res/layout/fragment_home.xml index b2068a0a..e0b16662 100644 --- a/app/src/main/res/layout/fragment_home.xml +++ b/app/src/main/res/layout/fragment_home.xml @@ -129,6 +129,294 @@ layout="@layout/item_placeholder_album" android:visibility="gone" /> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + - - - - - - - - https://undraw.co/ unDraw A special thanks goes to unDraw without whose illustrations we could not have made this application more beautiful + See all + Radio artist + New releases \ No newline at end of file