mirror of
https://github.com/antebudimir/tempus.git
synced 2025-12-31 17:43:32 +00:00
feat: Add play/pause button in song lists
This commit is contained in:
parent
905bb3e3c5
commit
5ab68e4a98
14 changed files with 555 additions and 135 deletions
|
|
@ -0,0 +1,38 @@
|
|||
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);
|
||||
|
||||
// (Optional) expose position or other info
|
||||
// private final MutableLiveData<Long> positionMs = new MutableLiveData<>(0L);
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue