feat: Add play/pause button in song lists

This commit is contained in:
Jaime García 2025-09-22 19:28:01 +02:00
parent 905bb3e3c5
commit 5ab68e4a98
No known key found for this signature in database
GPG key ID: BC4E5F71A71BDA5B
14 changed files with 555 additions and 135 deletions

View file

@ -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);
}
}