Adapters refactoring

This commit is contained in:
Antonio Cappiello 2020-11-28 14:50:15 +01:00
parent 18fae806a6
commit ae23d268cd
34 changed files with 341 additions and 100 deletions

View file

@ -16,8 +16,6 @@ import com.cappielloantonio.play.helper.recyclerview.ItemDecoration;
import com.cappielloantonio.play.ui.activities.MainActivity;
import com.cappielloantonio.play.viewmodel.AlbumCatalogueViewModel;
import java.util.ArrayList;
public class AlbumCatalogueFragment extends Fragment {
private static final String TAG = "ArtistCatalogueFragment";
@ -51,7 +49,7 @@ public class AlbumCatalogueFragment extends Fragment {
bind.albumCatalogueRecyclerView.addItemDecoration(new ItemDecoration(2, 20, false));
bind.albumCatalogueRecyclerView.setHasFixedSize(true);
albumAdapter = new AlbumCatalogueAdapter(requireContext(), new ArrayList<>());
albumAdapter = new AlbumCatalogueAdapter(requireContext());
albumAdapter.setClickListener((view, position) -> {
Bundle bundle = new Bundle();
bundle.putParcelable("album_object", albumAdapter.getItem(position));

View file

@ -16,8 +16,6 @@ import com.cappielloantonio.play.helper.recyclerview.ItemDecoration;
import com.cappielloantonio.play.ui.activities.MainActivity;
import com.cappielloantonio.play.viewmodel.ArtistCatalogueViewModel;
import java.util.ArrayList;
public class ArtistCatalogueFragment extends Fragment {
private static final String TAG = "ArtistCatalogueFragment";
@ -51,7 +49,7 @@ public class ArtistCatalogueFragment extends Fragment {
bind.artistCatalogueRecyclerView.addItemDecoration(new ItemDecoration(2, 20, false));
bind.artistCatalogueRecyclerView.setHasFixedSize(true);
artistAdapter = new ArtistCatalogueAdapter(requireContext(), new ArrayList<>());
artistAdapter = new ArtistCatalogueAdapter(requireContext());
artistAdapter.setClickListener((view, position) -> {
Bundle bundle = new Bundle();
bundle.putParcelable("artist_object", artistAdapter.getItem(position));

View file

@ -83,7 +83,7 @@ public class ArtistPageFragment extends Fragment {
bind.albumsRecyclerView.setLayoutManager(new LinearLayoutManager(requireContext(), LinearLayoutManager.HORIZONTAL, false));
bind.albumsRecyclerView.setHasFixedSize(true);
albumArtistPageAdapter = new AlbumArtistPageAdapter(requireContext(), new ArrayList<>());
albumArtistPageAdapter = new AlbumArtistPageAdapter(requireContext());
albumArtistPageAdapter.setClickListener((view, position) -> {
Bundle bundle = new Bundle();
bundle.putParcelable("album_object", albumArtistPageAdapter.getItem(position));

View file

@ -17,8 +17,6 @@ import com.cappielloantonio.play.model.Song;
import com.cappielloantonio.play.ui.activities.MainActivity;
import com.cappielloantonio.play.viewmodel.GenreCatalogueViewModel;
import java.util.ArrayList;
public class GenreCatalogueFragment extends Fragment {
private static final String TAG = "GenreCatalogueFragment";;
@ -57,7 +55,7 @@ public class GenreCatalogueFragment extends Fragment {
bind.genreCatalogueRecyclerView.addItemDecoration(new ItemDecoration(2, 16, false));
bind.genreCatalogueRecyclerView.setHasFixedSize(true);
genreCatalogueAdapter = new GenreCatalogueAdapter(requireContext(), new ArrayList<>());
genreCatalogueAdapter = new GenreCatalogueAdapter(requireContext());
genreCatalogueAdapter.setClickListener((view, position) -> {
Bundle bundle = new Bundle();
bundle.putString(Song.BY_GENRE, Song.BY_GENRE);

View file

@ -16,14 +16,13 @@ import androidx.viewpager2.widget.ViewPager2;
import com.cappielloantonio.play.R;
import com.cappielloantonio.play.adapter.DiscoverSongAdapter;
import com.cappielloantonio.play.adapter.RecentMusicAdapter;
import com.cappielloantonio.play.adapter.YearAdapter;
import com.cappielloantonio.play.databinding.FragmentHomeBinding;
import com.cappielloantonio.play.model.Song;
import com.cappielloantonio.play.ui.activities.MainActivity;
import com.cappielloantonio.play.util.PreferenceUtil;
import com.cappielloantonio.play.viewmodel.HomeViewModel;
import java.util.ArrayList;
public class HomeFragment extends Fragment {
private static final String TAG = "CategoriesFragment";
@ -33,6 +32,7 @@ public class HomeFragment extends Fragment {
private DiscoverSongAdapter discoverSongAdapter;
private RecentMusicAdapter recentlyAddedMusicAdapter;
private YearAdapter yearAdapter;
private RecentMusicAdapter recentlyPlayedMusicAdapter;
private RecentMusicAdapter mostPlayedMusicAdapter;
@ -48,6 +48,7 @@ public class HomeFragment extends Fragment {
init();
initDiscoverSongSlideView();
initRecentAddedSongView();
initYearSongView();
initRecentPlayedSongView();
initMostPlayedSongView();
@ -99,16 +100,30 @@ public class HomeFragment extends Fragment {
bind.recentlyAddedTracksRecyclerView.setLayoutManager(new LinearLayoutManager(requireContext(), LinearLayoutManager.HORIZONTAL, false));
bind.recentlyAddedTracksRecyclerView.setHasFixedSize(true);
recentlyAddedMusicAdapter = new RecentMusicAdapter(requireContext(), new ArrayList<>());
recentlyAddedMusicAdapter = new RecentMusicAdapter(requireContext());
bind.recentlyAddedTracksRecyclerView.setAdapter(recentlyAddedMusicAdapter);
homeViewModel.getRecentlyAddedSongList().observe(requireActivity(), songs -> recentlyAddedMusicAdapter.setItems(songs));
}
private void initYearSongView() {
bind.yearsRecyclerView.setLayoutManager(new LinearLayoutManager(requireContext(), LinearLayoutManager.HORIZONTAL, false));
bind.yearsRecyclerView.setHasFixedSize(true);
yearAdapter = new YearAdapter(requireContext(), homeViewModel.getYearList());
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);
}
private void initRecentPlayedSongView() {
bind.recentlyPlayedTracksRecyclerView.setLayoutManager(new LinearLayoutManager(requireContext(), LinearLayoutManager.HORIZONTAL, false));
bind.recentlyPlayedTracksRecyclerView.setHasFixedSize(true);
recentlyPlayedMusicAdapter = new RecentMusicAdapter(requireContext(), new ArrayList<>());
recentlyPlayedMusicAdapter = new RecentMusicAdapter(requireContext());
bind.recentlyPlayedTracksRecyclerView.setAdapter(recentlyPlayedMusicAdapter);
homeViewModel.getRecentlyPlayedSongList().observe(requireActivity(), songs -> recentlyPlayedMusicAdapter.setItems(songs));
}
@ -117,7 +132,7 @@ public class HomeFragment extends Fragment {
bind.mostPlayedTracksRecyclerView.setLayoutManager(new LinearLayoutManager(requireContext(), LinearLayoutManager.HORIZONTAL, false));
bind.mostPlayedTracksRecyclerView.setHasFixedSize(true);
mostPlayedMusicAdapter = new RecentMusicAdapter(requireContext(), new ArrayList<>());
mostPlayedMusicAdapter = new RecentMusicAdapter(requireContext());
bind.mostPlayedTracksRecyclerView.setAdapter(mostPlayedMusicAdapter);
homeViewModel.getMostPlayedSongList().observe(requireActivity(), songs -> mostPlayedMusicAdapter.setItems(songs));
}

View file

@ -25,8 +25,6 @@ import com.cappielloantonio.play.ui.activities.MainActivity;
import com.cappielloantonio.play.util.PreferenceUtil;
import com.cappielloantonio.play.viewmodel.LibraryViewModel;
import java.util.ArrayList;
public class LibraryFragment extends Fragment {
private static final String TAG = "LibraryFragment";
@ -75,7 +73,7 @@ public class LibraryFragment extends Fragment {
bind.albumRecyclerView.setLayoutManager(new LinearLayoutManager(requireContext(), LinearLayoutManager.HORIZONTAL, false));
bind.albumRecyclerView.setHasFixedSize(true);
albumAdapter = new AlbumAdapter(requireContext(), new ArrayList<>());
albumAdapter = new AlbumAdapter(requireContext());
albumAdapter.setClickListener((view, position) -> {
Bundle bundle = new Bundle();
bundle.putParcelable("album_object", albumAdapter.getItem(position));
@ -89,7 +87,7 @@ public class LibraryFragment extends Fragment {
bind.artistRecyclerView.setLayoutManager(new LinearLayoutManager(requireContext(), LinearLayoutManager.HORIZONTAL, false));
bind.artistRecyclerView.setHasFixedSize(true);
artistAdapter = new ArtistAdapter(requireContext(), new ArrayList<>());
artistAdapter = new ArtistAdapter(requireContext());
artistAdapter.setClickListener((view, position) -> {
Bundle bundle = new Bundle();
bundle.putParcelable("artist_object", artistAdapter.getItem(position));
@ -103,7 +101,7 @@ public class LibraryFragment extends Fragment {
bind.genreRecyclerView.setLayoutManager(new GridLayoutManager(requireContext(), 3, GridLayoutManager.HORIZONTAL, false));
bind.genreRecyclerView.setHasFixedSize(true);
genreAdapter = new GenreAdapter(requireContext(), new ArrayList<>());
genreAdapter = new GenreAdapter(requireContext());
genreAdapter.setClickListener((view, position) -> {
Bundle bundle = new Bundle();
bundle.putString(Song.BY_GENRE, Song.BY_GENRE);
@ -118,7 +116,7 @@ public class LibraryFragment extends Fragment {
bind.playlistRecyclerView.setLayoutManager(new GridLayoutManager(requireContext(), 2));
bind.playlistRecyclerView.setHasFixedSize(true);
playlistAdapter = new PlaylistAdapter(requireContext(), new ArrayList<>());
playlistAdapter = new PlaylistAdapter(requireContext());
playlistAdapter.setClickListener((view, position) -> Toast.makeText(requireContext(), "Playlist: " + position, Toast.LENGTH_SHORT).show());
bind.playlistRecyclerView.setAdapter(playlistAdapter);
libraryViewModel.getPlaylistList().observe(requireActivity(), playlists -> playlistAdapter.setItems(playlists));

View file

@ -72,7 +72,7 @@ public class SearchFragment extends Fragment {
bind.recentlySearchedTracksRecyclerView.setLayoutManager(new LinearLayoutManager(requireContext()));
bind.recentlySearchedTracksRecyclerView.setHasFixedSize(true);
recentSearchAdapter = new RecentSearchAdapter(requireContext(), new ArrayList<>());
recentSearchAdapter = new RecentSearchAdapter(requireContext());
recentSearchAdapter.setClickListener((view, position) -> {
RecentSearch search = recentSearchAdapter.getItem(position);
search(search.getSearch());
@ -95,7 +95,7 @@ public class SearchFragment extends Fragment {
bind.searchResultAlbumRecyclerView.addItemDecoration(new ItemDecoration(2, 20, false));
bind.searchResultAlbumRecyclerView.setHasFixedSize(true);
albumResultSearchAdapter = new AlbumCatalogueAdapter(requireContext(), new ArrayList<>());
albumResultSearchAdapter = new AlbumCatalogueAdapter(requireContext());
albumResultSearchAdapter.setClickListener((view, position) -> {
Bundle bundle = new Bundle();
bundle.putParcelable("album_object", albumResultSearchAdapter.getItem(position));
@ -108,7 +108,7 @@ public class SearchFragment extends Fragment {
bind.searchResultArtistRecyclerView.addItemDecoration(new ItemDecoration(2, 20, false));
bind.searchResultArtistRecyclerView.setHasFixedSize(true);
artistResultSearchAdapter = new ArtistCatalogueAdapter(requireContext(), new ArrayList<>());
artistResultSearchAdapter = new ArtistCatalogueAdapter(requireContext());
artistResultSearchAdapter.setClickListener((view, position) -> {
Bundle bundle = new Bundle();
bundle.putParcelable("artist_object", artistResultSearchAdapter.getItem(position));

View file

@ -74,6 +74,11 @@ public class SongListPageFragment extends Fragment {
songListPageViewModel.filterNames = getArguments().getStringArrayList("filter_name_list");
bind.pageTitleLabel.setText(songListPageViewModel.getFiltersTitle());
}
else if(getArguments().getString(Song.BY_YEAR) != null) {
songListPageViewModel.title = Song.BY_YEAR;
songListPageViewModel.year = getArguments().getInt("year_object");
bind.pageTitleLabel.setText("Year " + songListPageViewModel.year);
}
}
private void initSongListView() {