2020-11-20 15:38:08 +01:00
|
|
|
package com.cappielloantonio.play.viewmodel;
|
|
|
|
|
|
2020-11-21 18:41:35 +01:00
|
|
|
import android.app.Application;
|
|
|
|
|
|
|
|
|
|
import androidx.annotation.NonNull;
|
|
|
|
|
import androidx.lifecycle.AndroidViewModel;
|
|
|
|
|
import androidx.lifecycle.LiveData;
|
2021-07-28 15:28:32 +02:00
|
|
|
import androidx.lifecycle.MutableLiveData;
|
2020-11-20 15:38:08 +01:00
|
|
|
|
2021-07-27 12:10:28 +02:00
|
|
|
import com.cappielloantonio.play.interfaces.MediaCallback;
|
|
|
|
|
import com.cappielloantonio.play.model.Album;
|
2021-07-27 16:58:38 +02:00
|
|
|
import com.cappielloantonio.play.model.Artist;
|
2021-07-29 17:12:55 +02:00
|
|
|
import com.cappielloantonio.play.model.Download;
|
2020-11-20 15:38:08 +01:00
|
|
|
import com.cappielloantonio.play.model.Song;
|
2021-07-27 12:10:28 +02:00
|
|
|
import com.cappielloantonio.play.repository.AlbumRepository;
|
2021-07-27 16:58:38 +02:00
|
|
|
import com.cappielloantonio.play.repository.ArtistRepository;
|
2021-07-29 17:12:55 +02:00
|
|
|
import com.cappielloantonio.play.repository.DownloadRepository;
|
2020-11-21 18:41:35 +01:00
|
|
|
import com.cappielloantonio.play.repository.SongRepository;
|
2020-11-20 15:38:08 +01:00
|
|
|
|
2021-07-27 12:10:28 +02:00
|
|
|
import java.util.ArrayList;
|
2020-11-20 15:38:08 +01:00
|
|
|
import java.util.List;
|
2021-08-04 11:12:21 +02:00
|
|
|
import java.util.Map;
|
2020-11-20 15:38:08 +01:00
|
|
|
|
2020-11-21 18:41:35 +01:00
|
|
|
public class HomeViewModel extends AndroidViewModel {
|
2020-11-22 19:11:38 +01:00
|
|
|
private static final String TAG = "HomeViewModel";
|
2020-11-21 18:41:35 +01:00
|
|
|
private SongRepository songRepository;
|
2021-07-27 12:10:28 +02:00
|
|
|
private AlbumRepository albumRepository;
|
2021-07-27 16:58:38 +02:00
|
|
|
private ArtistRepository artistRepository;
|
2021-07-29 17:12:55 +02:00
|
|
|
private DownloadRepository downloadRepository;
|
2020-11-21 18:41:35 +01:00
|
|
|
|
2021-08-04 11:12:21 +02:00
|
|
|
private LiveData<List<Song>> dicoverSongSample;
|
2021-07-27 12:10:28 +02:00
|
|
|
private LiveData<List<Album>> mostPlayedAlbumSample;
|
|
|
|
|
private LiveData<List<Album>> recentlyAddedAlbumSample;
|
|
|
|
|
private LiveData<List<Album>> recentlyPlayedAlbumSample;
|
2021-08-04 11:12:21 +02:00
|
|
|
private LiveData<List<Download>> downloadedSongSample;
|
|
|
|
|
private LiveData<List<Integer>> years;
|
2021-07-27 12:10:28 +02:00
|
|
|
|
2021-07-27 16:58:38 +02:00
|
|
|
private LiveData<List<Song>> starredTracks;
|
|
|
|
|
private LiveData<List<Album>> starredAlbums;
|
|
|
|
|
private LiveData<List<Artist>> starredArtists;
|
|
|
|
|
|
2020-11-21 18:41:35 +01:00
|
|
|
public HomeViewModel(@NonNull Application application) {
|
|
|
|
|
super(application);
|
2020-11-20 15:38:08 +01:00
|
|
|
|
2020-11-21 18:41:35 +01:00
|
|
|
songRepository = new SongRepository(application);
|
2021-07-27 12:10:28 +02:00
|
|
|
albumRepository = new AlbumRepository(application);
|
2021-07-27 16:58:38 +02:00
|
|
|
artistRepository = new ArtistRepository(application);
|
2021-07-29 17:12:55 +02:00
|
|
|
downloadRepository = new DownloadRepository(application);
|
2020-11-20 15:38:08 +01:00
|
|
|
|
2021-08-04 11:12:21 +02:00
|
|
|
dicoverSongSample = songRepository.getRandomSample(10, null, null);
|
2021-07-29 14:19:19 +02:00
|
|
|
mostPlayedAlbumSample = albumRepository.getAlbums("frequent", 20);
|
|
|
|
|
recentlyAddedAlbumSample = albumRepository.getAlbums("newest", 20);
|
|
|
|
|
recentlyPlayedAlbumSample = albumRepository.getAlbums("recent", 20);
|
2021-08-04 11:12:21 +02:00
|
|
|
downloadedSongSample = downloadRepository.getLiveDownloadSample(10);
|
|
|
|
|
years = albumRepository.getDecades();
|
2021-07-27 16:58:38 +02:00
|
|
|
|
|
|
|
|
starredTracks = songRepository.getStarredSongs();
|
|
|
|
|
starredAlbums = albumRepository.getStarredAlbums();
|
|
|
|
|
starredArtists = artistRepository.getStarredArtists();
|
2021-07-27 12:10:28 +02:00
|
|
|
}
|
2020-11-24 10:52:00 +01:00
|
|
|
|
2021-07-27 12:10:28 +02:00
|
|
|
public SongRepository getSongRepository() {
|
|
|
|
|
return songRepository;
|
2020-11-20 15:38:08 +01:00
|
|
|
}
|
|
|
|
|
|
2021-07-28 15:46:05 +02:00
|
|
|
public LiveData<List<Song>> getDiscoverSongSample() {
|
|
|
|
|
return dicoverSongSample;
|
2020-11-21 18:41:35 +01:00
|
|
|
}
|
|
|
|
|
|
2021-08-04 11:12:21 +02:00
|
|
|
public LiveData<List<Integer>> getYearList() {
|
2021-07-28 15:46:05 +02:00
|
|
|
return years;
|
2020-11-21 18:41:35 +01:00
|
|
|
}
|
2020-11-20 15:38:08 +01:00
|
|
|
|
2021-07-27 16:58:38 +02:00
|
|
|
public LiveData<List<Song>> getStarredTracks() {
|
|
|
|
|
return starredTracks;
|
2020-11-20 15:38:08 +01:00
|
|
|
}
|
2020-11-28 14:50:15 +01:00
|
|
|
|
2021-07-27 16:58:38 +02:00
|
|
|
public LiveData<List<Album>> getStarredAlbums() {
|
|
|
|
|
return starredAlbums;
|
2020-11-28 14:50:15 +01:00
|
|
|
}
|
2020-11-30 20:54:05 +01:00
|
|
|
|
2021-07-27 16:58:38 +02:00
|
|
|
public LiveData<List<Artist>> getStarredArtists() {
|
|
|
|
|
return starredArtists;
|
2020-11-30 20:54:05 +01:00
|
|
|
}
|
2021-04-26 19:37:05 +02:00
|
|
|
|
2021-07-29 17:12:55 +02:00
|
|
|
public LiveData<List<Download>> getDownloaded() {
|
2021-04-26 19:37:05 +02:00
|
|
|
return downloadedSongSample;
|
|
|
|
|
}
|
2021-07-27 12:10:28 +02:00
|
|
|
|
2021-08-01 11:48:18 +02:00
|
|
|
public LiveData<List<Album>> getMostPlayedAlbums() {
|
2021-07-27 12:10:28 +02:00
|
|
|
return mostPlayedAlbumSample;
|
|
|
|
|
}
|
|
|
|
|
|
2021-08-01 11:48:18 +02:00
|
|
|
public LiveData<List<Album>> getMostRecentlyAddedAlbums() {
|
2021-07-27 12:10:28 +02:00
|
|
|
return recentlyAddedAlbumSample;
|
|
|
|
|
}
|
|
|
|
|
|
2021-08-01 11:48:18 +02:00
|
|
|
public LiveData<List<Album>> getRecentlyPlayedAlbumList() {
|
2021-07-27 12:10:28 +02:00
|
|
|
return recentlyPlayedAlbumSample;
|
|
|
|
|
}
|
2020-11-20 15:38:08 +01:00
|
|
|
}
|