Skip to content

Instantly share code, notes, and snippets.

@radzio
Created September 7, 2016 12:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save radzio/ae45b91db1956d8ae9f6a82b873c16bf to your computer and use it in GitHub Desktop.
Save radzio/ae45b91db1956d8ae9f6a82b873c16bf to your computer and use it in GitHub Desktop.
public static class MainViewModel {
public ObservableField<String> firstName = new ObservableField<>();
public ObservableField<String> lastName = new ObservableField<>();
public ObservableField<String> helloText = new ObservableField<>();
public ObservableBoolean helloButtonEnabled = new ObservableBoolean(false);
public MainViewModel() {
Observable.combineLatest(toObservable(firstName), toObservable(lastName), (firstName, lastName) -> StringUtils.isNotNullOrEmpty(firstName) && StringUtils.isNotNullOrEmpty(lastName))
.subscribe(result -> {
helloButtonEnabled.set(result);
if (!result) {
helloText.set(StringUtils.EMPTY);
}
}, Throwable::printStackTrace);
}
public void buttonClicked() {
helloText.set(String.format("Hello %s %s !", firstName.get(), lastName.get()));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment