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-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.QueueRepository;
|
2020-12-08 11:12:44 +01:00
|
|
|
import com.cappielloantonio.play.repository.SongRepository;
|
2021-04-27 11:01:02 +02:00
|
|
|
import com.cappielloantonio.play.service.MusicPlayerRemote;
|
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;
|
|
|
|
|
|
2021-07-28 15:28:32 +02:00
|
|
|
private LiveData<List<Queue>> queueSong;
|
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);
|
2020-12-05 21:31:12 +01:00
|
|
|
queueRepository = new QueueRepository(application);
|
|
|
|
|
|
|
|
|
|
queueSong = queueRepository.getLiveQueue();
|
|
|
|
|
}
|
|
|
|
|
|
2021-07-28 15:28:32 +02:00
|
|
|
public LiveData<List<Queue>> getQueueSong() {
|
2020-12-05 21:31:12 +01:00
|
|
|
return queueSong;
|
|
|
|
|
}
|
|
|
|
|
|
2021-08-13 17:29:37 +02:00
|
|
|
public Song getCurrentSong() {
|
|
|
|
|
return MusicPlayerRemote.getCurrentSong();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2020-12-08 11:12:44 +01:00
|
|
|
public void setFavorite() {
|
2021-04-19 14:44:30 +02:00
|
|
|
Song song = MusicPlayerRemote.getCurrentSong();
|
2021-07-29 17:14:57 +02:00
|
|
|
|
|
|
|
|
if (song.isFavorite()) {
|
|
|
|
|
songRepository.unstar(song.getId());
|
|
|
|
|
song.setFavorite(false);
|
|
|
|
|
} else {
|
|
|
|
|
songRepository.star(song.getId());
|
|
|
|
|
song.setFavorite(true);
|
|
|
|
|
}
|
2020-12-08 11:12:44 +01:00
|
|
|
}
|
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
|
|
|
}
|