From 05548af5c6f7ca363482734c7ab7ce6d6e6c223c Mon Sep 17 00:00:00 2001 From: CappielloAntonio Date: Mon, 13 Sep 2021 17:24:24 +0200 Subject: [PATCH] Change search result order --- .../play/ui/fragment/SearchFragment.java | 44 ++++++++++--------- app/src/main/res/layout/fragment_search.xml | 20 ++++----- 2 files changed, 33 insertions(+), 31 deletions(-) diff --git a/app/src/main/java/com/cappielloantonio/play/ui/fragment/SearchFragment.java b/app/src/main/java/com/cappielloantonio/play/ui/fragment/SearchFragment.java index 2c5ea3a4..e0f334fa 100644 --- a/app/src/main/java/com/cappielloantonio/play/ui/fragment/SearchFragment.java +++ b/app/src/main/java/com/cappielloantonio/play/ui/fragment/SearchFragment.java @@ -32,9 +32,9 @@ public class SearchFragment extends Fragment { private MainActivity activity; private SearchViewModel searchViewModel; - private SongHorizontalAdapter songHorizontalAdapter; - private AlbumAdapter albumAdapter; private ArtistAdapter artistAdapter; + private AlbumAdapter albumAdapter; + private SongHorizontalAdapter songHorizontalAdapter; @Nullable @Override @@ -70,12 +70,15 @@ public class SearchFragment extends Fragment { } private void initSearchResultView() { - // Songs - bind.searchResultTracksRecyclerView.setLayoutManager(new LinearLayoutManager(requireContext())); - bind.searchResultTracksRecyclerView.setHasFixedSize(true); + // Artists + bind.searchResultArtistRecyclerView.setLayoutManager(new LinearLayoutManager(requireContext(), LinearLayoutManager.HORIZONTAL, false)); + bind.searchResultArtistRecyclerView.setHasFixedSize(true); - songHorizontalAdapter = new SongHorizontalAdapter(activity, requireContext(), true); - bind.searchResultTracksRecyclerView.setAdapter(songHorizontalAdapter); + artistAdapter = new ArtistAdapter(requireContext()); + bind.searchResultArtistRecyclerView.setAdapter(artistAdapter); + + CustomLinearSnapHelper artistSnapHelper = new CustomLinearSnapHelper(); + artistSnapHelper.attachToRecyclerView(bind.searchResultArtistRecyclerView); // Albums bind.searchResultAlbumRecyclerView.setLayoutManager(new LinearLayoutManager(requireContext(), LinearLayoutManager.HORIZONTAL, false)); @@ -87,15 +90,12 @@ public class SearchFragment extends Fragment { CustomLinearSnapHelper albumSnapHelper = new CustomLinearSnapHelper(); albumSnapHelper.attachToRecyclerView(bind.searchResultAlbumRecyclerView); - // Artists - bind.searchResultArtistRecyclerView.setLayoutManager(new LinearLayoutManager(requireContext(), LinearLayoutManager.HORIZONTAL, false)); - bind.searchResultArtistRecyclerView.setHasFixedSize(true); + // Songs + bind.searchResultTracksRecyclerView.setLayoutManager(new LinearLayoutManager(requireContext())); + bind.searchResultTracksRecyclerView.setHasFixedSize(true); - artistAdapter = new ArtistAdapter(requireContext()); - bind.searchResultArtistRecyclerView.setAdapter(artistAdapter); - - CustomLinearSnapHelper artistSnapHelper = new CustomLinearSnapHelper(); - artistSnapHelper.attachToRecyclerView(bind.searchResultArtistRecyclerView); + songHorizontalAdapter = new SongHorizontalAdapter(activity, requireContext(), true); + bind.searchResultTracksRecyclerView.setAdapter(songHorizontalAdapter); } private void initSearchView() { @@ -161,20 +161,22 @@ public class SearchFragment extends Fragment { } private void performSearch(String query) { - searchViewModel.searchSong(query).observe(requireActivity(), songs -> { + searchViewModel.searchArtist(query).observe(requireActivity(), artists -> { if (bind != null) - bind.searchSongSector.setVisibility(!songs.isEmpty() ? View.VISIBLE : View.GONE); - songHorizontalAdapter.setItems(songs); + bind.searchArtistSector.setVisibility(!artists.isEmpty() ? View.VISIBLE : View.GONE); + artistAdapter.setItems(artists); }); + searchViewModel.searchAlbum(query).observe(requireActivity(), albums -> { if (bind != null) bind.searchAlbumSector.setVisibility(!albums.isEmpty() ? View.VISIBLE : View.GONE); albumAdapter.setItems(albums); }); - searchViewModel.searchArtist(query).observe(requireActivity(), artists -> { + + searchViewModel.searchSong(query).observe(requireActivity(), songs -> { if (bind != null) - bind.searchArtistSector.setVisibility(!artists.isEmpty() ? View.VISIBLE : View.GONE); - artistAdapter.setItems(artists); + bind.searchSongSector.setVisibility(!songs.isEmpty() ? View.VISIBLE : View.GONE); + songHorizontalAdapter.setItems(songs); }); bind.searchResultLayout.setVisibility(View.VISIBLE); diff --git a/app/src/main/res/layout/fragment_search.xml b/app/src/main/res/layout/fragment_search.xml index 48d99580..04f8d506 100644 --- a/app/src/main/res/layout/fragment_search.xml +++ b/app/src/main/res/layout/fragment_search.xml @@ -49,9 +49,9 @@ android:orientation="vertical" android:paddingBottom="@dimen/global_padding_bottom"> - + + android:text="@string/search_title_artist" /> @@ -109,9 +111,9 @@ android:paddingBottom="8dp" /> - + + android:text="@string/search_title_song" />