Return back to a limited number of top song in Artist page

This commit is contained in:
CappielloAntonio 2021-08-02 10:39:41 +02:00
parent 59e0de7836
commit cd7e3bf84f
3 changed files with 8 additions and 12 deletions

View file

@ -14,9 +14,7 @@ import androidx.annotation.Nullable;
import androidx.core.view.ViewCompat;
import androidx.fragment.app.Fragment;
import androidx.lifecycle.ViewModelProvider;
import androidx.recyclerview.widget.GridLayoutManager;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.PagerSnapHelper;
import com.cappielloantonio.play.App;
import com.cappielloantonio.play.R;
@ -31,7 +29,6 @@ import com.cappielloantonio.play.repository.ArtistRepository;
import com.cappielloantonio.play.repository.QueueRepository;
import com.cappielloantonio.play.service.MusicPlayerRemote;
import com.cappielloantonio.play.ui.activity.MainActivity;
import com.cappielloantonio.play.util.UIUtil;
import com.cappielloantonio.play.viewmodel.ArtistPageViewModel;
import java.util.ArrayList;
@ -166,18 +163,14 @@ public class ArtistPageFragment extends Fragment {
}
private void initTopSongsView() {
bind.mostStreamedSongRecyclerView.setHasFixedSize(true);
bind.mostStreamedSongRecyclerView.setLayoutManager(new LinearLayoutManager(requireContext()));
songHorizontalAdapter = new SongHorizontalAdapter(activity, requireContext(), getChildFragmentManager());
bind.mostStreamedSongRecyclerView.setAdapter(songHorizontalAdapter);
artistPageViewModel.getArtistTopSongList().observe(requireActivity(), songs -> {
artistPageViewModel.getArtistTopSongList(10).observe(requireActivity(), songs -> {
if (bind != null) bind.artistPageTopSongsSector.setVisibility(!songs.isEmpty() ? View.VISIBLE : View.GONE);
bind.mostStreamedSongRecyclerView.setLayoutManager(new GridLayoutManager(requireContext(), UIUtil.getSpanCount(songs.size(), 5), GridLayoutManager.HORIZONTAL, false));
songHorizontalAdapter.setItems(songs);
});
PagerSnapHelper pagerSnapHelper = new PagerSnapHelper();
pagerSnapHelper.attachToRecyclerView(bind.mostStreamedSongRecyclerView);
}
private void initAlbumsView() {

View file

@ -53,8 +53,8 @@ public class ArtistPageViewModel extends AndroidViewModel {
return randomList;
}
public LiveData<List<Song>> getArtistTopSongList() {
songList = artistRepository.getTopSongs(artist.getName(), 50);
public LiveData<List<Song>> getArtistTopSongList(int count) {
songList = artistRepository.getTopSongs(artist.getName(), count);
return songList;
}

View file

@ -11,6 +11,7 @@ import androidx.lifecycle.MutableLiveData;
import com.cappielloantonio.play.model.Artist;
import com.cappielloantonio.play.model.Genre;
import com.cappielloantonio.play.model.Song;
import com.cappielloantonio.play.repository.ArtistRepository;
import com.cappielloantonio.play.repository.DownloadRepository;
import com.cappielloantonio.play.repository.SongRepository;
import com.cappielloantonio.play.util.MappingUtil;
@ -20,6 +21,7 @@ import java.util.List;
public class SongListPageViewModel extends AndroidViewModel {
private SongRepository songRepository;
private ArtistRepository artistRepository;
private DownloadRepository downloadRepository;
public String title;
@ -37,6 +39,7 @@ public class SongListPageViewModel extends AndroidViewModel {
super(application);
songRepository = new SongRepository(application);
artistRepository = new ArtistRepository(application);
downloadRepository = new DownloadRepository(application);
}
@ -57,7 +60,7 @@ public class SongListPageViewModel extends AndroidViewModel {
songList = songList = songRepository.getSongsByGenre(genre.getId());
break;
case Song.BY_ARTIST:
// songList = songRepository.getArtistListLiveTopSong(artist.getId());
songList = artistRepository.getTopSongs(artist.getName(), 50);
break;
case Song.BY_GENRES:
songList = songRepository.getSongsByGenres(filters);