mirror of
https://github.com/antebudimir/tempus.git
synced 2026-01-01 18:03:33 +00:00
Report the favorite elements in the home and divided the layout into sections of interest
This commit is contained in:
parent
cba5bf4b75
commit
206f2562f5
11 changed files with 644 additions and 253 deletions
|
|
@ -108,8 +108,6 @@ public class AlbumHorizontalAdapter extends RecyclerView.Adapter<AlbumHorizontal
|
|||
Navigation.findNavController(view).navigate(R.id.action_downloadFragment_to_albumPageFragment, bundle);
|
||||
} else if (Objects.requireNonNull(Navigation.findNavController(view).getCurrentDestination()).getId() == R.id.libraryFragment) {
|
||||
Navigation.findNavController(view).navigate(R.id.action_libraryFragment_to_albumPageFragment, bundle);
|
||||
} else if (Objects.requireNonNull(Navigation.findNavController(view).getCurrentDestination()).getId() == R.id.starredFragment) {
|
||||
Navigation.findNavController(view).navigate(R.id.action_starredFragment_to_albumPageFragment, bundle);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -2,21 +2,31 @@ package com.cappielloantonio.play.adapter;
|
|||
|
||||
import android.content.Context;
|
||||
import android.os.Bundle;
|
||||
import android.util.Log;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.media3.session.MediaBrowser;
|
||||
import androidx.navigation.Navigation;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
|
||||
import com.bumptech.glide.load.resource.bitmap.RoundedCorners;
|
||||
import com.cappielloantonio.play.App;
|
||||
import com.cappielloantonio.play.R;
|
||||
import com.cappielloantonio.play.glide.CustomGlideRequest;
|
||||
import com.cappielloantonio.play.interfaces.MediaCallback;
|
||||
import com.cappielloantonio.play.model.Artist;
|
||||
import com.cappielloantonio.play.model.Song;
|
||||
import com.cappielloantonio.play.repository.ArtistRepository;
|
||||
import com.cappielloantonio.play.service.MediaManager;
|
||||
import com.cappielloantonio.play.ui.activity.MainActivity;
|
||||
import com.cappielloantonio.play.util.MusicUtil;
|
||||
import com.google.common.util.concurrent.ListenableFuture;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
|
@ -26,11 +36,15 @@ public class ArtistAdapter extends RecyclerView.Adapter<ArtistAdapter.ViewHolder
|
|||
private static final String TAG = "ArtistAdapter";
|
||||
|
||||
private final LayoutInflater inflater;
|
||||
private final MainActivity mainActivity;
|
||||
private final Context context;
|
||||
|
||||
private List<Artist> artists;
|
||||
|
||||
public ArtistAdapter(Context context) {
|
||||
private ListenableFuture<MediaBrowser> 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<ArtistAdapter.ViewHolder
|
|||
notifyDataSetChanged();
|
||||
}
|
||||
|
||||
public void setMediaBrowserListenableFuture(ListenableFuture<MediaBrowser> 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<ArtistAdapter.ViewHolder
|
|||
Navigation.findNavController(view).navigate(R.id.action_libraryFragment_to_artistPageFragment, bundle);
|
||||
} else if (Objects.requireNonNull(Navigation.findNavController(view).getCurrentDestination()).getId() == R.id.artistCatalogueFragment) {
|
||||
Navigation.findNavController(view).navigate(R.id.action_artistCatalogueFragment_to_artistPageFragment, bundle);
|
||||
} else if (Objects.requireNonNull(Navigation.findNavController(view).getCurrentDestination()).getId() == R.id.homeFragment) {
|
||||
if (mediaBrowserListenableFuture != null) {
|
||||
ArtistRepository artistRepository = new ArtistRepository(App.getInstance());
|
||||
artistRepository.getInstantMix(artists.get(getBindingAdapterPosition()), 20, new MediaCallback() {
|
||||
@Override
|
||||
public void onError(Exception exception) {
|
||||
Log.e(TAG, "onError() " + exception.getMessage());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onLoadMedia(List<?> media) {
|
||||
if (media.size() > 0) {
|
||||
MediaManager.startQueue(mediaBrowserListenableFuture, context, (ArrayList<Song>) media, 0);
|
||||
mainActivity.setBottomSheetInPeek(true);
|
||||
} else {
|
||||
Toast.makeText(context, context.getString(R.string.artist_error_retrieving_radio), Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -110,13 +110,13 @@ public class ArtistHorizontalAdapter extends RecyclerView.Adapter<ArtistHorizont
|
|||
Bundle bundle = new Bundle();
|
||||
bundle.putParcelable("artist_object", artists.get(getBindingAdapterPosition()));
|
||||
|
||||
if (Objects.requireNonNull(Navigation.findNavController(view).getCurrentDestination()).getId() == R.id.artistListPageFragment) {
|
||||
if (Objects.requireNonNull(Navigation.findNavController(view).getCurrentDestination()).getId() == R.id.homeFragment) {
|
||||
Navigation.findNavController(view).navigate(R.id.action_homeFragment_to_artistPageFragment, bundle);
|
||||
} else if (Objects.requireNonNull(Navigation.findNavController(view).getCurrentDestination()).getId() == R.id.artistListPageFragment) {
|
||||
if (!isDownloaded) Navigation.findNavController(view).navigate(R.id.action_artistListPageFragment_to_artistPageFragment, bundle);
|
||||
else Navigation.findNavController(view).navigate(R.id.action_artistListPageFragment_to_albumListPageFragment, bundle);
|
||||
} else if (Objects.requireNonNull(Navigation.findNavController(view).getCurrentDestination()).getId() == R.id.downloadFragment) {
|
||||
Navigation.findNavController(view).navigate(R.id.action_downloadFragment_to_albumListPageFragment, bundle);
|
||||
} else if (Objects.requireNonNull(Navigation.findNavController(view).getCurrentDestination()).getId() == R.id.starredFragment) {
|
||||
Navigation.findNavController(view).navigate(R.id.action_starredFragment_to_artistPageFragment, bundle);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -27,6 +27,9 @@ import androidx.viewpager2.widget.ViewPager2;
|
|||
|
||||
import com.cappielloantonio.play.R;
|
||||
import com.cappielloantonio.play.adapter.AlbumAdapter;
|
||||
import com.cappielloantonio.play.adapter.AlbumHorizontalAdapter;
|
||||
import com.cappielloantonio.play.adapter.ArtistAdapter;
|
||||
import com.cappielloantonio.play.adapter.ArtistHorizontalAdapter;
|
||||
import com.cappielloantonio.play.adapter.DiscoverSongAdapter;
|
||||
import com.cappielloantonio.play.adapter.SimilarTrackAdapter;
|
||||
import com.cappielloantonio.play.adapter.SongHorizontalAdapter;
|
||||
|
|
@ -35,6 +38,7 @@ import com.cappielloantonio.play.databinding.FragmentHomeBinding;
|
|||
import com.cappielloantonio.play.helper.recyclerview.CustomLinearSnapHelper;
|
||||
import com.cappielloantonio.play.helper.recyclerview.DotsIndicatorDecoration;
|
||||
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.service.MediaService;
|
||||
|
|
@ -55,11 +59,16 @@ public class HomeFragment extends Fragment {
|
|||
private HomeViewModel homeViewModel;
|
||||
|
||||
private DiscoverSongAdapter discoverSongAdapter;
|
||||
private SimilarTrackAdapter similarMusicAdapter;
|
||||
private ArtistAdapter radioArtistAdapter;
|
||||
private SongHorizontalAdapter starredSongAdapter;
|
||||
private AlbumHorizontalAdapter starredAlbumAdapter;
|
||||
private ArtistHorizontalAdapter starredArtistAdapter;
|
||||
private AlbumAdapter recentlyAddedAlbumAdapter;
|
||||
private AlbumAdapter recentlyPlayedAlbumAdapter;
|
||||
private AlbumAdapter mostPlayedAlbumAdapter;
|
||||
private AlbumHorizontalAdapter newReleasesAlbumAdapter;
|
||||
private YearAdapter yearAdapter;
|
||||
private SimilarTrackAdapter similarMusicAdapter;
|
||||
|
||||
private ListenableFuture<MediaBrowser> 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);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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) {
|
||||
|
|
|
|||
|
|
@ -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();
|
||||
|
|
|
|||
|
|
@ -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<List<Song>> dicoverSongSample = new MutableLiveData<>(null);
|
||||
private final MutableLiveData<List<Album>> newReleasedAlbum = new MutableLiveData<>(null);
|
||||
private final MutableLiveData<List<Song>> starredTracksSample = new MutableLiveData<>(null);
|
||||
private final MutableLiveData<List<Artist>> starredArtistsSample = new MutableLiveData<>(null);
|
||||
private final MutableLiveData<List<Song>> starredTracks = new MutableLiveData<>(null);
|
||||
private final MutableLiveData<List<Album>> starredAlbums = new MutableLiveData<>(null);
|
||||
private final MutableLiveData<List<Artist>> starredArtists = new MutableLiveData<>(null);
|
||||
private final MutableLiveData<List<Album>> mostPlayedAlbumSample = new MutableLiveData<>(null);
|
||||
private final MutableLiveData<List<Album>> recentlyPlayedAlbumSample = new MutableLiveData<>(null);
|
||||
private final MutableLiveData<List<Integer>> 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<List<Song>> getDiscoverSongSample() {
|
||||
return dicoverSongSample;
|
||||
}
|
||||
|
||||
public LiveData<List<Album>> 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<List<Song>> getStarredTracksSample() {
|
||||
return starredTracksSample;
|
||||
}
|
||||
|
||||
public LiveData<List<Artist>> getStarredArtistsSample() {
|
||||
return starredArtistsSample;
|
||||
}
|
||||
|
||||
public LiveData<List<Song>> getStarredTracks(LifecycleOwner owner) {
|
||||
songRepository.getStarredSongs(true, 20).observe(owner, starredTracks::postValue);
|
||||
return starredTracks;
|
||||
}
|
||||
|
||||
public LiveData<List<Album>> getStarredAlbums(LifecycleOwner owner) {
|
||||
albumRepository.getStarredAlbums(true, 20).observe(owner, starredAlbums::postValue);
|
||||
return starredAlbums;
|
||||
}
|
||||
|
||||
public LiveData<List<Artist>> getStarredArtists(LifecycleOwner owner) {
|
||||
artistRepository.getStarredArtists(true, 20).observe(owner, starredArtists::postValue);
|
||||
return starredArtists;
|
||||
}
|
||||
|
||||
public LiveData<List<Integer>> 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);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue