mirror of
https://github.com/antebudimir/tempus.git
synced 2025-12-31 17:43:32 +00:00
Change search result order
This commit is contained in:
parent
45361c4851
commit
05548af5c6
2 changed files with 33 additions and 31 deletions
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -49,9 +49,9 @@
|
|||
android:orientation="vertical"
|
||||
android:paddingBottom="@dimen/global_padding_bottom">
|
||||
|
||||
<!-- Songs -->
|
||||
<!-- Artist -->
|
||||
<LinearLayout
|
||||
android:id="@+id/search_song_sector"
|
||||
android:id="@+id/search_artist_sector"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="vertical"
|
||||
|
|
@ -65,16 +65,18 @@
|
|||
android:paddingStart="16dp"
|
||||
android:paddingTop="20dp"
|
||||
android:paddingEnd="16dp"
|
||||
android:text="@string/search_title_song" />
|
||||
android:text="@string/search_title_artist" />
|
||||
|
||||
<androidx.recyclerview.widget.RecyclerView
|
||||
android:id="@+id/search_result_tracks_recycler_view"
|
||||
android:id="@+id/search_result_artist_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="8dp" />
|
||||
</LinearLayout>
|
||||
|
||||
|
|
@ -109,9 +111,9 @@
|
|||
android:paddingBottom="8dp" />
|
||||
</LinearLayout>
|
||||
|
||||
<!-- Artist -->
|
||||
<!-- Songs -->
|
||||
<LinearLayout
|
||||
android:id="@+id/search_artist_sector"
|
||||
android:id="@+id/search_song_sector"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="vertical"
|
||||
|
|
@ -125,18 +127,16 @@
|
|||
android:paddingStart="16dp"
|
||||
android:paddingTop="20dp"
|
||||
android:paddingEnd="16dp"
|
||||
android:text="@string/search_title_artist" />
|
||||
android:text="@string/search_title_song" />
|
||||
|
||||
<androidx.recyclerview.widget.RecyclerView
|
||||
android:id="@+id/search_result_artist_recycler_view"
|
||||
android:id="@+id/search_result_tracks_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="8dp" />
|
||||
</LinearLayout>
|
||||
</LinearLayout>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue