2020-12-01 20:04:54 +01:00
|
|
|
package com.cappielloantonio.play.viewmodel;
|
|
|
|
|
|
|
|
|
|
import android.app.Application;
|
|
|
|
|
|
|
|
|
|
import androidx.annotation.NonNull;
|
|
|
|
|
import androidx.lifecycle.AndroidViewModel;
|
|
|
|
|
|
2021-07-29 16:00:00 +02:00
|
|
|
import com.cappielloantonio.play.repository.AlbumRepository;
|
2023-03-06 21:59:10 +01:00
|
|
|
import com.cappielloantonio.play.subsonic.models.ArtistID3;
|
|
|
|
|
|
|
|
|
|
import java.util.Date;
|
2020-12-01 20:04:54 +01:00
|
|
|
|
|
|
|
|
public class ArtistBottomSheetViewModel extends AndroidViewModel {
|
2021-09-02 14:12:13 +02:00
|
|
|
private final AlbumRepository albumRepository;
|
2021-07-29 16:00:00 +02:00
|
|
|
|
2023-03-06 21:59:10 +01:00
|
|
|
private ArtistID3 artist;
|
2020-12-01 20:04:54 +01:00
|
|
|
|
|
|
|
|
public ArtistBottomSheetViewModel(@NonNull Application application) {
|
|
|
|
|
super(application);
|
2021-07-29 16:00:00 +02:00
|
|
|
|
|
|
|
|
albumRepository = new AlbumRepository(application);
|
2020-12-01 20:04:54 +01:00
|
|
|
}
|
|
|
|
|
|
2023-03-06 21:59:10 +01:00
|
|
|
public ArtistID3 getArtist() {
|
2020-12-01 20:04:54 +01:00
|
|
|
return artist;
|
|
|
|
|
}
|
2021-04-27 11:01:02 +02:00
|
|
|
|
2023-03-06 21:59:10 +01:00
|
|
|
public void setArtist(ArtistID3 artist) {
|
2021-04-27 11:01:02 +02:00
|
|
|
this.artist = artist;
|
|
|
|
|
}
|
2021-07-29 16:00:00 +02:00
|
|
|
|
|
|
|
|
public void setFavorite() {
|
2023-03-06 21:59:10 +01:00
|
|
|
if (artist.getStarred() != null) {
|
2021-07-29 16:00:00 +02:00
|
|
|
albumRepository.unstar(artist.getId());
|
2023-03-06 21:59:10 +01:00
|
|
|
artist.setStarred(null);
|
2021-07-29 16:00:00 +02:00
|
|
|
} else {
|
|
|
|
|
albumRepository.star(artist.getId());
|
2023-03-06 21:59:10 +01:00
|
|
|
artist.setStarred(new Date());
|
2021-07-29 16:00:00 +02:00
|
|
|
}
|
|
|
|
|
}
|
2020-12-01 20:04:54 +01:00
|
|
|
}
|