First reimplementation of download functionality

This commit is contained in:
antonio
2023-03-10 09:31:15 +01:00
parent 77a3b90b4e
commit 3e7d260d6a
16 changed files with 143 additions and 92 deletions

View File

@@ -8,10 +8,10 @@ import androidx.lifecycle.LifecycleOwner;
import androidx.lifecycle.LiveData;
import androidx.lifecycle.MutableLiveData;
import com.cappielloantonio.play.model.Album;
import com.cappielloantonio.play.model.Artist;
import com.cappielloantonio.play.model.Playlist;
import com.cappielloantonio.play.repository.DownloadRepository;
import com.cappielloantonio.play.subsonic.models.AlbumID3;
import com.cappielloantonio.play.subsonic.models.ArtistID3;
import com.cappielloantonio.play.subsonic.models.Child;
import com.cappielloantonio.play.util.MappingUtil;
@@ -23,8 +23,8 @@ public class DownloadViewModel extends AndroidViewModel {
private final DownloadRepository downloadRepository;
private final MutableLiveData<List<Artist>> downloadedArtistSample = new MutableLiveData<>(null);
private final MutableLiveData<List<Album>> downloadedAlbumSample = new MutableLiveData<>(null);
private final MutableLiveData<List<ArtistID3>> downloadedArtistSample = new MutableLiveData<>(null);
private final MutableLiveData<List<AlbumID3>> downloadedAlbumSample = new MutableLiveData<>(null);
private final MutableLiveData<List<Child>> downloadedTrackSample = new MutableLiveData<>(null);
private final MutableLiveData<List<Playlist>> downloadedPlaylistSample = new MutableLiveData<>(null);
@@ -34,13 +34,40 @@ public class DownloadViewModel extends AndroidViewModel {
downloadRepository = new DownloadRepository(application);
}
public LiveData<List<Artist>> getDownloadedArtists(LifecycleOwner owner, int size) {
downloadRepository.getLiveDownloadSample(size, true, false, false, false).observe(owner, downloads -> downloadedArtistSample.postValue(MappingUtil.mapDownloadToArtist(downloads)));
public LiveData<List<ArtistID3>> getDownloadedArtists(LifecycleOwner owner, int size) {
downloadRepository.getLiveDownloadSample(size, true, false, false, false)
.observe(owner, downloads -> downloadedArtistSample.postValue(downloads.stream().map(download -> {
ArtistID3 artist = new ArtistID3();
artist.setId(download.getArtistId());
artist.setName(download.getArtist());
artist.setCoverArtId(download.getCoverArtId());
// artist.setAlbumCount(0);
// artist.setStarred(null);
return artist;
}).collect(Collectors.toList())));
return downloadedArtistSample;
}
public LiveData<List<Album>> getDownloadedAlbums(LifecycleOwner owner, int size) {
downloadRepository.getLiveDownloadSample(size, false, true, false, false).observe(owner, downloads -> downloadedAlbumSample.postValue(MappingUtil.mapDownloadToAlbum(downloads)));
public LiveData<List<AlbumID3>> getDownloadedAlbums(LifecycleOwner owner, int size) {
downloadRepository.getLiveDownloadSample(size, false, true, false, false)
.observe(owner, downloads -> downloadedAlbumSample.postValue(downloads.stream().map(download -> {
AlbumID3 album = new AlbumID3();
album.setId(download.getAlbumId());
album.setName(download.getAlbum());
album.setArtist(album.getArtist());
album.setArtistId(album.getArtistId());
album.setCoverArtId(album.getCoverArtId());
// album.setSongCount(0);
// album.setDuration(0);
// album.setPlayCount(null);
// album.setCreated(null);
// album.setStarred(null);
album.setYear(album.getYear());
// album.setGenre(null);
return album;
}).collect(Collectors.toList())));
return downloadedAlbumSample;
}