mirror of
https://github.com/antebudimir/tempus.git
synced 2026-01-02 18:31:40 +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 MainActivity activity;
|
||||||
private SearchViewModel searchViewModel;
|
private SearchViewModel searchViewModel;
|
||||||
|
|
||||||
private SongHorizontalAdapter songHorizontalAdapter;
|
|
||||||
private AlbumAdapter albumAdapter;
|
|
||||||
private ArtistAdapter artistAdapter;
|
private ArtistAdapter artistAdapter;
|
||||||
|
private AlbumAdapter albumAdapter;
|
||||||
|
private SongHorizontalAdapter songHorizontalAdapter;
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
@Override
|
@Override
|
||||||
|
|
@ -70,12 +70,15 @@ public class SearchFragment extends Fragment {
|
||||||
}
|
}
|
||||||
|
|
||||||
private void initSearchResultView() {
|
private void initSearchResultView() {
|
||||||
// Songs
|
// Artists
|
||||||
bind.searchResultTracksRecyclerView.setLayoutManager(new LinearLayoutManager(requireContext()));
|
bind.searchResultArtistRecyclerView.setLayoutManager(new LinearLayoutManager(requireContext(), LinearLayoutManager.HORIZONTAL, false));
|
||||||
bind.searchResultTracksRecyclerView.setHasFixedSize(true);
|
bind.searchResultArtistRecyclerView.setHasFixedSize(true);
|
||||||
|
|
||||||
songHorizontalAdapter = new SongHorizontalAdapter(activity, requireContext(), true);
|
artistAdapter = new ArtistAdapter(requireContext());
|
||||||
bind.searchResultTracksRecyclerView.setAdapter(songHorizontalAdapter);
|
bind.searchResultArtistRecyclerView.setAdapter(artistAdapter);
|
||||||
|
|
||||||
|
CustomLinearSnapHelper artistSnapHelper = new CustomLinearSnapHelper();
|
||||||
|
artistSnapHelper.attachToRecyclerView(bind.searchResultArtistRecyclerView);
|
||||||
|
|
||||||
// Albums
|
// Albums
|
||||||
bind.searchResultAlbumRecyclerView.setLayoutManager(new LinearLayoutManager(requireContext(), LinearLayoutManager.HORIZONTAL, false));
|
bind.searchResultAlbumRecyclerView.setLayoutManager(new LinearLayoutManager(requireContext(), LinearLayoutManager.HORIZONTAL, false));
|
||||||
|
|
@ -87,15 +90,12 @@ public class SearchFragment extends Fragment {
|
||||||
CustomLinearSnapHelper albumSnapHelper = new CustomLinearSnapHelper();
|
CustomLinearSnapHelper albumSnapHelper = new CustomLinearSnapHelper();
|
||||||
albumSnapHelper.attachToRecyclerView(bind.searchResultAlbumRecyclerView);
|
albumSnapHelper.attachToRecyclerView(bind.searchResultAlbumRecyclerView);
|
||||||
|
|
||||||
// Artists
|
// Songs
|
||||||
bind.searchResultArtistRecyclerView.setLayoutManager(new LinearLayoutManager(requireContext(), LinearLayoutManager.HORIZONTAL, false));
|
bind.searchResultTracksRecyclerView.setLayoutManager(new LinearLayoutManager(requireContext()));
|
||||||
bind.searchResultArtistRecyclerView.setHasFixedSize(true);
|
bind.searchResultTracksRecyclerView.setHasFixedSize(true);
|
||||||
|
|
||||||
artistAdapter = new ArtistAdapter(requireContext());
|
songHorizontalAdapter = new SongHorizontalAdapter(activity, requireContext(), true);
|
||||||
bind.searchResultArtistRecyclerView.setAdapter(artistAdapter);
|
bind.searchResultTracksRecyclerView.setAdapter(songHorizontalAdapter);
|
||||||
|
|
||||||
CustomLinearSnapHelper artistSnapHelper = new CustomLinearSnapHelper();
|
|
||||||
artistSnapHelper.attachToRecyclerView(bind.searchResultArtistRecyclerView);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void initSearchView() {
|
private void initSearchView() {
|
||||||
|
|
@ -161,20 +161,22 @@ public class SearchFragment extends Fragment {
|
||||||
}
|
}
|
||||||
|
|
||||||
private void performSearch(String query) {
|
private void performSearch(String query) {
|
||||||
searchViewModel.searchSong(query).observe(requireActivity(), songs -> {
|
searchViewModel.searchArtist(query).observe(requireActivity(), artists -> {
|
||||||
if (bind != null)
|
if (bind != null)
|
||||||
bind.searchSongSector.setVisibility(!songs.isEmpty() ? View.VISIBLE : View.GONE);
|
bind.searchArtistSector.setVisibility(!artists.isEmpty() ? View.VISIBLE : View.GONE);
|
||||||
songHorizontalAdapter.setItems(songs);
|
artistAdapter.setItems(artists);
|
||||||
});
|
});
|
||||||
|
|
||||||
searchViewModel.searchAlbum(query).observe(requireActivity(), albums -> {
|
searchViewModel.searchAlbum(query).observe(requireActivity(), albums -> {
|
||||||
if (bind != null)
|
if (bind != null)
|
||||||
bind.searchAlbumSector.setVisibility(!albums.isEmpty() ? View.VISIBLE : View.GONE);
|
bind.searchAlbumSector.setVisibility(!albums.isEmpty() ? View.VISIBLE : View.GONE);
|
||||||
albumAdapter.setItems(albums);
|
albumAdapter.setItems(albums);
|
||||||
});
|
});
|
||||||
searchViewModel.searchArtist(query).observe(requireActivity(), artists -> {
|
|
||||||
|
searchViewModel.searchSong(query).observe(requireActivity(), songs -> {
|
||||||
if (bind != null)
|
if (bind != null)
|
||||||
bind.searchArtistSector.setVisibility(!artists.isEmpty() ? View.VISIBLE : View.GONE);
|
bind.searchSongSector.setVisibility(!songs.isEmpty() ? View.VISIBLE : View.GONE);
|
||||||
artistAdapter.setItems(artists);
|
songHorizontalAdapter.setItems(songs);
|
||||||
});
|
});
|
||||||
|
|
||||||
bind.searchResultLayout.setVisibility(View.VISIBLE);
|
bind.searchResultLayout.setVisibility(View.VISIBLE);
|
||||||
|
|
|
||||||
|
|
@ -49,9 +49,9 @@
|
||||||
android:orientation="vertical"
|
android:orientation="vertical"
|
||||||
android:paddingBottom="@dimen/global_padding_bottom">
|
android:paddingBottom="@dimen/global_padding_bottom">
|
||||||
|
|
||||||
<!-- Songs -->
|
<!-- Artist -->
|
||||||
<LinearLayout
|
<LinearLayout
|
||||||
android:id="@+id/search_song_sector"
|
android:id="@+id/search_artist_sector"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:orientation="vertical"
|
android:orientation="vertical"
|
||||||
|
|
@ -65,16 +65,18 @@
|
||||||
android:paddingStart="16dp"
|
android:paddingStart="16dp"
|
||||||
android:paddingTop="20dp"
|
android:paddingTop="20dp"
|
||||||
android:paddingEnd="16dp"
|
android:paddingEnd="16dp"
|
||||||
android:text="@string/search_title_song" />
|
android:text="@string/search_title_artist" />
|
||||||
|
|
||||||
<androidx.recyclerview.widget.RecyclerView
|
<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_width="match_parent"
|
||||||
android:layout_height="match_parent"
|
android:layout_height="match_parent"
|
||||||
android:layout_marginTop="8dp"
|
android:layout_marginTop="8dp"
|
||||||
android:layout_marginBottom="8dp"
|
android:layout_marginBottom="8dp"
|
||||||
android:clipToPadding="false"
|
android:clipToPadding="false"
|
||||||
|
android:paddingStart="16dp"
|
||||||
android:paddingTop="8dp"
|
android:paddingTop="8dp"
|
||||||
|
android:paddingEnd="8dp"
|
||||||
android:paddingBottom="8dp" />
|
android:paddingBottom="8dp" />
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
|
|
||||||
|
|
@ -109,9 +111,9 @@
|
||||||
android:paddingBottom="8dp" />
|
android:paddingBottom="8dp" />
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
|
|
||||||
<!-- Artist -->
|
<!-- Songs -->
|
||||||
<LinearLayout
|
<LinearLayout
|
||||||
android:id="@+id/search_artist_sector"
|
android:id="@+id/search_song_sector"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:orientation="vertical"
|
android:orientation="vertical"
|
||||||
|
|
@ -125,18 +127,16 @@
|
||||||
android:paddingStart="16dp"
|
android:paddingStart="16dp"
|
||||||
android:paddingTop="20dp"
|
android:paddingTop="20dp"
|
||||||
android:paddingEnd="16dp"
|
android:paddingEnd="16dp"
|
||||||
android:text="@string/search_title_artist" />
|
android:text="@string/search_title_song" />
|
||||||
|
|
||||||
<androidx.recyclerview.widget.RecyclerView
|
<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_width="match_parent"
|
||||||
android:layout_height="match_parent"
|
android:layout_height="match_parent"
|
||||||
android:layout_marginTop="8dp"
|
android:layout_marginTop="8dp"
|
||||||
android:layout_marginBottom="8dp"
|
android:layout_marginBottom="8dp"
|
||||||
android:clipToPadding="false"
|
android:clipToPadding="false"
|
||||||
android:paddingStart="16dp"
|
|
||||||
android:paddingTop="8dp"
|
android:paddingTop="8dp"
|
||||||
android:paddingEnd="8dp"
|
|
||||||
android:paddingBottom="8dp" />
|
android:paddingBottom="8dp" />
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue