2020-12-05 21:31:12 +01:00
|
|
|
package com.cappielloantonio.play.viewmodel;
|
|
|
|
|
|
|
|
|
|
import android.app.Application;
|
|
|
|
|
|
|
|
|
|
import androidx.annotation.NonNull;
|
|
|
|
|
import androidx.lifecycle.AndroidViewModel;
|
|
|
|
|
import androidx.lifecycle.LiveData;
|
|
|
|
|
|
2021-04-27 10:44:55 +02:00
|
|
|
import com.cappielloantonio.play.service.MusicPlayerRemote;
|
2020-12-05 21:31:12 +01:00
|
|
|
import com.cappielloantonio.play.model.Song;
|
|
|
|
|
import com.cappielloantonio.play.repository.QueueRepository;
|
2020-12-08 11:12:44 +01:00
|
|
|
import com.cappielloantonio.play.repository.SongRepository;
|
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
|
|
|
|
2020-12-08 11:12:44 +01:00
|
|
|
private SongRepository songRepository;
|
2020-12-05 21:31:12 +01:00
|
|
|
private QueueRepository queueRepository;
|
|
|
|
|
|
|
|
|
|
private LiveData<List<Song>> queueSong;
|
|
|
|
|
|
|
|
|
|
public PlayerBottomSheetViewModel(@NonNull Application application) {
|
|
|
|
|
super(application);
|
|
|
|
|
|
2020-12-08 11:12:44 +01:00
|
|
|
songRepository = new SongRepository(application);
|
2020-12-05 21:31:12 +01:00
|
|
|
queueRepository = new QueueRepository(application);
|
|
|
|
|
|
|
|
|
|
queueSong = queueRepository.getLiveQueue();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public LiveData<List<Song>> getQueueSong() {
|
|
|
|
|
return queueSong;
|
|
|
|
|
}
|
|
|
|
|
|
2020-12-08 11:12:44 +01:00
|
|
|
public void setFavorite() {
|
2021-04-19 14:44:30 +02:00
|
|
|
Song song = MusicPlayerRemote.getCurrentSong();
|
2021-04-13 18:13:22 +02:00
|
|
|
song.setFavorite(!song.isFavorite());
|
2020-12-08 11:12:44 +01:00
|
|
|
songRepository.setFavoriteStatus(song);
|
|
|
|
|
}
|
2020-12-05 21:31:12 +01:00
|
|
|
|
2021-04-16 18:00:19 +02:00
|
|
|
public void orderSongAfterSwap(List<Song> songs) {
|
|
|
|
|
queueRepository.insertAllAndStartNew(songs);
|
|
|
|
|
}
|
|
|
|
|
|
2021-04-16 10:08:31 +02:00
|
|
|
public void removeSong(int position) {
|
|
|
|
|
queueRepository.deleteByPosition(position);
|
|
|
|
|
}
|
2020-12-05 21:31:12 +01:00
|
|
|
}
|