2020-11-23 09:28:20 +01:00
|
|
|
package com.cappielloantonio.play.viewmodel;
|
|
|
|
|
|
|
|
|
|
import android.app.Application;
|
|
|
|
|
|
|
|
|
|
import androidx.annotation.NonNull;
|
|
|
|
|
import androidx.lifecycle.AndroidViewModel;
|
|
|
|
|
import androidx.lifecycle.LiveData;
|
2021-07-30 14:09:50 +02:00
|
|
|
import androidx.lifecycle.MutableLiveData;
|
2020-11-23 09:28:20 +01:00
|
|
|
|
|
|
|
|
import com.cappielloantonio.play.model.Album;
|
2021-05-01 17:11:09 +02:00
|
|
|
import com.cappielloantonio.play.model.Artist;
|
2020-11-23 09:28:20 +01:00
|
|
|
import com.cappielloantonio.play.model.Song;
|
2021-07-30 14:09:50 +02:00
|
|
|
import com.cappielloantonio.play.repository.AlbumRepository;
|
2021-05-01 17:11:09 +02:00
|
|
|
import com.cappielloantonio.play.repository.ArtistRepository;
|
2020-11-23 09:28:20 +01:00
|
|
|
import com.cappielloantonio.play.repository.SongRepository;
|
|
|
|
|
|
|
|
|
|
import java.util.List;
|
|
|
|
|
|
|
|
|
|
public class AlbumPageViewModel extends AndroidViewModel {
|
|
|
|
|
private SongRepository songRepository;
|
2021-07-30 14:09:50 +02:00
|
|
|
private AlbumRepository albumRepository;
|
2021-05-01 17:11:09 +02:00
|
|
|
private ArtistRepository artistRepository;
|
2020-11-23 09:28:20 +01:00
|
|
|
|
2021-07-30 14:09:50 +02:00
|
|
|
private LiveData<List<Song>> songLiveList = new MutableLiveData<>();
|
2020-11-23 09:28:20 +01:00
|
|
|
|
|
|
|
|
private Album album;
|
|
|
|
|
|
|
|
|
|
public AlbumPageViewModel(@NonNull Application application) {
|
|
|
|
|
super(application);
|
|
|
|
|
|
|
|
|
|
songRepository = new SongRepository(application);
|
2021-07-30 14:09:50 +02:00
|
|
|
albumRepository = new AlbumRepository(application);
|
2021-05-01 17:11:09 +02:00
|
|
|
artistRepository = new ArtistRepository(application);
|
2020-11-23 09:28:20 +01:00
|
|
|
}
|
|
|
|
|
|
2021-04-26 19:50:23 +02:00
|
|
|
public LiveData<List<Song>> getAlbumSongLiveList() {
|
2021-07-30 14:09:50 +02:00
|
|
|
songLiveList = albumRepository.getAlbumTracks(album.getId());
|
2021-04-26 19:50:23 +02:00
|
|
|
return songLiveList;
|
|
|
|
|
}
|
|
|
|
|
|
2020-11-23 09:28:20 +01:00
|
|
|
public Album getAlbum() {
|
|
|
|
|
return album;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void setAlbum(Album album) {
|
|
|
|
|
this.album = album;
|
|
|
|
|
}
|
2021-05-01 17:11:09 +02:00
|
|
|
|
2021-07-30 14:09:50 +02:00
|
|
|
public LiveData<Artist> getArtist() {
|
|
|
|
|
return artistRepository.getArtistInfo(album.getArtistId());
|
2021-05-01 17:11:09 +02:00
|
|
|
}
|
2020-11-23 09:28:20 +01:00
|
|
|
}
|