mirror of
https://github.com/antebudimir/tempus.git
synced 2025-12-31 17:43:32 +00:00
Add album page
This commit is contained in:
parent
c2be2711b9
commit
b2c269a051
18 changed files with 334 additions and 68 deletions
|
|
@ -10,6 +10,7 @@ import androidx.recyclerview.widget.RecyclerView;
|
||||||
|
|
||||||
import com.cappielloantonio.play.R;
|
import com.cappielloantonio.play.R;
|
||||||
import com.cappielloantonio.play.model.Album;
|
import com.cappielloantonio.play.model.Album;
|
||||||
|
import com.cappielloantonio.play.model.Artist;
|
||||||
import com.cappielloantonio.play.util.Util;
|
import com.cappielloantonio.play.util.Util;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
@ -65,6 +66,10 @@ public class AlbumAdapter extends RecyclerView.Adapter<AlbumAdapter.ViewHolder>
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Album getItem(int position) {
|
||||||
|
return albums.get(position);
|
||||||
|
}
|
||||||
|
|
||||||
public void setItems(List<Album> albums) {
|
public void setItems(List<Album> albums) {
|
||||||
this.albums = albums;
|
this.albums = albums;
|
||||||
notifyDataSetChanged();
|
notifyDataSetChanged();
|
||||||
|
|
|
||||||
|
|
@ -61,6 +61,10 @@ public class AlbumArtistPageAdapter extends RecyclerView.Adapter<AlbumArtistPage
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Album getItem(int position) {
|
||||||
|
return albums.get(position);
|
||||||
|
}
|
||||||
|
|
||||||
public void setItems(List<Album> albums) {
|
public void setItems(List<Album> albums) {
|
||||||
this.albums = albums;
|
this.albums = albums;
|
||||||
notifyDataSetChanged();
|
notifyDataSetChanged();
|
||||||
|
|
|
||||||
|
|
@ -10,6 +10,7 @@ import androidx.recyclerview.widget.RecyclerView;
|
||||||
|
|
||||||
import com.cappielloantonio.play.R;
|
import com.cappielloantonio.play.R;
|
||||||
import com.cappielloantonio.play.model.Album;
|
import com.cappielloantonio.play.model.Album;
|
||||||
|
import com.cappielloantonio.play.model.Artist;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
|
@ -64,6 +65,10 @@ public class AlbumCatalogueAdapter extends RecyclerView.Adapter<AlbumCatalogueAd
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Album getItem(int position) {
|
||||||
|
return albums.get(position);
|
||||||
|
}
|
||||||
|
|
||||||
public void setItems(List<Album> albums) {
|
public void setItems(List<Album> albums) {
|
||||||
this.albums = albums;
|
this.albums = albums;
|
||||||
notifyDataSetChanged();
|
notifyDataSetChanged();
|
||||||
|
|
|
||||||
|
|
@ -62,6 +62,10 @@ public class ArtistAdapter extends RecyclerView.Adapter<ArtistAdapter.ViewHolder
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Artist getItem(int position) {
|
||||||
|
return artists.get(position);
|
||||||
|
}
|
||||||
|
|
||||||
public void setItems(List<Artist> artists) {
|
public void setItems(List<Artist> artists) {
|
||||||
this.artists = artists;
|
this.artists = artists;
|
||||||
notifyDataSetChanged();
|
notifyDataSetChanged();
|
||||||
|
|
|
||||||
|
|
@ -35,6 +35,9 @@ public interface SongDao {
|
||||||
@Query("SELECT * FROM song WHERE play_count != 0 AND artistId = :artistID ORDER BY play_count DESC LIMIT :number")
|
@Query("SELECT * FROM song WHERE play_count != 0 AND artistId = :artistID ORDER BY play_count DESC LIMIT :number")
|
||||||
LiveData<List<Song>> getArtistTopSongsSample(String artistID, int number);
|
LiveData<List<Song>> getArtistTopSongsSample(String artistID, int number);
|
||||||
|
|
||||||
|
@Query("SELECT * FROM song WHERE albumId = :albumID ORDER BY trackNumber ASC")
|
||||||
|
LiveData<List<Song>> getAlbumSong(String albumID);
|
||||||
|
|
||||||
@Query("SELECT EXISTS(SELECT * FROM song WHERE id = :id)")
|
@Query("SELECT EXISTS(SELECT * FROM song WHERE id = :id)")
|
||||||
boolean exist(String id);
|
boolean exist(String id);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -19,6 +19,7 @@ public class SongRepository {
|
||||||
private LiveData<List<Song>> listLiveSampleRecentlyPlayedSongs;
|
private LiveData<List<Song>> listLiveSampleRecentlyPlayedSongs;
|
||||||
private LiveData<List<Song>> listLiveSampleMostPlayedSongs;
|
private LiveData<List<Song>> listLiveSampleMostPlayedSongs;
|
||||||
private LiveData<List<Song>> listLiveSampleArtistTopSongs;
|
private LiveData<List<Song>> listLiveSampleArtistTopSongs;
|
||||||
|
private LiveData<List<Song>> listLiveAlbumSongs;
|
||||||
|
|
||||||
|
|
||||||
public SongRepository(Application application) {
|
public SongRepository(Application application) {
|
||||||
|
|
@ -51,6 +52,11 @@ public class SongRepository {
|
||||||
return listLiveSampleArtistTopSongs;
|
return listLiveSampleArtistTopSongs;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public LiveData<List<Song>> getAlbumListLiveSong(String albumID) {
|
||||||
|
listLiveAlbumSongs = songDao.getAlbumSong(albumID);
|
||||||
|
return listLiveAlbumSongs;
|
||||||
|
}
|
||||||
|
|
||||||
public boolean exist(Song song) {
|
public boolean exist(Song song) {
|
||||||
boolean exist = false;
|
boolean exist = false;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -10,9 +10,11 @@ import androidx.fragment.app.Fragment;
|
||||||
import androidx.lifecycle.ViewModelProvider;
|
import androidx.lifecycle.ViewModelProvider;
|
||||||
import androidx.recyclerview.widget.GridLayoutManager;
|
import androidx.recyclerview.widget.GridLayoutManager;
|
||||||
|
|
||||||
|
import com.cappielloantonio.play.R;
|
||||||
import com.cappielloantonio.play.adapter.AlbumCatalogueAdapter;
|
import com.cappielloantonio.play.adapter.AlbumCatalogueAdapter;
|
||||||
import com.cappielloantonio.play.databinding.FragmentAlbumCatalogueBinding;
|
import com.cappielloantonio.play.databinding.FragmentAlbumCatalogueBinding;
|
||||||
import com.cappielloantonio.play.helper.recyclerview.ItemlDecoration;
|
import com.cappielloantonio.play.helper.recyclerview.ItemlDecoration;
|
||||||
|
import com.cappielloantonio.play.ui.activities.MainActivity;
|
||||||
import com.cappielloantonio.play.viewmodel.AlbumCatalogueViewModel;
|
import com.cappielloantonio.play.viewmodel.AlbumCatalogueViewModel;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
|
@ -21,12 +23,15 @@ public class AlbumCatalogueFragment extends Fragment {
|
||||||
private static final String TAG = "ArtistCatalogueFragment";
|
private static final String TAG = "ArtistCatalogueFragment";
|
||||||
|
|
||||||
private FragmentAlbumCatalogueBinding bind;
|
private FragmentAlbumCatalogueBinding bind;
|
||||||
|
private MainActivity activity;
|
||||||
private AlbumCatalogueViewModel albumCatalogueViewModel;
|
private AlbumCatalogueViewModel albumCatalogueViewModel;
|
||||||
|
|
||||||
private AlbumCatalogueAdapter albumAdapter;
|
private AlbumCatalogueAdapter albumAdapter;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
||||||
|
activity = (MainActivity) getActivity();
|
||||||
|
|
||||||
bind = FragmentAlbumCatalogueBinding.inflate(inflater, container, false);
|
bind = FragmentAlbumCatalogueBinding.inflate(inflater, container, false);
|
||||||
View view = bind.getRoot();
|
View view = bind.getRoot();
|
||||||
albumCatalogueViewModel = new ViewModelProvider(requireActivity()).get(AlbumCatalogueViewModel.class);
|
albumCatalogueViewModel = new ViewModelProvider(requireActivity()).get(AlbumCatalogueViewModel.class);
|
||||||
|
|
@ -48,7 +53,11 @@ public class AlbumCatalogueFragment extends Fragment {
|
||||||
bind.albumCatalogueRecyclerView.setHasFixedSize(true);
|
bind.albumCatalogueRecyclerView.setHasFixedSize(true);
|
||||||
|
|
||||||
albumAdapter = new AlbumCatalogueAdapter(requireContext(), new ArrayList<>());
|
albumAdapter = new AlbumCatalogueAdapter(requireContext(), new ArrayList<>());
|
||||||
albumAdapter.setClickListener((view, position) -> Toast.makeText(requireContext(), "Click: " + position, Toast.LENGTH_SHORT).show());
|
albumAdapter.setClickListener((view, position) -> {
|
||||||
|
Bundle bundle = new Bundle();
|
||||||
|
bundle.putParcelable("album_object", albumAdapter.getItem(position));
|
||||||
|
activity.navController.navigate(R.id.action_libraryFragment_to_albumPageFragment, bundle);
|
||||||
|
});
|
||||||
bind.albumCatalogueRecyclerView.setAdapter(albumAdapter);
|
bind.albumCatalogueRecyclerView.setAdapter(albumAdapter);
|
||||||
albumCatalogueViewModel.getAlbumList().observe(requireActivity(), albums -> {
|
albumCatalogueViewModel.getAlbumList().observe(requireActivity(), albums -> {
|
||||||
bind.loadingProgressBar.setVisibility(View.GONE);
|
bind.loadingProgressBar.setVisibility(View.GONE);
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,65 @@
|
||||||
|
package com.cappielloantonio.play.ui.fragment;
|
||||||
|
|
||||||
|
import android.os.Bundle;
|
||||||
|
import android.view.LayoutInflater;
|
||||||
|
import android.view.View;
|
||||||
|
import android.view.ViewGroup;
|
||||||
|
|
||||||
|
import androidx.fragment.app.Fragment;
|
||||||
|
import androidx.lifecycle.ViewModelProvider;
|
||||||
|
import androidx.recyclerview.widget.LinearLayoutManager;
|
||||||
|
|
||||||
|
import com.cappielloantonio.play.adapter.AlbumArtistPageAdapter;
|
||||||
|
import com.cappielloantonio.play.adapter.SongResultSearchAdapter;
|
||||||
|
import com.cappielloantonio.play.databinding.FragmentAlbumPageBinding;
|
||||||
|
import com.cappielloantonio.play.databinding.FragmentArtistPageBinding;
|
||||||
|
import com.cappielloantonio.play.model.Album;
|
||||||
|
import com.cappielloantonio.play.ui.activities.MainActivity;
|
||||||
|
import com.cappielloantonio.play.viewmodel.AlbumPageViewModel;
|
||||||
|
import com.cappielloantonio.play.viewmodel.ArtistPageViewModel;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
|
||||||
|
public class AlbumPageFragment extends Fragment {
|
||||||
|
|
||||||
|
private FragmentAlbumPageBinding bind;
|
||||||
|
private MainActivity activity;
|
||||||
|
private AlbumPageViewModel albumPageViewModel;
|
||||||
|
|
||||||
|
private SongResultSearchAdapter songResultSearchAdapter;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
||||||
|
activity = (MainActivity) getActivity();
|
||||||
|
|
||||||
|
bind = FragmentAlbumPageBinding.inflate(inflater, container, false);
|
||||||
|
View view = bind.getRoot();
|
||||||
|
albumPageViewModel = new ViewModelProvider(requireActivity()).get(AlbumPageViewModel.class);
|
||||||
|
|
||||||
|
init();
|
||||||
|
initSongsView();
|
||||||
|
|
||||||
|
return view;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onDestroyView() {
|
||||||
|
super.onDestroyView();
|
||||||
|
bind = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void init() {
|
||||||
|
albumPageViewModel.setAlbum(getArguments().getParcelable("album_object"));
|
||||||
|
|
||||||
|
bind.albumTitleLabel.setText(albumPageViewModel.getAlbum().getTitle());
|
||||||
|
}
|
||||||
|
|
||||||
|
private void initSongsView() {
|
||||||
|
bind.songRecyclerView.setLayoutManager(new LinearLayoutManager(requireContext()));
|
||||||
|
bind.songRecyclerView.setHasFixedSize(true);
|
||||||
|
|
||||||
|
songResultSearchAdapter = new SongResultSearchAdapter(requireContext(), new ArrayList<>());
|
||||||
|
bind.songRecyclerView.setAdapter(songResultSearchAdapter);
|
||||||
|
albumPageViewModel.getAlbumSongList().observe(requireActivity(), songs -> songResultSearchAdapter.setItems(songs));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -29,12 +29,15 @@ public class ArtistCatalogueFragment extends Fragment {
|
||||||
private static final String TAG = "ArtistCatalogueFragment";
|
private static final String TAG = "ArtistCatalogueFragment";
|
||||||
|
|
||||||
private FragmentArtistCatalogueBinding bind;
|
private FragmentArtistCatalogueBinding bind;
|
||||||
|
private MainActivity activity;
|
||||||
private ArtistCatalogueViewModel artistCatalogueViewModel;
|
private ArtistCatalogueViewModel artistCatalogueViewModel;
|
||||||
|
|
||||||
private ArtistCatalogueAdapter artistAdapter;
|
private ArtistCatalogueAdapter artistAdapter;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
||||||
|
activity = (MainActivity) getActivity();
|
||||||
|
|
||||||
bind = FragmentArtistCatalogueBinding.inflate(inflater, container, false);
|
bind = FragmentArtistCatalogueBinding.inflate(inflater, container, false);
|
||||||
View view = bind.getRoot();
|
View view = bind.getRoot();
|
||||||
artistCatalogueViewModel = new ViewModelProvider(requireActivity()).get(ArtistCatalogueViewModel.class);
|
artistCatalogueViewModel = new ViewModelProvider(requireActivity()).get(ArtistCatalogueViewModel.class);
|
||||||
|
|
@ -56,7 +59,11 @@ public class ArtistCatalogueFragment extends Fragment {
|
||||||
bind.artistCatalogueRecyclerView.setHasFixedSize(true);
|
bind.artistCatalogueRecyclerView.setHasFixedSize(true);
|
||||||
|
|
||||||
artistAdapter = new ArtistCatalogueAdapter(requireContext(), new ArrayList<>());
|
artistAdapter = new ArtistCatalogueAdapter(requireContext(), new ArrayList<>());
|
||||||
artistAdapter.setClickListener((view, position) -> Toast.makeText(requireContext(), "Click: " + position, Toast.LENGTH_SHORT).show());
|
artistAdapter.setClickListener((view, position) -> {
|
||||||
|
Bundle bundle = new Bundle();
|
||||||
|
bundle.putParcelable("artist_object", artistAdapter.getItem(position));
|
||||||
|
activity.navController.navigate(R.id.action_artistCatalogueFragment_to_artistPageFragment, bundle);
|
||||||
|
});
|
||||||
bind.artistCatalogueRecyclerView.setAdapter(artistAdapter);
|
bind.artistCatalogueRecyclerView.setAdapter(artistAdapter);
|
||||||
artistCatalogueViewModel.getArtistList().observe(requireActivity(), artists -> {
|
artistCatalogueViewModel.getArtistList().observe(requireActivity(), artists -> {
|
||||||
bind.loadingProgressBar.setVisibility(View.GONE);
|
bind.loadingProgressBar.setVisibility(View.GONE);
|
||||||
|
|
|
||||||
|
|
@ -31,8 +31,6 @@ public class ArtistPageFragment extends Fragment {
|
||||||
private SongResultSearchAdapter songResultSearchAdapter;
|
private SongResultSearchAdapter songResultSearchAdapter;
|
||||||
private AlbumArtistPageAdapter albumArtistPageAdapter;
|
private AlbumArtistPageAdapter albumArtistPageAdapter;
|
||||||
|
|
||||||
private String artistID;
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
||||||
activity = (MainActivity) getActivity();
|
activity = (MainActivity) getActivity();
|
||||||
|
|
@ -55,7 +53,9 @@ public class ArtistPageFragment extends Fragment {
|
||||||
}
|
}
|
||||||
|
|
||||||
private void init() {
|
private void init() {
|
||||||
artistID = getArguments().getString("artistID");
|
artistPageViewModel.setArtist(getArguments().getParcelable("artist_object"));
|
||||||
|
|
||||||
|
bind.artistNameLabel.setText(artistPageViewModel.getArtist().getName());
|
||||||
}
|
}
|
||||||
|
|
||||||
private void initTopSongsView() {
|
private void initTopSongsView() {
|
||||||
|
|
@ -64,7 +64,7 @@ public class ArtistPageFragment extends Fragment {
|
||||||
|
|
||||||
songResultSearchAdapter = new SongResultSearchAdapter(requireContext(), new ArrayList<>());
|
songResultSearchAdapter = new SongResultSearchAdapter(requireContext(), new ArrayList<>());
|
||||||
bind.mostStreamedSongRecyclerView.setAdapter(songResultSearchAdapter);
|
bind.mostStreamedSongRecyclerView.setAdapter(songResultSearchAdapter);
|
||||||
artistPageViewModel.getArtistTopSongList(artistID).observe(requireActivity(), songs -> songResultSearchAdapter.setItems(songs));
|
artistPageViewModel.getArtistTopSongList().observe(requireActivity(), songs -> songResultSearchAdapter.setItems(songs));
|
||||||
}
|
}
|
||||||
|
|
||||||
private void initAlbumsView() {
|
private void initAlbumsView() {
|
||||||
|
|
@ -72,7 +72,12 @@ public class ArtistPageFragment extends Fragment {
|
||||||
bind.albumsRecyclerView.setHasFixedSize(true);
|
bind.albumsRecyclerView.setHasFixedSize(true);
|
||||||
|
|
||||||
albumArtistPageAdapter = new AlbumArtistPageAdapter(requireContext(), new ArrayList<>());
|
albumArtistPageAdapter = new AlbumArtistPageAdapter(requireContext(), new ArrayList<>());
|
||||||
|
albumArtistPageAdapter.setClickListener((view, position) -> {
|
||||||
|
Bundle bundle = new Bundle();
|
||||||
|
bundle.putParcelable("album_object", albumArtistPageAdapter.getItem(position));
|
||||||
|
activity.navController.navigate(R.id.action_artistPageFragment_to_albumPageFragment, bundle);
|
||||||
|
});
|
||||||
bind.albumsRecyclerView.setAdapter(albumArtistPageAdapter);
|
bind.albumsRecyclerView.setAdapter(albumArtistPageAdapter);
|
||||||
artistPageViewModel.getAlbumList(artistID).observe(requireActivity(), songs -> albumArtistPageAdapter.setItems(songs));
|
artistPageViewModel.getAlbumList().observe(requireActivity(), songs -> albumArtistPageAdapter.setItems(songs));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -78,7 +78,11 @@ public class LibraryFragment extends Fragment {
|
||||||
bind.albumRecyclerView.setHasFixedSize(true);
|
bind.albumRecyclerView.setHasFixedSize(true);
|
||||||
|
|
||||||
albumAdapter = new AlbumAdapter(requireContext(), new ArrayList<>());
|
albumAdapter = new AlbumAdapter(requireContext(), new ArrayList<>());
|
||||||
albumAdapter.setClickListener((view, position) -> Toast.makeText(requireContext(), "Album: " + position, Toast.LENGTH_SHORT).show());
|
albumAdapter.setClickListener((view, position) -> {
|
||||||
|
Bundle bundle = new Bundle();
|
||||||
|
bundle.putParcelable("album_object", albumAdapter.getItem(position));
|
||||||
|
activity.navController.navigate(R.id.action_libraryFragment_to_albumPageFragment, bundle);
|
||||||
|
});
|
||||||
bind.albumRecyclerView.setAdapter(albumAdapter);
|
bind.albumRecyclerView.setAdapter(albumAdapter);
|
||||||
libraryViewModel.getAlbumSample().observe(requireActivity(), albums -> albumAdapter.setItems(albums));
|
libraryViewModel.getAlbumSample().observe(requireActivity(), albums -> albumAdapter.setItems(albums));
|
||||||
}
|
}
|
||||||
|
|
@ -88,7 +92,11 @@ public class LibraryFragment extends Fragment {
|
||||||
bind.artistRecyclerView.setHasFixedSize(true);
|
bind.artistRecyclerView.setHasFixedSize(true);
|
||||||
|
|
||||||
artistAdapter = new ArtistAdapter(requireContext(), new ArrayList<>());
|
artistAdapter = new ArtistAdapter(requireContext(), new ArrayList<>());
|
||||||
artistAdapter.setClickListener((view, position) -> Toast.makeText(requireContext(), "Artist: " + position, Toast.LENGTH_SHORT).show());
|
artistAdapter.setClickListener((view, position) -> {
|
||||||
|
Bundle bundle = new Bundle();
|
||||||
|
bundle.putParcelable("artist_object", artistAdapter.getItem(position));
|
||||||
|
activity.navController.navigate(R.id.action_libraryFragment_to_artistPageFragment, bundle);
|
||||||
|
});
|
||||||
bind.artistRecyclerView.setAdapter(artistAdapter);
|
bind.artistRecyclerView.setAdapter(artistAdapter);
|
||||||
libraryViewModel.getArtistSample().observe(requireActivity(), artists -> artistAdapter.setItems(artists));
|
libraryViewModel.getArtistSample().observe(requireActivity(), artists -> artistAdapter.setItems(artists));
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -99,7 +99,9 @@ public class SearchFragment extends Fragment {
|
||||||
|
|
||||||
albumResultSearchAdapter = new AlbumCatalogueAdapter(requireContext(), new ArrayList<>());
|
albumResultSearchAdapter = new AlbumCatalogueAdapter(requireContext(), new ArrayList<>());
|
||||||
albumResultSearchAdapter.setClickListener((view, position) -> {
|
albumResultSearchAdapter.setClickListener((view, position) -> {
|
||||||
Toast.makeText(requireContext(), "Album " + position, Toast.LENGTH_SHORT).show();
|
Bundle bundle = new Bundle();
|
||||||
|
bundle.putParcelable("album_object", albumResultSearchAdapter.getItem(position));
|
||||||
|
activity.navController.navigate(R.id.action_searchFragment_to_albumPageFragment, bundle);
|
||||||
});
|
});
|
||||||
bind.searchResultAlbumRecyclerView.setAdapter(albumResultSearchAdapter);
|
bind.searchResultAlbumRecyclerView.setAdapter(albumResultSearchAdapter);
|
||||||
|
|
||||||
|
|
@ -110,9 +112,8 @@ public class SearchFragment extends Fragment {
|
||||||
|
|
||||||
artistResultSearchAdapter = new ArtistCatalogueAdapter(requireContext(), new ArrayList<>());
|
artistResultSearchAdapter = new ArtistCatalogueAdapter(requireContext(), new ArrayList<>());
|
||||||
artistResultSearchAdapter.setClickListener((view, position) -> {
|
artistResultSearchAdapter.setClickListener((view, position) -> {
|
||||||
Toast.makeText(requireContext(), "Artist " + position, Toast.LENGTH_SHORT).show();
|
|
||||||
Bundle bundle = new Bundle();
|
Bundle bundle = new Bundle();
|
||||||
bundle.putString("artistID", artistResultSearchAdapter.getItem(position).id);
|
bundle.putParcelable("artist_object", artistResultSearchAdapter.getItem(position));
|
||||||
activity.navController.navigate(R.id.action_searchFragment_to_artistPageFragment, bundle);
|
activity.navController.navigate(R.id.action_searchFragment_to_artistPageFragment, bundle);
|
||||||
});
|
});
|
||||||
bind.searchResultArtistRecyclerView.setAdapter(artistResultSearchAdapter);
|
bind.searchResultArtistRecyclerView.setAdapter(artistResultSearchAdapter);
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,42 @@
|
||||||
|
package com.cappielloantonio.play.viewmodel;
|
||||||
|
|
||||||
|
import android.app.Application;
|
||||||
|
|
||||||
|
import androidx.annotation.NonNull;
|
||||||
|
import androidx.lifecycle.AndroidViewModel;
|
||||||
|
import androidx.lifecycle.LiveData;
|
||||||
|
|
||||||
|
import com.cappielloantonio.play.model.Album;
|
||||||
|
import com.cappielloantonio.play.model.Artist;
|
||||||
|
import com.cappielloantonio.play.model.Song;
|
||||||
|
import com.cappielloantonio.play.repository.AlbumRepository;
|
||||||
|
import com.cappielloantonio.play.repository.SongRepository;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class AlbumPageViewModel extends AndroidViewModel {
|
||||||
|
private SongRepository songRepository;
|
||||||
|
|
||||||
|
private LiveData<List<Song>> songList;
|
||||||
|
|
||||||
|
private Album album;
|
||||||
|
|
||||||
|
public AlbumPageViewModel(@NonNull Application application) {
|
||||||
|
super(application);
|
||||||
|
|
||||||
|
songRepository = new SongRepository(application);
|
||||||
|
}
|
||||||
|
|
||||||
|
public LiveData<List<Song>> getAlbumSongList() {
|
||||||
|
songList = songRepository.getAlbumListLiveSong(album.getId());
|
||||||
|
return songList;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Album getAlbum() {
|
||||||
|
return album;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setAlbum(Album album) {
|
||||||
|
this.album = album;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -7,6 +7,7 @@ import androidx.lifecycle.AndroidViewModel;
|
||||||
import androidx.lifecycle.LiveData;
|
import androidx.lifecycle.LiveData;
|
||||||
|
|
||||||
import com.cappielloantonio.play.model.Album;
|
import com.cappielloantonio.play.model.Album;
|
||||||
|
import com.cappielloantonio.play.model.Artist;
|
||||||
import com.cappielloantonio.play.model.Song;
|
import com.cappielloantonio.play.model.Song;
|
||||||
import com.cappielloantonio.play.repository.AlbumRepository;
|
import com.cappielloantonio.play.repository.AlbumRepository;
|
||||||
import com.cappielloantonio.play.repository.SongRepository;
|
import com.cappielloantonio.play.repository.SongRepository;
|
||||||
|
|
@ -20,6 +21,8 @@ public class ArtistPageViewModel extends AndroidViewModel {
|
||||||
private LiveData<List<Song>> songList;
|
private LiveData<List<Song>> songList;
|
||||||
private LiveData<List<Album>> albumList;
|
private LiveData<List<Album>> albumList;
|
||||||
|
|
||||||
|
private Artist artist;
|
||||||
|
|
||||||
public ArtistPageViewModel(@NonNull Application application) {
|
public ArtistPageViewModel(@NonNull Application application) {
|
||||||
super(application);
|
super(application);
|
||||||
|
|
||||||
|
|
@ -27,13 +30,21 @@ public class ArtistPageViewModel extends AndroidViewModel {
|
||||||
albumRepository = new AlbumRepository(application);
|
albumRepository = new AlbumRepository(application);
|
||||||
}
|
}
|
||||||
|
|
||||||
public LiveData<List<Album>> getAlbumList(String artistID) {
|
public LiveData<List<Album>> getAlbumList() {
|
||||||
albumList = albumRepository.getArtistListLiveAlbums(artistID);
|
albumList = albumRepository.getArtistListLiveAlbums(artist.id);
|
||||||
return albumList;
|
return albumList;
|
||||||
}
|
}
|
||||||
|
|
||||||
public LiveData<List<Song>> getArtistTopSongList(String artistID) {
|
public LiveData<List<Song>> getArtistTopSongList() {
|
||||||
songList = songRepository.getArtistListLiveTopSong(artistID);
|
songList = songRepository.getArtistListLiveTopSong(artist.id);
|
||||||
return songList;
|
return songList;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Artist getArtist() {
|
||||||
|
return artist;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setArtist(Artist artist) {
|
||||||
|
this.artist = artist;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
76
app/src/main/res/layout/fragment_album_page.xml
Normal file
76
app/src/main/res/layout/fragment_album_page.xml
Normal file
|
|
@ -0,0 +1,76 @@
|
||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<androidx.core.widget.NestedScrollView
|
||||||
|
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content">
|
||||||
|
|
||||||
|
<LinearLayout
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:orientation="vertical">
|
||||||
|
|
||||||
|
<androidx.constraintlayout.widget.ConstraintLayout
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent">
|
||||||
|
|
||||||
|
<androidx.cardview.widget.CardView
|
||||||
|
android:id="@+id/card_view"
|
||||||
|
android:layout_width="0dp"
|
||||||
|
android:layout_height="0dp"
|
||||||
|
android:backgroundTint="@color/cardColor"
|
||||||
|
app:layout_constraintDimensionRatio="W, 4:5"
|
||||||
|
app:layout_constraintLeft_toLeftOf="parent"
|
||||||
|
app:layout_constraintRight_toRightOf="parent"
|
||||||
|
app:layout_constraintTop_toTopOf="parent">
|
||||||
|
|
||||||
|
<androidx.constraintlayout.widget.ConstraintLayout
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent">
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/album_title_label"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:fontFamily="@font/open_sans_font_family"
|
||||||
|
android:textColor="@color/titleTextColor"
|
||||||
|
android:textSize="40sp"
|
||||||
|
android:textStyle="bold"
|
||||||
|
android:textAlignment="center"
|
||||||
|
android:textFontWeight="900"
|
||||||
|
android:paddingStart="20dp"
|
||||||
|
android:paddingEnd="20dp"
|
||||||
|
android:paddingBottom="32dp"
|
||||||
|
app:layout_constraintBottom_toBottomOf="parent"
|
||||||
|
app:layout_constraintEnd_toEndOf="parent"
|
||||||
|
app:layout_constraintStart_toStartOf="parent" />
|
||||||
|
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||||
|
</androidx.cardview.widget.CardView>
|
||||||
|
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||||
|
|
||||||
|
<!-- Label and button -->
|
||||||
|
<TextView
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:fontFamily="@font/open_sans_font_family"
|
||||||
|
android:paddingStart="16dp"
|
||||||
|
android:paddingTop="20dp"
|
||||||
|
android:paddingEnd="16dp"
|
||||||
|
android:text="Song"
|
||||||
|
android:textColor="@color/titleTextColor"
|
||||||
|
android:textSize="22sp"
|
||||||
|
android:textStyle="bold" />
|
||||||
|
|
||||||
|
<androidx.recyclerview.widget.RecyclerView
|
||||||
|
android:id="@+id/song_recycler_view"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent"
|
||||||
|
android:layout_marginTop="8dp"
|
||||||
|
android:layout_marginBottom="8dp"
|
||||||
|
android:clipToPadding="false"
|
||||||
|
android:paddingStart="16dp"
|
||||||
|
android:paddingTop="8dp"
|
||||||
|
android:paddingEnd="8dp"
|
||||||
|
android:paddingBottom="54dp" />
|
||||||
|
</LinearLayout>
|
||||||
|
</androidx.core.widget.NestedScrollView>
|
||||||
|
|
@ -29,14 +29,17 @@
|
||||||
android:layout_height="match_parent">
|
android:layout_height="match_parent">
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
|
android:id="@+id/artist_name_label"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:fontFamily="@font/open_sans_font_family"
|
android:fontFamily="@font/open_sans_font_family"
|
||||||
android:text="Green Day"
|
|
||||||
android:textColor="@color/titleTextColor"
|
android:textColor="@color/titleTextColor"
|
||||||
android:textSize="40sp"
|
android:textSize="40sp"
|
||||||
android:textStyle="bold"
|
android:textStyle="bold"
|
||||||
|
android:textAlignment="center"
|
||||||
android:textFontWeight="900"
|
android:textFontWeight="900"
|
||||||
|
android:paddingStart="20dp"
|
||||||
|
android:paddingEnd="20dp"
|
||||||
android:paddingBottom="32dp"
|
android:paddingBottom="32dp"
|
||||||
app:layout_constraintBottom_toBottomOf="parent"
|
app:layout_constraintBottom_toBottomOf="parent"
|
||||||
app:layout_constraintEnd_toEndOf="parent"
|
app:layout_constraintEnd_toEndOf="parent"
|
||||||
|
|
@ -115,6 +118,6 @@
|
||||||
android:paddingStart="16dp"
|
android:paddingStart="16dp"
|
||||||
android:paddingTop="8dp"
|
android:paddingTop="8dp"
|
||||||
android:paddingEnd="8dp"
|
android:paddingEnd="8dp"
|
||||||
android:paddingBottom="8dp" />
|
android:paddingBottom="54dp" />
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
</androidx.core.widget.NestedScrollView>
|
</androidx.core.widget.NestedScrollView>
|
||||||
|
|
|
||||||
|
|
@ -1,19 +1,18 @@
|
||||||
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||||
xmlns:tools="http://schemas.android.com/tools"
|
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:orientation="horizontal"
|
android:orientation="horizontal"
|
||||||
android:paddingTop="2dp"
|
android:paddingTop="2dp"
|
||||||
android:paddingBottom="2dp"
|
android:paddingEnd="4dp"
|
||||||
android:paddingEnd="4dp">
|
android:paddingBottom="2dp">
|
||||||
|
|
||||||
<androidx.cardview.widget.CardView xmlns:card_view="http://schemas.android.com/apk/res-auto"
|
<androidx.cardview.widget.CardView xmlns:card_view="http://schemas.android.com/apk/res-auto"
|
||||||
android:id="@+id/imageView"
|
android:id="@+id/imageView"
|
||||||
android:layout_width="48dp"
|
android:layout_width="48dp"
|
||||||
android:layout_height="48dp"
|
android:layout_height="48dp"
|
||||||
android:layout_margin="2dp"
|
|
||||||
android:layout_gravity="center"
|
android:layout_gravity="center"
|
||||||
|
android:layout_margin="2dp"
|
||||||
android:backgroundTint="@color/cardColor"
|
android:backgroundTint="@color/cardColor"
|
||||||
app:layout_constraintBottom_toBottomOf="parent"
|
app:layout_constraintBottom_toBottomOf="parent"
|
||||||
app:layout_constraintStart_toStartOf="parent"
|
app:layout_constraintStart_toStartOf="parent"
|
||||||
|
|
@ -22,36 +21,41 @@
|
||||||
card_view:cardCornerRadius="4dp"
|
card_view:cardCornerRadius="4dp"
|
||||||
card_view:cardElevation="2dp"
|
card_view:cardElevation="2dp"
|
||||||
card_view:cardPreventCornerOverlap="false"
|
card_view:cardPreventCornerOverlap="false"
|
||||||
card_view:cardUseCompatPadding="false"/>
|
card_view:cardUseCompatPadding="false" />
|
||||||
|
|
||||||
<TextView
|
<LinearLayout
|
||||||
android:id="@+id/search_result_song_title_text_view"
|
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="match_parent"
|
||||||
android:fontFamily="@font/open_sans_font_family"
|
android:orientation="vertical"
|
||||||
android:paddingStart="12dp"
|
android:layout_weight="1">
|
||||||
android:paddingTop="4dp"
|
|
||||||
android:text="@string/label_placeholder"
|
|
||||||
android:textColor="@color/titleTextColor"
|
|
||||||
android:textSize="14sp"
|
|
||||||
android:textStyle="bold"
|
|
||||||
app:layout_constraintStart_toEndOf="@+id/imageView"
|
|
||||||
app:layout_constraintTop_toTopOf="parent"
|
|
||||||
app:layout_constraintBottom_toTopOf="@id/search_result_song_artist_text_view"/>
|
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
android:id="@+id/search_result_song_artist_text_view"
|
android:id="@+id/search_result_song_title_text_view"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="0dp"
|
||||||
android:fontFamily="@font/open_sans_font_family"
|
android:layout_weight="1"
|
||||||
android:paddingStart="12dp"
|
android:ellipsize="end"
|
||||||
android:paddingBottom="4dp"
|
android:fontFamily="@font/open_sans_font_family"
|
||||||
android:text="@string/label_placeholder"
|
android:maxLines="1"
|
||||||
android:textColor="@color/subtitleTextColor"
|
android:paddingStart="12dp"
|
||||||
android:textSize="12sp"
|
android:paddingTop="8dp"
|
||||||
app:layout_constraintBottom_toBottomOf="parent"
|
android:paddingEnd="12dp"
|
||||||
app:layout_constraintStart_toEndOf="@+id/imageView"
|
android:text="@string/label_placeholder"
|
||||||
app:layout_constraintTop_toBottomOf="@+id/search_result_song_title_text_view" />
|
android:textColor="@color/titleTextColor"
|
||||||
|
android:textSize="14sp"
|
||||||
|
android:textStyle="bold" />
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/search_result_song_artist_text_view"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="0dp"
|
||||||
|
android:layout_weight="1"
|
||||||
|
android:fontFamily="@font/open_sans_font_family"
|
||||||
|
android:paddingStart="12dp"
|
||||||
|
android:text="@string/label_placeholder"
|
||||||
|
android:textColor="@color/subtitleTextColor"
|
||||||
|
android:textSize="12sp" />
|
||||||
|
</LinearLayout>
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
android:id="@+id/search_result_song_duration_text_view"
|
android:id="@+id/search_result_song_duration_text_view"
|
||||||
|
|
@ -60,10 +64,11 @@
|
||||||
android:fontFamily="@font/open_sans_font_family"
|
android:fontFamily="@font/open_sans_font_family"
|
||||||
android:paddingStart="8dp"
|
android:paddingStart="8dp"
|
||||||
android:paddingEnd="8dp"
|
android:paddingEnd="8dp"
|
||||||
|
android:gravity="center_vertical"
|
||||||
android:text="@string/label_placeholder"
|
android:text="@string/label_placeholder"
|
||||||
android:textColor="@color/subtitleTextColor"
|
android:textColor="@color/subtitleTextColor"
|
||||||
android:textSize="12sp"
|
android:textSize="12sp"
|
||||||
app:layout_constraintBottom_toBottomOf="parent"
|
app:layout_constraintBottom_toBottomOf="parent"
|
||||||
app:layout_constraintEnd_toEndOf="parent"
|
app:layout_constraintEnd_toEndOf="parent"
|
||||||
app:layout_constraintTop_toTopOf="parent" />
|
app:layout_constraintTop_toTopOf="parent" />
|
||||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
</LinearLayout>
|
||||||
|
|
@ -83,11 +83,10 @@
|
||||||
app:destination="@id/genreCatalogueFragment" />
|
app:destination="@id/genreCatalogueFragment" />
|
||||||
<action
|
<action
|
||||||
android:id="@+id/action_libraryFragment_to_artistPageFragment"
|
android:id="@+id/action_libraryFragment_to_artistPageFragment"
|
||||||
app:destination="@id/artistPageFragment">
|
app:destination="@id/artistPageFragment"/>
|
||||||
<argument
|
<action
|
||||||
android:name="artistID"
|
android:id="@+id/action_libraryFragment_to_albumPageFragment"
|
||||||
app:argType="string"/>
|
app:destination="@id/albumPageFragment" />
|
||||||
</action>
|
|
||||||
</fragment>
|
</fragment>
|
||||||
<fragment
|
<fragment
|
||||||
android:id="@+id/settingsFragment"
|
android:id="@+id/settingsFragment"
|
||||||
|
|
@ -104,11 +103,10 @@
|
||||||
app:destination="@id/filterFragment" />
|
app:destination="@id/filterFragment" />
|
||||||
<action
|
<action
|
||||||
android:id="@+id/action_searchFragment_to_artistPageFragment"
|
android:id="@+id/action_searchFragment_to_artistPageFragment"
|
||||||
app:destination="@id/artistPageFragment">
|
app:destination="@id/artistPageFragment"/>
|
||||||
<argument
|
<action
|
||||||
android:name="artistID"
|
android:id="@+id/action_searchFragment_to_albumPageFragment"
|
||||||
app:argType="string"/>
|
app:destination="@id/albumPageFragment" />
|
||||||
</action>
|
|
||||||
</fragment>
|
</fragment>
|
||||||
<fragment
|
<fragment
|
||||||
android:id="@+id/filterFragment"
|
android:id="@+id/filterFragment"
|
||||||
|
|
@ -122,17 +120,17 @@
|
||||||
tools:layout="@layout/fragment_artist_catalogue">
|
tools:layout="@layout/fragment_artist_catalogue">
|
||||||
<action
|
<action
|
||||||
android:id="@+id/action_artistCatalogueFragment_to_artistPageFragment"
|
android:id="@+id/action_artistCatalogueFragment_to_artistPageFragment"
|
||||||
app:destination="@id/artistPageFragment">
|
app:destination="@id/artistPageFragment"/>
|
||||||
<argument
|
|
||||||
android:name="artistID"
|
|
||||||
app:argType="string"/>
|
|
||||||
</action>
|
|
||||||
</fragment>
|
</fragment>
|
||||||
<fragment
|
<fragment
|
||||||
android:id="@+id/albumCatalogueFragment"
|
android:id="@+id/albumCatalogueFragment"
|
||||||
android:name="com.cappielloantonio.play.ui.fragment.AlbumCatalogueFragment"
|
android:name="com.cappielloantonio.play.ui.fragment.AlbumCatalogueFragment"
|
||||||
android:label="AlbumCatalogueFragment"
|
android:label="AlbumCatalogueFragment"
|
||||||
tools:layout="@layout/fragment_album_catalogue"/>
|
tools:layout="@layout/fragment_album_catalogue">
|
||||||
|
<action
|
||||||
|
android:id="@+id/action_albumCatalogueFragment_to_albumPageFragment"
|
||||||
|
app:destination="@id/albumPageFragment" />
|
||||||
|
</fragment>
|
||||||
<fragment
|
<fragment
|
||||||
android:id="@+id/genreCatalogueFragment"
|
android:id="@+id/genreCatalogueFragment"
|
||||||
android:name="com.cappielloantonio.play.ui.fragment.GenreCatalogueFragment"
|
android:name="com.cappielloantonio.play.ui.fragment.GenreCatalogueFragment"
|
||||||
|
|
@ -143,5 +141,14 @@
|
||||||
android:id="@+id/artistPageFragment"
|
android:id="@+id/artistPageFragment"
|
||||||
android:name="com.cappielloantonio.play.ui.fragment.ArtistPageFragment"
|
android:name="com.cappielloantonio.play.ui.fragment.ArtistPageFragment"
|
||||||
android:label="ArtistPageFragment"
|
android:label="ArtistPageFragment"
|
||||||
tools:layout="@layout/fragment_artist_page"/>
|
tools:layout="@layout/fragment_artist_page">
|
||||||
|
<action
|
||||||
|
android:id="@+id/action_artistPageFragment_to_albumPageFragment"
|
||||||
|
app:destination="@id/albumPageFragment" />
|
||||||
|
</fragment>
|
||||||
|
<fragment
|
||||||
|
android:id="@+id/albumPageFragment"
|
||||||
|
android:name="com.cappielloantonio.play.ui.fragment.AlbumPageFragment"
|
||||||
|
android:label="AlbumPageFragment"
|
||||||
|
tools:layout="@layout/fragment_album_page"/>
|
||||||
</navigation>
|
</navigation>
|
||||||
Loading…
Add table
Add a link
Reference in a new issue