Skip to content

Instantly share code, notes, and snippets.

@rahulmmohan
Created March 16, 2017 11:09

Revisions

  1. rahulmmohan created this gist Mar 16, 2017.
    45 changes: 45 additions & 0 deletions MainActivity.java
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,45 @@
    isUsernameValid.distinctUntilChanged().doOnNext(new Consumer<Boolean>() {
    @Override
    public void accept(Boolean valid) throws Exception {
    Log.d(TAG, "Username " + (valid ? "Valid" : "Invalid"));
    }
    }).map(new Function<Boolean, Integer>() {

    @Override
    public Integer apply(Boolean valid) throws Exception {
    return valid?Color.WHITE:Color.RED;
    }
    }).subscribe(new Consumer<Integer>() {

    @Override
    public void accept(Integer color) throws Exception {
    mUsernameEditText.setTextColor(color);
    }
    });

    isEmailValid.distinctUntilChanged().doOnNext(new Consumer<Boolean>() {
    @Override
    public void accept(Boolean valid) throws Exception {
    Log.d(TAG, "Email " + (valid ? "Valid" : "Invalid"));
    }
    }).map(new Function<Boolean, Integer>() {

    @Override
    public Integer apply(Boolean valid) throws Exception {
    return valid?Color.WHITE:Color.RED;
    }
    }).subscribe(new Consumer<Integer>() {

    @Override
    public void accept(Integer color) throws Exception {
    mEmailEditText.setTextColor(color);
    }
    });

    registerButtonObservable.distinctUntilChanged().subscribe(new Consumer<Boolean>() {
    @Override
    public void accept(Boolean aBoolean) throws Exception {
    mRegisterButton.setEnabled(aBoolean);
    }

    });