Fix shuffling genres only queuing 25 songs (#246)

This commit is contained in:
eddyizm 2025-11-09 16:41:17 -08:00 committed by GitHub
commit 33981f9885
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 38 additions and 3 deletions

View file

@ -100,6 +100,33 @@ public class SongRepository {
return randomSongsSample; 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()
.getRandomSongs(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) { public void scrobble(String id, boolean submission) {
App.getSubsonicClientInstance(false) App.getSubsonicClientInstance(false)
.getMediaAnnotationClient() .getMediaAnnotationClient()

View file

@ -34,6 +34,11 @@ public class AlbumSongListClient {
return albumSongListService.getRandomSongs(subsonic.getParams(), size, fromYear, toYear); return albumSongListService.getRandomSongs(subsonic.getParams(), size, fromYear, toYear);
} }
public Call<ApiResponse> getRandomSongs(int size, Integer fromYear, Integer toYear, String genre) {
Log.d(TAG, "getRandomSongs()");
return albumSongListService.getRandomSongs(subsonic.getParams(), size, fromYear, toYear, genre);
}
public Call<ApiResponse> getSongsByGenre(String genre, int count, int offset) { public Call<ApiResponse> getSongsByGenre(String genre, int count, int offset) {
Log.d(TAG, "getSongsByGenre()"); Log.d(TAG, "getSongsByGenre()");
return albumSongListService.getSongsByGenre(subsonic.getParams(), genre, count, offset); return albumSongListService.getSongsByGenre(subsonic.getParams(), genre, count, offset);

View file

@ -19,6 +19,9 @@ public interface AlbumSongListService {
@GET("getRandomSongs") @GET("getRandomSongs")
Call<ApiResponse> getRandomSongs(@QueryMap Map<String, String> params, @Query("size") int size, @Query("fromYear") Integer fromYear, @Query("toYear") Integer toYear); Call<ApiResponse> getRandomSongs(@QueryMap Map<String, String> params, @Query("size") int size, @Query("fromYear") Integer fromYear, @Query("toYear") Integer toYear);
@GET("getRandomSongs")
Call<ApiResponse> getRandomSongs(@QueryMap Map<String, String> params, @Query("size") int size, @Query("fromYear") Integer fromYear, @Query("toYear") Integer toYear, @Query("genre") String genre);
@GET("getSongsByGenre") @GET("getSongsByGenre")
Call<ApiResponse> getSongsByGenre(@QueryMap Map<String, String> params, @Query("genre") String genre, @Query("count") int count, @Query("offset") int offset); Call<ApiResponse> getSongsByGenre(@QueryMap Map<String, String> params, @Query("genre") String genre, @Query("count") int count, @Query("offset") int offset);

View file

@ -189,7 +189,7 @@ public class SongListPageFragment extends Fragment implements ClickCallback {
bind.songListShuffleImageView.setOnClickListener(v -> { bind.songListShuffleImageView.setOnClickListener(v -> {
Collections.shuffle(songs); Collections.shuffle(songs);
MediaManager.startQueue(mediaBrowserListenableFuture, songs.subList(0, Math.min(25, songs.size())), 0); MediaManager.startQueue(mediaBrowserListenableFuture, songs.subList(0, Math.min(500, songs.size())), 0);
activity.setBottomSheetInPeek(true); activity.setBottomSheetInPeek(true);
}); });
} }

View file

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