fix: fixed directory navigation

This commit is contained in:
antonio 2023-07-02 19:23:08 +02:00
parent 803b61430f
commit a9b264004c
6 changed files with 26 additions and 91 deletions

View file

@ -4,9 +4,7 @@ import android.app.Application;
import androidx.annotation.NonNull;
import androidx.lifecycle.AndroidViewModel;
import androidx.lifecycle.LifecycleOwner;
import androidx.lifecycle.LiveData;
import androidx.lifecycle.MutableLiveData;
import com.cappielloantonio.tempo.repository.DirectoryRepository;
import com.cappielloantonio.tempo.subsonic.models.Directory;
@ -14,34 +12,13 @@ import com.cappielloantonio.tempo.subsonic.models.Directory;
public class DirectoryViewModel extends AndroidViewModel {
private final DirectoryRepository directoryRepository;
private MutableLiveData<String> id = new MutableLiveData<>(null);
private MutableLiveData<String> name = new MutableLiveData<>(null);
private MutableLiveData<Directory> directory = new MutableLiveData<>(null);
public DirectoryViewModel(@NonNull Application application) {
super(application);
directoryRepository = new DirectoryRepository();
}
public LiveData<Directory> getDirectory() {
return directory;
}
public void setMusicDirectoryId(String id) {
this.id.setValue(id);
}
public void setMusicDirectoryName(String name) {
this.name.setValue(name);
}
public void loadMusicDirectory(LifecycleOwner owner) {
this.id.observe(owner, id -> directoryRepository.getMusicDirectory(id).observe(owner, directory -> this.directory.setValue(directory)));
}
public void goBack() {
this.id.setValue(this.directory.getValue().getParentId());
public LiveData<Directory> loadMusicDirectory(String id) {
return directoryRepository.getMusicDirectory(id);
}
}