mirror of
https://github.com/antebudimir/tempus.git
synced 2026-01-01 09:53:33 +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.model.Album;
|
||||
import com.cappielloantonio.play.model.Artist;
|
||||
import com.cappielloantonio.play.util.Util;
|
||||
|
||||
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) {
|
||||
this.albums = albums;
|
||||
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) {
|
||||
this.albums = albums;
|
||||
notifyDataSetChanged();
|
||||
|
|
|
|||
|
|
@ -10,6 +10,7 @@ import androidx.recyclerview.widget.RecyclerView;
|
|||
|
||||
import com.cappielloantonio.play.R;
|
||||
import com.cappielloantonio.play.model.Album;
|
||||
import com.cappielloantonio.play.model.Artist;
|
||||
|
||||
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) {
|
||||
this.albums = albums;
|
||||
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) {
|
||||
this.artists = artists;
|
||||
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")
|
||||
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)")
|
||||
boolean exist(String id);
|
||||
|
||||
|
|
|
|||
|
|
@ -19,6 +19,7 @@ public class SongRepository {
|
|||
private LiveData<List<Song>> listLiveSampleRecentlyPlayedSongs;
|
||||
private LiveData<List<Song>> listLiveSampleMostPlayedSongs;
|
||||
private LiveData<List<Song>> listLiveSampleArtistTopSongs;
|
||||
private LiveData<List<Song>> listLiveAlbumSongs;
|
||||
|
||||
|
||||
public SongRepository(Application application) {
|
||||
|
|
@ -51,6 +52,11 @@ public class SongRepository {
|
|||
return listLiveSampleArtistTopSongs;
|
||||
}
|
||||
|
||||
public LiveData<List<Song>> getAlbumListLiveSong(String albumID) {
|
||||
listLiveAlbumSongs = songDao.getAlbumSong(albumID);
|
||||
return listLiveAlbumSongs;
|
||||
}
|
||||
|
||||
public boolean exist(Song song) {
|
||||
boolean exist = false;
|
||||
|
||||
|
|
|
|||
|
|
@ -10,9 +10,11 @@ import androidx.fragment.app.Fragment;
|
|||
import androidx.lifecycle.ViewModelProvider;
|
||||
import androidx.recyclerview.widget.GridLayoutManager;
|
||||
|
||||
import com.cappielloantonio.play.R;
|
||||
import com.cappielloantonio.play.adapter.AlbumCatalogueAdapter;
|
||||
import com.cappielloantonio.play.databinding.FragmentAlbumCatalogueBinding;
|
||||
import com.cappielloantonio.play.helper.recyclerview.ItemlDecoration;
|
||||
import com.cappielloantonio.play.ui.activities.MainActivity;
|
||||
import com.cappielloantonio.play.viewmodel.AlbumCatalogueViewModel;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
|
@ -21,12 +23,15 @@ public class AlbumCatalogueFragment extends Fragment {
|
|||
private static final String TAG = "ArtistCatalogueFragment";
|
||||
|
||||
private FragmentAlbumCatalogueBinding bind;
|
||||
private MainActivity activity;
|
||||
private AlbumCatalogueViewModel albumCatalogueViewModel;
|
||||
|
||||
private AlbumCatalogueAdapter albumAdapter;
|
||||
|
||||
@Override
|
||||
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
||||
activity = (MainActivity) getActivity();
|
||||
|
||||
bind = FragmentAlbumCatalogueBinding.inflate(inflater, container, false);
|
||||
View view = bind.getRoot();
|
||||
albumCatalogueViewModel = new ViewModelProvider(requireActivity()).get(AlbumCatalogueViewModel.class);
|
||||
|
|
@ -48,7 +53,11 @@ public class AlbumCatalogueFragment extends Fragment {
|
|||
bind.albumCatalogueRecyclerView.setHasFixedSize(true);
|
||||
|
||||
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);
|
||||
albumCatalogueViewModel.getAlbumList().observe(requireActivity(), albums -> {
|
||||
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 FragmentArtistCatalogueBinding bind;
|
||||
private MainActivity activity;
|
||||
private ArtistCatalogueViewModel artistCatalogueViewModel;
|
||||
|
||||
private ArtistCatalogueAdapter artistAdapter;
|
||||
|
||||
@Override
|
||||
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
||||
activity = (MainActivity) getActivity();
|
||||
|
||||
bind = FragmentArtistCatalogueBinding.inflate(inflater, container, false);
|
||||
View view = bind.getRoot();
|
||||
artistCatalogueViewModel = new ViewModelProvider(requireActivity()).get(ArtistCatalogueViewModel.class);
|
||||
|
|
@ -56,7 +59,11 @@ public class ArtistCatalogueFragment extends Fragment {
|
|||
bind.artistCatalogueRecyclerView.setHasFixedSize(true);
|
||||
|
||||
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);
|
||||
artistCatalogueViewModel.getArtistList().observe(requireActivity(), artists -> {
|
||||
bind.loadingProgressBar.setVisibility(View.GONE);
|
||||
|
|
|
|||
|
|
@ -31,8 +31,6 @@ public class ArtistPageFragment extends Fragment {
|
|||
private SongResultSearchAdapter songResultSearchAdapter;
|
||||
private AlbumArtistPageAdapter albumArtistPageAdapter;
|
||||
|
||||
private String artistID;
|
||||
|
||||
@Override
|
||||
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
||||
activity = (MainActivity) getActivity();
|
||||
|
|
@ -55,7 +53,9 @@ public class ArtistPageFragment extends Fragment {
|
|||
}
|
||||
|
||||
private void init() {
|
||||
artistID = getArguments().getString("artistID");
|
||||
artistPageViewModel.setArtist(getArguments().getParcelable("artist_object"));
|
||||
|
||||
bind.artistNameLabel.setText(artistPageViewModel.getArtist().getName());
|
||||
}
|
||||
|
||||
private void initTopSongsView() {
|
||||
|
|
@ -64,7 +64,7 @@ public class ArtistPageFragment extends Fragment {
|
|||
|
||||
songResultSearchAdapter = new SongResultSearchAdapter(requireContext(), new ArrayList<>());
|
||||
bind.mostStreamedSongRecyclerView.setAdapter(songResultSearchAdapter);
|
||||
artistPageViewModel.getArtistTopSongList(artistID).observe(requireActivity(), songs -> songResultSearchAdapter.setItems(songs));
|
||||
artistPageViewModel.getArtistTopSongList().observe(requireActivity(), songs -> songResultSearchAdapter.setItems(songs));
|
||||
}
|
||||
|
||||
private void initAlbumsView() {
|
||||
|
|
@ -72,7 +72,12 @@ public class ArtistPageFragment extends Fragment {
|
|||
bind.albumsRecyclerView.setHasFixedSize(true);
|
||||
|
||||
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);
|
||||
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);
|
||||
|
||||
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);
|
||||
libraryViewModel.getAlbumSample().observe(requireActivity(), albums -> albumAdapter.setItems(albums));
|
||||
}
|
||||
|
|
@ -88,7 +92,11 @@ public class LibraryFragment extends Fragment {
|
|||
bind.artistRecyclerView.setHasFixedSize(true);
|
||||
|
||||
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);
|
||||
libraryViewModel.getArtistSample().observe(requireActivity(), artists -> artistAdapter.setItems(artists));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -99,7 +99,9 @@ public class SearchFragment extends Fragment {
|
|||
|
||||
albumResultSearchAdapter = new AlbumCatalogueAdapter(requireContext(), new ArrayList<>());
|
||||
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);
|
||||
|
||||
|
|
@ -110,9 +112,8 @@ public class SearchFragment extends Fragment {
|
|||
|
||||
artistResultSearchAdapter = new ArtistCatalogueAdapter(requireContext(), new ArrayList<>());
|
||||
artistResultSearchAdapter.setClickListener((view, position) -> {
|
||||
Toast.makeText(requireContext(), "Artist " + position, Toast.LENGTH_SHORT).show();
|
||||
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);
|
||||
});
|
||||
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 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;
|
||||
|
|
@ -20,6 +21,8 @@ public class ArtistPageViewModel extends AndroidViewModel {
|
|||
private LiveData<List<Song>> songList;
|
||||
private LiveData<List<Album>> albumList;
|
||||
|
||||
private Artist artist;
|
||||
|
||||
public ArtistPageViewModel(@NonNull Application application) {
|
||||
super(application);
|
||||
|
||||
|
|
@ -27,13 +30,21 @@ public class ArtistPageViewModel extends AndroidViewModel {
|
|||
albumRepository = new AlbumRepository(application);
|
||||
}
|
||||
|
||||
public LiveData<List<Album>> getAlbumList(String artistID) {
|
||||
albumList = albumRepository.getArtistListLiveAlbums(artistID);
|
||||
public LiveData<List<Album>> getAlbumList() {
|
||||
albumList = albumRepository.getArtistListLiveAlbums(artist.id);
|
||||
return albumList;
|
||||
}
|
||||
|
||||
public LiveData<List<Song>> getArtistTopSongList(String artistID) {
|
||||
songList = songRepository.getArtistListLiveTopSong(artistID);
|
||||
public LiveData<List<Song>> getArtistTopSongList() {
|
||||
songList = songRepository.getArtistListLiveTopSong(artist.id);
|
||||
return songList;
|
||||
}
|
||||
|
||||
public Artist getArtist() {
|
||||
return artist;
|
||||
}
|
||||
|
||||
public void setArtist(Artist artist) {
|
||||
this.artist = artist;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue