Skip to content

Commit

Permalink
Coupled value updates with server providing
Browse files Browse the repository at this point in the history
  • Loading branch information
Steppschuh committed Feb 5, 2020
1 parent 47171c0 commit f09caeb
Showing 1 changed file with 12 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ public class ExampleViewModel extends AndroidViewModel {
private RxBleServer bleServer;
private Disposable provideServicesDisposable;
private Disposable advertiseServicesDisposable;
private Disposable updateValueDisposable;

private MutableLiveData<Boolean> isProvidingServices = new MutableLiveData<>();
private MutableLiveData<Boolean> isAdvertisingService = new MutableLiveData<>();
Expand All @@ -34,12 +35,6 @@ public ExampleViewModel(@NonNull Application application) {

exampleProfile = new ExampleProfile(application);
bleServer = exampleProfile.getExampleServer();
viewModelDisposable.add(exampleProfile.updateCharacteristicValues()
.subscribeOn(Schedulers.io())
.subscribe(
() -> Timber.d("Done updating characteristic values"),
this::postError
));

isProvidingServices.setValue(false);
isAdvertisingService.setValue(false);
Expand Down Expand Up @@ -79,14 +74,25 @@ private void startProvidingServices() {
this::postError
);

updateValueDisposable = exampleProfile.updateCharacteristicValues()
.subscribeOn(Schedulers.io())
.subscribe(
() -> Timber.d("Done updating characteristic values"),
this::postError
);

viewModelDisposable.add(provideServicesDisposable);
viewModelDisposable.add(updateValueDisposable);
}

private void stopProvidingServices() {
Timber.d("Stopping to provide services");
if (provideServicesDisposable != null && !provideServicesDisposable.isDisposed()) {
provideServicesDisposable.dispose();
}
if (updateValueDisposable != null && !updateValueDisposable.isDisposed()) {
updateValueDisposable.dispose();
}
}

/*
Expand Down

0 comments on commit f09caeb

Please sign in to comment.