mirror of
https://github.com/antebudimir/tempus.git
synced 2026-01-01 01:53:31 +00:00
Added the ability to refresh samples on the home page
This commit is contained in:
parent
0b57cd3176
commit
bd9dc276f1
8 changed files with 127 additions and 16 deletions
|
|
@ -4,6 +4,7 @@ import android.app.Application;
|
|||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.lifecycle.AndroidViewModel;
|
||||
import androidx.lifecycle.LifecycleOwner;
|
||||
import androidx.lifecycle.LiveData;
|
||||
import androidx.lifecycle.MutableLiveData;
|
||||
|
||||
|
|
@ -28,16 +29,16 @@ public class HomeViewModel extends AndroidViewModel {
|
|||
private ArtistRepository artistRepository;
|
||||
private DownloadRepository downloadRepository;
|
||||
|
||||
private LiveData<List<Song>> dicoverSongSample;
|
||||
private LiveData<List<Album>> mostPlayedAlbumSample;
|
||||
private LiveData<List<Album>> recentlyAddedAlbumSample;
|
||||
private LiveData<List<Album>> recentlyPlayedAlbumSample;
|
||||
private MutableLiveData<List<Song>> dicoverSongSample;
|
||||
private MutableLiveData<List<Album>> mostPlayedAlbumSample;
|
||||
private MutableLiveData<List<Album>> recentlyAddedAlbumSample;
|
||||
private MutableLiveData<List<Album>> recentlyPlayedAlbumSample;
|
||||
private LiveData<List<Download>> downloadedSongSample;
|
||||
private LiveData<List<Integer>> years;
|
||||
|
||||
private LiveData<List<Song>> starredTracks;
|
||||
private LiveData<List<Album>> starredAlbums;
|
||||
private LiveData<List<Artist>> starredArtists;
|
||||
private MutableLiveData<List<Song>> starredTracks;
|
||||
private MutableLiveData<List<Album>> starredAlbums;
|
||||
private MutableLiveData<List<Artist>> starredArtists;
|
||||
|
||||
public HomeViewModel(@NonNull Application application) {
|
||||
super(application);
|
||||
|
|
@ -98,4 +99,32 @@ public class HomeViewModel extends AndroidViewModel {
|
|||
public LiveData<List<Album>> getRecentlyPlayedAlbumList() {
|
||||
return recentlyPlayedAlbumSample;
|
||||
}
|
||||
|
||||
public void refreshDiscoverySongSample(LifecycleOwner owner) {
|
||||
songRepository.getRandomSample(10, null, null).observe(owner, songs -> dicoverSongSample.postValue(songs));
|
||||
}
|
||||
|
||||
public void refreshStarredTracks(LifecycleOwner owner) {
|
||||
songRepository.getStarredSongs().observe(owner, songs -> starredTracks.postValue(songs));
|
||||
}
|
||||
|
||||
public void refreshStarredAlbums(LifecycleOwner owner) {
|
||||
albumRepository.getStarredAlbums().observe(owner, albums -> starredAlbums.postValue(albums));
|
||||
}
|
||||
|
||||
public void refreshStarredArtists(LifecycleOwner owner) {
|
||||
artistRepository.getStarredArtists().observe(owner, artists -> starredArtists.postValue(artists));
|
||||
}
|
||||
|
||||
public void refreshMostPlayedAlbums(LifecycleOwner owner) {
|
||||
albumRepository.getAlbums("frequent", 20).observe(owner, albums -> mostPlayedAlbumSample.postValue(albums));
|
||||
}
|
||||
|
||||
public void refreshMostRecentlyAddedAlbums(LifecycleOwner owner) {
|
||||
albumRepository.getAlbums("newest", 20).observe(owner, albums -> recentlyAddedAlbumSample.postValue(albums));
|
||||
}
|
||||
|
||||
public void refreshRecentlyPlayedAlbumList(LifecycleOwner owner) {
|
||||
albumRepository.getAlbums("recent", 20).observe(owner, albums -> recentlyPlayedAlbumSample.postValue(albums));
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,7 +4,9 @@ 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;
|
||||
|
|
@ -23,10 +25,10 @@ public class LibraryViewModel extends AndroidViewModel {
|
|||
private GenreRepository genreRepository;
|
||||
private PlaylistRepository playlistRepository;
|
||||
|
||||
private LiveData<List<Playlist>> playlistSample;
|
||||
private LiveData<List<Album>> sampleAlbum;
|
||||
private LiveData<List<Artist>> sampleArtist;
|
||||
private LiveData<List<Genre>> sampleGenres;
|
||||
private MutableLiveData<List<Playlist>> playlistSample;
|
||||
private MutableLiveData<List<Album>> sampleAlbum;
|
||||
private MutableLiveData<List<Artist>> sampleArtist;
|
||||
private MutableLiveData<List<Genre>> sampleGenres;
|
||||
|
||||
public LibraryViewModel(@NonNull Application application) {
|
||||
super(application);
|
||||
|
|
@ -44,10 +46,6 @@ public class LibraryViewModel extends AndroidViewModel {
|
|||
playlistSample = playlistRepository.getPlaylists(true, 10);
|
||||
}
|
||||
|
||||
public LiveData<List<Playlist>> getPlaylistSample() {
|
||||
return playlistSample;
|
||||
}
|
||||
|
||||
public LiveData<List<Album>> getAlbumSample() {
|
||||
return sampleAlbum;
|
||||
}
|
||||
|
|
@ -59,4 +57,24 @@ public class LibraryViewModel extends AndroidViewModel {
|
|||
public LiveData<List<Genre>> getGenreSample() {
|
||||
return sampleGenres;
|
||||
}
|
||||
|
||||
public LiveData<List<Playlist>> getPlaylistSample() {
|
||||
return playlistSample;
|
||||
}
|
||||
|
||||
public void refreshAlbumSample(LifecycleOwner owner) {
|
||||
albumRepository.getAlbums("random", 20).observe(owner, albums -> sampleAlbum.postValue(albums));
|
||||
}
|
||||
|
||||
public void refreshArtistSample(LifecycleOwner owner) {
|
||||
artistRepository.getArtists(true, 20).observe(owner, artists -> sampleArtist.postValue(artists));
|
||||
}
|
||||
|
||||
public void refreshGenreSample(LifecycleOwner owner) {
|
||||
genreRepository.getGenres(true, 15).observe(owner, genres -> sampleGenres.postValue(genres));
|
||||
}
|
||||
|
||||
public void refreshPlaylistSample(LifecycleOwner owner) {
|
||||
playlistRepository.getPlaylists(true, 10).observe(owner, playlists -> playlistSample.postValue(playlists));
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue