mirror of
https://github.com/antebudimir/tempus.git
synced 2026-01-01 18:03:33 +00:00
65 lines
2.4 KiB
Java
65 lines
2.4 KiB
Java
|
|
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.Song;
|
||
|
|
import com.cappielloantonio.play.repository.AlbumRepository;
|
||
|
|
import com.cappielloantonio.play.repository.ArtistRepository;
|
||
|
|
import com.cappielloantonio.play.repository.SongRepository;
|
||
|
|
|
||
|
|
import java.util.List;
|
||
|
|
|
||
|
|
public class StarredViewModel extends AndroidViewModel {
|
||
|
|
private final SongRepository songRepository;
|
||
|
|
private final AlbumRepository albumRepository;
|
||
|
|
private final ArtistRepository artistRepository;
|
||
|
|
|
||
|
|
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);
|
||
|
|
|
||
|
|
|
||
|
|
public StarredViewModel(@NonNull Application application) {
|
||
|
|
super(application);
|
||
|
|
|
||
|
|
songRepository = new SongRepository(application);
|
||
|
|
albumRepository = new AlbumRepository(application);
|
||
|
|
artistRepository = new ArtistRepository(application);
|
||
|
|
}
|
||
|
|
|
||
|
|
public LiveData<List<Song>> getStarredTracks(LifecycleOwner owner) {
|
||
|
|
songRepository.getStarredSongs(true, 20).observe(owner, starredTracks::postValue);
|
||
|
|
return starredTracks;
|
||
|
|
}
|
||
|
|
|
||
|
|
public LiveData<List<Album>> getStarredAlbums(LifecycleOwner owner) {
|
||
|
|
albumRepository.getStarredAlbums(true, 20).observe(owner, starredAlbums::postValue);
|
||
|
|
return starredAlbums;
|
||
|
|
}
|
||
|
|
|
||
|
|
public LiveData<List<Artist>> getStarredArtists(LifecycleOwner owner) {
|
||
|
|
artistRepository.getStarredArtists(true, 20).observe(owner, starredArtists::postValue);
|
||
|
|
return starredArtists;
|
||
|
|
}
|
||
|
|
|
||
|
|
public void refreshStarredTracks(LifecycleOwner owner) {
|
||
|
|
songRepository.getStarredSongs(true, 20).observe(owner, starredTracks::postValue);
|
||
|
|
}
|
||
|
|
|
||
|
|
public void refreshStarredAlbums(LifecycleOwner owner) {
|
||
|
|
albumRepository.getStarredAlbums(true, 20).observe(owner, starredAlbums::postValue);
|
||
|
|
}
|
||
|
|
|
||
|
|
public void refreshStarredArtists(LifecycleOwner owner) {
|
||
|
|
artistRepository.getStarredArtists(true, 20).observe(owner, starredArtists::postValue);
|
||
|
|
}
|
||
|
|
}
|