mirror of
https://github.com/antebudimir/tempus.git
synced 2026-01-01 09:53:33 +00:00
First implementation of the panel dedicated to the download, divided by type of the downloaded resource
This commit is contained in:
parent
8789b44e26
commit
23568bae9b
16 changed files with 609 additions and 102 deletions
|
|
@ -0,0 +1,52 @@
|
|||
package com.cappielloantonio.play.viewmodel;
|
||||
|
||||
import android.app.Application;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.lifecycle.AndroidViewModel;
|
||||
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.Download;
|
||||
import com.cappielloantonio.play.model.Song;
|
||||
import com.cappielloantonio.play.repository.AlbumRepository;
|
||||
import com.cappielloantonio.play.repository.ArtistRepository;
|
||||
import com.cappielloantonio.play.repository.DownloadRepository;
|
||||
import com.cappielloantonio.play.repository.SongRepository;
|
||||
import com.cappielloantonio.play.util.MappingUtil;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class DownloadViewModel extends AndroidViewModel {
|
||||
private static final String TAG = "HomeViewModel";
|
||||
|
||||
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<Song>> downloadedTrackSample = new MutableLiveData<>(null);
|
||||
|
||||
public DownloadViewModel(@NonNull Application application) {
|
||||
super(application);
|
||||
|
||||
downloadRepository = new DownloadRepository(application);
|
||||
}
|
||||
|
||||
public LiveData<List<Artist>> getDownloadedArtists(LifecycleOwner owner, int size) {
|
||||
downloadRepository.getLiveDownloadSample(size).observe(owner, downloads -> downloadedArtistSample.postValue(MappingUtil.mapDownloadToArtist(downloads)));
|
||||
return downloadedArtistSample;
|
||||
}
|
||||
|
||||
public LiveData<List<Album>> getDownloadedAlbums(LifecycleOwner owner, int size) {
|
||||
downloadRepository.getLiveDownloadSample(size).observe(owner, downloads -> downloadedAlbumSample.postValue(MappingUtil.mapDownloadToAlbum(downloads)));
|
||||
return downloadedAlbumSample;
|
||||
}
|
||||
|
||||
public LiveData<List<Song>> getDownloadedTracks(LifecycleOwner owner, int size) {
|
||||
downloadRepository.getLiveDownloadSample(size).observe(owner, downloads -> downloadedTrackSample.postValue(MappingUtil.mapDownloadToSong(downloads)));
|
||||
return downloadedTrackSample;
|
||||
}
|
||||
}
|
||||
|
|
@ -25,7 +25,6 @@ public class HomeViewModel extends AndroidViewModel {
|
|||
private final SongRepository songRepository;
|
||||
private final AlbumRepository albumRepository;
|
||||
private final ArtistRepository artistRepository;
|
||||
private final DownloadRepository downloadRepository;
|
||||
|
||||
private final MutableLiveData<List<Song>> dicoverSongSample = new MutableLiveData<>(null);
|
||||
private final MutableLiveData<List<Song>> starredTracksSample = new MutableLiveData<>(null);
|
||||
|
|
@ -36,7 +35,6 @@ public class HomeViewModel extends AndroidViewModel {
|
|||
private final MutableLiveData<List<Song>> starredTracks = new MutableLiveData<>(null);
|
||||
private final MutableLiveData<List<Album>> starredAlbums = new MutableLiveData<>(null);
|
||||
private final MutableLiveData<List<Artist>> starredArtists = new MutableLiveData<>(null);
|
||||
private final MutableLiveData<List<Download>> downloadedSongSample = new MutableLiveData<>(null);
|
||||
private final MutableLiveData<List<Album>> recentlyAddedAlbumSample = new MutableLiveData<>(null);
|
||||
|
||||
public HomeViewModel(@NonNull Application application) {
|
||||
|
|
@ -45,7 +43,6 @@ public class HomeViewModel extends AndroidViewModel {
|
|||
songRepository = new SongRepository(application);
|
||||
albumRepository = new AlbumRepository(application);
|
||||
artistRepository = new ArtistRepository(application);
|
||||
downloadRepository = new DownloadRepository(application);
|
||||
|
||||
songRepository.getRandomSample(10, null, null).observeForever(dicoverSongSample::postValue);
|
||||
songRepository.getStarredSongs(true, 10).observeForever(starredTracksSample::postValue);
|
||||
|
|
@ -79,11 +76,6 @@ public class HomeViewModel extends AndroidViewModel {
|
|||
return starredArtists;
|
||||
}
|
||||
|
||||
public LiveData<List<Download>> getDownloaded(LifecycleOwner owner) {
|
||||
downloadRepository.getLiveDownloadSample(10).observe(owner, downloadedSongSample::postValue);
|
||||
return downloadedSongSample;
|
||||
}
|
||||
|
||||
public LiveData<List<Album>> getMostPlayedAlbums(LifecycleOwner owner) {
|
||||
albumRepository.getAlbums("frequent", 20).observe(owner, mostPlayedAlbumSample::postValue);
|
||||
return mostPlayedAlbumSample;
|
||||
|
|
|
|||
|
|
@ -70,7 +70,7 @@ public class SongListPageViewModel extends AndroidViewModel {
|
|||
songList = songRepository.getStarredSongs(false, -1);
|
||||
break;
|
||||
case Song.DOWNLOADED:
|
||||
songList.setValue(MappingUtil.mapDownload(downloadRepository.getLiveDownload()));
|
||||
songList.setValue(MappingUtil.mapDownloadToSong(downloadRepository.getLiveDownload()));
|
||||
break;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue