Added discover/recentryAddedAlbum/recentlyPlayedAlbum/mostPlayedAlbum data retrieval

This commit is contained in:
CappielloAntonio 2021-07-27 12:10:28 +02:00
parent 304a5f078a
commit 532fcd1ee6
45 changed files with 351 additions and 1205 deletions

View file

@ -0,0 +1,31 @@
package com.cappielloantonio.play.util;
import com.cappielloantonio.play.model.Album;
import com.cappielloantonio.play.model.Song;
import com.cappielloantonio.play.subsonic.models.AlbumID3;
import com.cappielloantonio.play.subsonic.models.Child;
import java.util.ArrayList;
import java.util.List;
public class MappingUtil {
public static ArrayList<Song> mapSong(List<Child> children) {
ArrayList<Song> songs = new ArrayList();
for(Child child : children){
songs.add(new Song(child));
}
return songs;
}
public static ArrayList<Album> mapAlbum(List<AlbumID3> albumID3List) {
ArrayList<Album> albums = new ArrayList();
for(AlbumID3 albumID3 : albumID3List){
albums.add(new Album(albumID3));
}
return albums;
}
}

View file

@ -68,7 +68,7 @@ public class SyncUtil {
});
}
public static void getSongs(Context context, MediaCallback callback, AlbumID3 album) {
public static void getSongs(Context context, Map<Integer, Song> currentCatalogue, MediaCallback callback, AlbumID3 album) {
App.getSubsonicClientInstance(context, false)
.getBrowsingClient()
.getAlbum(album.getId())
@ -79,9 +79,9 @@ public class SyncUtil {
String errorMessage = response.body().getError().getCode().getValue() + " - " + response.body().getError().getMessage();
callback.onError(new Exception(errorMessage));
} else if (response.body().getStatus().getValue().equals(ResponseStatus.OK)) {
List<Child> childList = new ArrayList<>();
childList.addAll(response.body().getAlbum().getSongs());
callback.onLoadMedia(childList);
List<Song> songList = new ArrayList<>(MappingUtil.mapSong(response.body().getAlbum().getSongs()));
updateSongData(currentCatalogue, songList);
callback.onLoadMedia(songList);
} else {
callback.onError(new Exception("Empty response"));
}
@ -307,16 +307,16 @@ public class SyncUtil {
return bundle;
}
private static Song updateSongData(Map<Integer, Song> library, Song newSong) {
if (library.containsKey(newSong.hashCode())) {
Song oldSong = library.get(newSong.hashCode());
newSong.setFavorite(oldSong.isFavorite());
newSong.setAdded(oldSong.getAdded());
newSong.setLastPlay(oldSong.getLastPlay());
newSong.setPlayCount(oldSong.getPlayCount());
newSong.setOffline(oldSong.isOffline());
private static void updateSongData(Map<Integer, Song> library, List<Song> songs) {
for (Song song: songs) {
if (library.containsKey(song.hashCode())) {
Song oldSong = library.get(song.hashCode());
song.setFavorite(oldSong.isFavorite());
song.setAdded(oldSong.getAdded());
song.setLastPlay(oldSong.getLastPlay());
song.setPlayCount(oldSong.getPlayCount());
song.setOffline(oldSong.isOffline());
}
}
return newSong;
}
}