mirror of
https://github.com/antebudimir/tempus.git
synced 2025-12-31 17:43:32 +00:00
feat: Added API call to retrieve AlbumID3 details in album page as the object passed from search and album list are different
This commit is contained in:
parent
a67571ee4f
commit
2c3aebc83b
4 changed files with 61 additions and 34 deletions
|
|
@ -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.tempo.repository.AlbumRepository;
|
||||
import com.cappielloantonio.tempo.repository.ArtistRepository;
|
||||
|
|
@ -18,8 +20,8 @@ import java.util.List;
|
|||
public class AlbumPageViewModel extends AndroidViewModel {
|
||||
private final AlbumRepository albumRepository;
|
||||
private final ArtistRepository artistRepository;
|
||||
|
||||
private AlbumID3 album;
|
||||
private String albumId;
|
||||
private final MutableLiveData<AlbumID3> album = new MutableLiveData<>(null);
|
||||
|
||||
public AlbumPageViewModel(@NonNull Application application) {
|
||||
super(application);
|
||||
|
|
@ -29,22 +31,27 @@ public class AlbumPageViewModel extends AndroidViewModel {
|
|||
}
|
||||
|
||||
public LiveData<List<Child>> getAlbumSongLiveList() {
|
||||
return albumRepository.getAlbumTracks(album.getId());
|
||||
return albumRepository.getAlbumTracks(albumId);
|
||||
}
|
||||
|
||||
public AlbumID3 getAlbum() {
|
||||
public MutableLiveData<AlbumID3> getAlbum() {
|
||||
return album;
|
||||
}
|
||||
|
||||
public void setAlbum(AlbumID3 album) {
|
||||
this.album = album;
|
||||
public void setAlbum(LifecycleOwner owner, AlbumID3 album) {
|
||||
this.albumId = album.getId();
|
||||
this.album.postValue(album);
|
||||
|
||||
albumRepository.getAlbum(album.getId()).observe(owner, albums -> {
|
||||
if (albums != null) this.album.setValue(album);
|
||||
});
|
||||
}
|
||||
|
||||
public LiveData<ArtistID3> getArtist() {
|
||||
return artistRepository.getArtistInfo(album.getArtistId());
|
||||
return artistRepository.getArtistInfo(albumId);
|
||||
}
|
||||
|
||||
public LiveData<AlbumInfo> getAlbumInfo() {
|
||||
return albumRepository.getAlbumInfo(album.getId());
|
||||
return albumRepository.getAlbumInfo(albumId);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue