tempus/app/src/main/java/com/cappielloantonio/play/viewmodel/PlayerBottomSheetViewModel.java

86 lines
2.7 KiB
Java
Raw Normal View History

2020-12-05 21:31:12 +01:00
package com.cappielloantonio.play.viewmodel;
import android.app.Application;
import android.content.Context;
2020-12-05 21:31:12 +01:00
import androidx.annotation.NonNull;
import androidx.lifecycle.AndroidViewModel;
import androidx.lifecycle.LifecycleOwner;
2020-12-05 21:31:12 +01:00
import androidx.lifecycle.LiveData;
import androidx.lifecycle.MutableLiveData;
2020-12-05 21:31:12 +01:00
import com.cappielloantonio.play.model.Artist;
2021-07-28 15:28:32 +02:00
import com.cappielloantonio.play.model.Queue;
2020-12-05 21:31:12 +01:00
import com.cappielloantonio.play.model.Song;
import com.cappielloantonio.play.repository.ArtistRepository;
2020-12-05 21:31:12 +01:00
import com.cappielloantonio.play.repository.QueueRepository;
2020-12-08 11:12:44 +01:00
import com.cappielloantonio.play.repository.SongRepository;
import com.cappielloantonio.play.util.PreferenceUtil;
2020-12-05 21:31:12 +01:00
import java.util.List;
public class PlayerBottomSheetViewModel extends AndroidViewModel {
2020-12-08 11:12:44 +01:00
private static final String TAG = "PlayerBottomSheetViewModel";
2021-04-19 14:44:30 +02:00
2021-09-02 14:12:13 +02:00
private final SongRepository songRepository;
private final ArtistRepository artistRepository;
2021-09-02 14:12:13 +02:00
private final QueueRepository queueRepository;
2020-12-05 21:31:12 +01:00
private final MutableLiveData<String> lyricsLiveData = new MutableLiveData<>(null);
private final MutableLiveData<Song> songLiveData = new MutableLiveData<>(null);
2020-12-05 21:31:12 +01:00
public PlayerBottomSheetViewModel(@NonNull Application application) {
super(application);
2020-12-08 11:12:44 +01:00
songRepository = new SongRepository(application);
artistRepository = new ArtistRepository(application);
2020-12-05 21:31:12 +01:00
queueRepository = new QueueRepository(application);
}
2021-07-28 15:28:32 +02:00
public LiveData<List<Queue>> getQueueSong() {
return queueRepository.getLiveQueue();
2020-12-05 21:31:12 +01:00
}
public Song getCurrentSong() {
// return MusicPlayerRemote.getCurrentSong();
return null;
}
public void setFavorite(Context context) {
Song song = getCurrentSong();
2021-09-02 14:12:13 +02:00
if (song != null) {
if (song.isFavorite()) {
songRepository.unstar(song.getId());
song.setFavorite(false);
} else {
songRepository.star(song.getId());
song.setFavorite(true);
if (PreferenceUtil.getInstance(context).isStarredSyncEnabled()) {
// DownloadUtil.getDownloadTracker(context).download(Collections.singletonList(song), null, null);
}
2021-09-02 14:12:13 +02:00
}
}
2020-12-08 11:12:44 +01:00
}
2020-12-05 21:31:12 +01:00
public LiveData<Artist> getArtist() {
Song song = getCurrentSong();
return artistRepository.getArtist(song.getArtistId());
}
public LiveData<Song> getLiveSong() {
return songLiveData;
}
public LiveData<String> getLiveLyrics() {
return lyricsLiveData;
}
public void refreshSongInfo(LifecycleOwner owner, Song song) {
songLiveData.postValue(song);
songRepository.getSongLyrics(song).observe(owner, lyricsLiveData::postValue);
}
2020-12-05 21:31:12 +01:00
}