2023-06-17 15:30:23 +02:00
|
|
|
package com.cappielloantonio.tempo.viewmodel;
|
2020-11-30 20:54:05 +01:00
|
|
|
|
|
|
|
|
import android.app.Application;
|
|
|
|
|
|
|
|
|
|
import androidx.annotation.NonNull;
|
|
|
|
|
import androidx.lifecycle.AndroidViewModel;
|
2021-07-31 16:37:41 +02:00
|
|
|
import androidx.lifecycle.LiveData;
|
|
|
|
|
import androidx.lifecycle.MutableLiveData;
|
2020-11-30 20:54:05 +01:00
|
|
|
|
2023-06-17 15:30:23 +02:00
|
|
|
import com.cappielloantonio.tempo.repository.AlbumRepository;
|
|
|
|
|
import com.cappielloantonio.tempo.repository.ArtistRepository;
|
|
|
|
|
import com.cappielloantonio.tempo.subsonic.models.AlbumID3;
|
|
|
|
|
import com.cappielloantonio.tempo.subsonic.models.ArtistID3;
|
|
|
|
|
import com.cappielloantonio.tempo.subsonic.models.Child;
|
2020-11-30 20:54:05 +01:00
|
|
|
|
2023-03-06 21:59:10 +01:00
|
|
|
import java.util.Date;
|
2021-07-31 16:37:41 +02:00
|
|
|
import java.util.List;
|
|
|
|
|
|
2020-11-30 20:54:05 +01:00
|
|
|
public class AlbumBottomSheetViewModel extends AndroidViewModel {
|
2021-09-02 14:12:13 +02:00
|
|
|
private final AlbumRepository albumRepository;
|
|
|
|
|
private final ArtistRepository artistRepository;
|
2020-12-01 20:04:54 +01:00
|
|
|
|
2023-03-06 21:59:10 +01:00
|
|
|
private AlbumID3 album;
|
2020-11-30 20:54:05 +01:00
|
|
|
|
|
|
|
|
public AlbumBottomSheetViewModel(@NonNull Application application) {
|
|
|
|
|
super(application);
|
|
|
|
|
|
2023-03-10 15:21:02 +01:00
|
|
|
albumRepository = new AlbumRepository();
|
|
|
|
|
artistRepository = new ArtistRepository();
|
2020-11-30 20:54:05 +01:00
|
|
|
}
|
|
|
|
|
|
2023-03-06 21:59:10 +01:00
|
|
|
public AlbumID3 getAlbum() {
|
2020-12-01 20:04:54 +01:00
|
|
|
return album;
|
2020-11-30 20:54:05 +01:00
|
|
|
}
|
|
|
|
|
|
2023-03-06 21:59:10 +01:00
|
|
|
public void setAlbum(AlbumID3 album) {
|
2020-12-01 20:04:54 +01:00
|
|
|
this.album = album;
|
2020-11-30 20:54:05 +01:00
|
|
|
}
|
|
|
|
|
|
2023-03-06 21:59:10 +01:00
|
|
|
public LiveData<ArtistID3> getArtist() {
|
2021-07-31 16:37:41 +02:00
|
|
|
return artistRepository.getArtist(album.getArtistId());
|
|
|
|
|
}
|
|
|
|
|
|
2023-03-06 21:59:10 +01:00
|
|
|
public MutableLiveData<List<Child>> getAlbumTracks() {
|
2021-07-31 16:37:41 +02:00
|
|
|
return albumRepository.getAlbumTracks(album.getId());
|
2020-11-30 20:54:05 +01:00
|
|
|
}
|
2021-07-29 16:00:00 +02:00
|
|
|
|
|
|
|
|
public void setFavorite() {
|
2023-03-06 21:59:10 +01:00
|
|
|
if (album.getStarred() != null) {
|
2021-07-29 16:00:00 +02:00
|
|
|
artistRepository.unstar(album.getId());
|
2023-03-06 21:59:10 +01:00
|
|
|
album.setStarred(null);
|
2021-07-29 16:00:00 +02:00
|
|
|
} else {
|
|
|
|
|
artistRepository.star(album.getId());
|
2023-03-06 21:59:10 +01:00
|
|
|
album.setStarred(new Date());
|
2021-07-29 16:00:00 +02:00
|
|
|
}
|
|
|
|
|
}
|
2020-11-30 20:54:05 +01:00
|
|
|
}
|