use getRandomSampleWithGenre() rather than getSongsByGenre()

This commit is contained in:
observer 2025-11-09 15:05:05 +00:00
parent 8ce0a82506
commit 35784216bc
No known key found for this signature in database
GPG key ID: 2DE1FE56348E60D0
2 changed files with 29 additions and 2 deletions

View file

@ -100,6 +100,33 @@ public class SongRepository {
return randomSongsSample;
}
public MutableLiveData<List<Child>> getRandomSampleWithGenre(int number, Integer fromYear, Integer toYear, String genre) {
MutableLiveData<List<Child>> randomSongsSample = new MutableLiveData<>();
App.getSubsonicClientInstance(false)
.getAlbumSongListClient()
.getRandomSongs2(number, fromYear, toYear, genre)
.enqueue(new Callback<ApiResponse>() {
@Override
public void onResponse(@NonNull Call<ApiResponse> call, @NonNull Response<ApiResponse> response) {
List<Child> songs = new ArrayList<>();
if (response.isSuccessful() && response.body() != null && response.body().getSubsonicResponse().getRandomSongs() != null && response.body().getSubsonicResponse().getRandomSongs().getSongs() != null) {
songs.addAll(response.body().getSubsonicResponse().getRandomSongs().getSongs());
}
randomSongsSample.setValue(songs);
}
@Override
public void onFailure(@NonNull Call<ApiResponse> call, @NonNull Throwable t) {
}
});
return randomSongsSample;
}
public void scrobble(String id, boolean submission) {
App.getSubsonicClientInstance(false)
.getMediaAnnotationClient()

View file

@ -37,7 +37,7 @@ public class SongListPageViewModel extends AndroidViewModel {
public int year = 0;
public int maxNumberByYear = 500;
public int maxNumberByGenre = 100;
public int maxNumberByGenre = 500;
public SongListPageViewModel(@NonNull Application application) {
super(application);
@ -51,7 +51,7 @@ public class SongListPageViewModel extends AndroidViewModel {
switch (title) {
case Constants.MEDIA_BY_GENRE:
songList = songRepository.getSongsByGenre(genre.getGenre(), 0);
songList = songRepository.getRandomSampleWithGenre(maxNumberByGenre, 0, 3000, genre.getGenre());
break;
case Constants.MEDIA_BY_ARTIST:
songList = artistRepository.getTopSongs(artist.getName(), 50);