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> starredTracks = new MutableLiveData<>(null); private final MutableLiveData> starredAlbums = new MutableLiveData<>(null); private final MutableLiveData> 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> getStarredTracks(LifecycleOwner owner) { songRepository.getStarredSongs(true, 20).observe(owner, starredTracks::postValue); return starredTracks; } public LiveData> getStarredAlbums(LifecycleOwner owner) { albumRepository.getStarredAlbums(true, 20).observe(owner, starredAlbums::postValue); return starredAlbums; } public LiveData> 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); } }