Refactoring - Removed most of the click listeners from the adapters and moved them into the appropriate fragments

This commit is contained in:
antonio 2023-01-04 09:14:15 +01:00
parent 29f56945c2
commit 754fc69eab
54 changed files with 1143 additions and 1137 deletions

View file

@ -245,27 +245,27 @@ public class ArtistRepository {
return artist;
}
public void getInstantMix(Artist artist, int count, MediaCallback callback) {
public MutableLiveData<ArrayList<Media>> getInstantMix(Artist artist, int count) {
MutableLiveData<ArrayList<Media>> instantMix = new MutableLiveData<>();
App.getSubsonicClientInstance(application, false)
.getBrowsingClient()
.getSimilarSongs2(artist.getId(), count)
.enqueue(new Callback<SubsonicResponse>() {
@Override
public void onResponse(@NonNull Call<SubsonicResponse> call, @NonNull Response<SubsonicResponse> response) {
List<Media> songs = new ArrayList<>();
if (response.isSuccessful() && response.body() != null && response.body().getSimilarSongs2() != null) {
songs.addAll(MappingUtil.mapSong(response.body().getSimilarSongs2().getSongs()));
instantMix.setValue(MappingUtil.mapSong(response.body().getSimilarSongs2().getSongs()));
}
callback.onLoadMedia(songs);
}
@Override
public void onFailure(@NonNull Call<SubsonicResponse> call, @NonNull Throwable t) {
callback.onLoadMedia(new ArrayList<>());
}
});
return instantMix;
}
public MutableLiveData<ArrayList<Media>> getArtistRandomSong(LifecycleOwner owner, Artist artist, int count) {

View file

@ -59,7 +59,9 @@ public class SongRepository {
return starredSongs;
}
public void getInstantMix(Media song, int count, MediaCallback callback) {
public MutableLiveData<ArrayList<Media>> getInstantMix(Media song, int count) {
MutableLiveData<ArrayList<Media>> instantMix = new MutableLiveData<>();
App.getSubsonicClientInstance(application, false)
.getBrowsingClient()
.getSimilarSongs2(song.getId(), count)
@ -67,23 +69,17 @@ public class SongRepository {
@Override
public void onResponse(@NonNull Call<SubsonicResponse> call, @NonNull Response<SubsonicResponse> response) {
if (response.isSuccessful() && response.body() != null && response.body().getSimilarSongs2() != null) {
List<Media> songs = new ArrayList<>(MappingUtil.mapSong(response.body().getSimilarSongs2().getSongs()));
if (songs.size() <= 1) {
songs.add(song);
}
callback.onLoadMedia(songs);
instantMix.setValue(MappingUtil.mapSong(response.body().getSimilarSongs2().getSongs()));
}
}
@Override
public void onFailure(@NonNull Call<SubsonicResponse> call, @NonNull Throwable t) {
List<Media> songs = new ArrayList<>();
songs.add(song);
callback.onLoadMedia(songs);
instantMix.setValue(null);
}
});
return instantMix;
}
public MutableLiveData<List<Media>> getRandomSample(int number, Integer fromYear, Integer toYear) {