2025-09-22 19:28:01 +02:00
|
|
|
package com.cappielloantonio.tempo.viewmodel;
|
|
|
|
|
|
|
|
|
|
import androidx.lifecycle.LiveData;
|
|
|
|
|
import androidx.lifecycle.MutableLiveData;
|
|
|
|
|
import androidx.lifecycle.ViewModel;
|
|
|
|
|
|
|
|
|
|
import java.util.Objects;
|
|
|
|
|
|
|
|
|
|
public class PlaybackViewModel extends ViewModel {
|
|
|
|
|
|
2025-09-22 20:03:02 +02:00
|
|
|
private final MutableLiveData<String> currentSongId = new MutableLiveData<>(null);
|
2025-09-22 19:28:01 +02:00
|
|
|
private final MutableLiveData<Boolean> isPlaying = new MutableLiveData<>(false);
|
|
|
|
|
|
2025-09-22 20:03:02 +02:00
|
|
|
public LiveData<String> getCurrentSongId() {
|
|
|
|
|
return currentSongId;
|
2025-09-22 19:28:01 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public LiveData<Boolean> getIsPlaying() {
|
|
|
|
|
return isPlaying;
|
|
|
|
|
}
|
|
|
|
|
|
2025-09-22 20:03:02 +02:00
|
|
|
public void update(String songId, boolean playing) {
|
|
|
|
|
if (!Objects.equals(currentSongId.getValue(), songId)) {
|
|
|
|
|
currentSongId.postValue(songId);
|
2025-09-22 19:28:01 +02:00
|
|
|
}
|
|
|
|
|
if (!Objects.equals(isPlaying.getValue(), playing)) {
|
|
|
|
|
isPlaying.postValue(playing);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void clear() {
|
2025-09-22 20:03:02 +02:00
|
|
|
currentSongId.postValue(null);
|
2025-09-22 19:28:01 +02:00
|
|
|
isPlaying.postValue(false);
|
|
|
|
|
}
|
|
|
|
|
}
|