Implemented Top Songs view per artist

This commit is contained in:
CappielloAntonio 2021-08-02 09:31:44 +02:00
parent 7ad2e1da1d
commit f321a5520f
6 changed files with 37 additions and 26 deletions

View file

@ -284,6 +284,27 @@ public class ArtistRepository {
return randomSongs;
}
public MutableLiveData<List<Song>> getTopSongs(String artistName, int count) {
MutableLiveData<List<Song>> topSongs = new MutableLiveData<>();
App.getSubsonicClientInstance(application, false)
.getBrowsingClient()
.getTopSongs(artistName, count)
.enqueue(new Callback<SubsonicResponse>() {
@Override
public void onResponse(Call<SubsonicResponse> call, Response<SubsonicResponse> response) {
topSongs.setValue(MappingUtil.mapSong(response.body().getTopSongs().getSongs()));
}
@Override
public void onFailure(Call<SubsonicResponse> call, Throwable t) {
}
});
return topSongs;
}
private void addToMutableLiveData(MutableLiveData<List<Artist>> liveData, Artist artist) {
List<Artist> liveArtists = liveData.getValue();
liveArtists.add(artist);

View file

@ -110,9 +110,9 @@ public class BrowsingClient {
return browsingService.getSimilarSongs2(subsonic.getParams(), id, limit);
}
public Call<SubsonicResponse> getTopSongs(String id, int count) {
public Call<SubsonicResponse> getTopSongs(String artist, int count) {
Log.d(TAG, "getTopSongs()");
return browsingService.getTopSongs(subsonic.getParams(), id, count);
return browsingService.getTopSongs(subsonic.getParams(), artist, count);
}
private OkHttpClient getOkHttpClient() {

View file

@ -59,5 +59,5 @@ public interface BrowsingService {
Call<SubsonicResponse> getSimilarSongs2(@QueryMap Map<String, String> params, @Query("id") String id, @Query("count") int count);
@GET("getTopSongs")
Call<SubsonicResponse> getTopSongs(@QueryMap Map<String, String> params, @Query("id") String id, @Query("count") int count);
Call<SubsonicResponse> getTopSongs(@QueryMap Map<String, String> params, @Query("artist") String artist, @Query("count") int count);
}

View file

@ -10,6 +10,7 @@ public class SubsonicResponse {
@Element
private Error error;
private ScanStatus scanStatus;
@Element(name = "topSongs")
private TopSongs topSongs;
@Element(name = "similarSongs2")
private SimilarSongs2 similarSongs2;

View file

@ -1,35 +1,24 @@
package com.cappielloantonio.play.subsonic.models;
import com.tickaroo.tikxml.annotation.Element;
import com.tickaroo.tikxml.annotation.Xml;
import java.util.ArrayList;
import java.util.List;
@Xml
public class TopSongs {
@Element(name = "song")
protected List<Child> songs;
/**
* Gets the value of the songs property.
*
* <p>
* This accessor method returns a reference to the live list,
* not a snapshot. Therefore any modification you make to the
* returned list will be present inside the JAXB object.
* This is why there is not a <CODE>set</CODE> method for the songs property.
*
* <p>
* For example, to add a new item, do as follows:
* <pre>
* getSongs().add(newItem);
* </pre>
*
*
* <p>
* Objects of the following type(s) are allowed in the list
* {@link Child }
*/
public List<Child> getSongs() {
if (songs == null) {
songs = new ArrayList<Child>();
songs = new ArrayList<>();
}
return this.songs;
}
public void setSongs(List<Child> songs) {
this.songs = songs;
}
}

View file

@ -54,7 +54,7 @@ public class ArtistPageViewModel extends AndroidViewModel {
}
public LiveData<List<Song>> getArtistTopSongList() {
// songList = songRepository.getArtistListLiveTopSongSample(artist.id);
songList = artistRepository.getTopSongs(artist.getName(), 50);
return songList;
}