public static <T> Observable<T> toObservable(@NonNull final ObservableField<T> field) { return Observable.create(e -> { T initialValue = field.get(); if (initialValue != null) { e.onNext(initialValue); } final OnPropertyChangedCallback callback = new OnPropertyChangedCallback() { @Override public void onPropertyChanged(android.databinding.Observable observable, int i) { e.onNext(field.get()); } }; field.addOnPropertyChangedCallback(callback); e.setCancellable(() -> field.removeOnPropertyChangedCallback(callback)); }); }
public void setEpochCollector(EpochCollector collector) { this.collector = collector; this.collector.addOnPropertyChangedCallback(new OnPropertyChangedCallback() { @Override public void onPropertyChanged(Observable sender, int propertyId) { EpochSurfaceView.this.invalidate(); } } ); }