mirror of
https://github.com/antebudimir/tempus.git
synced 2026-01-01 01:53:31 +00:00
35 lines
996 B
Java
35 lines
996 B
Java
|
|
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 {
|
||
|
|
|
||
|
|
private final MutableLiveData<String> currentMediaId = new MutableLiveData<>(null);
|
||
|
|
private final MutableLiveData<Boolean> isPlaying = new MutableLiveData<>(false);
|
||
|
|
|
||
|
|
public LiveData<String> getCurrentMediaId() {
|
||
|
|
return currentMediaId;
|
||
|
|
}
|
||
|
|
|
||
|
|
public LiveData<Boolean> getIsPlaying() {
|
||
|
|
return isPlaying;
|
||
|
|
}
|
||
|
|
|
||
|
|
public void update(String mediaId, boolean playing) {
|
||
|
|
if (!Objects.equals(currentMediaId.getValue(), mediaId)) {
|
||
|
|
currentMediaId.postValue(mediaId);
|
||
|
|
}
|
||
|
|
if (!Objects.equals(isPlaying.getValue(), playing)) {
|
||
|
|
isPlaying.postValue(playing);
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
public void clear() {
|
||
|
|
currentMediaId.postValue(null);
|
||
|
|
isPlaying.postValue(false);
|
||
|
|
}
|
||
|
|
}
|