This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package com.rohmanhakim.androidreactivedemo; | |
| import android.support.v7.app.AppCompatActivity; | |
| import android.os.Bundle; | |
| import android.text.TextUtils; | |
| import android.util.Log; | |
| import android.view.View; | |
| import android.widget.Button; | |
| import android.widget.EditText; | |
| import android.widget.TextView; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Observable<Boolean> emptyFieldStream = Observable.combineLatest( | |
| RxTextView.textChanges(etEmail) | |
| .map(new Func1<CharSequence, Boolean>() { | |
| @Override | |
| public Boolean call(CharSequence charSequence) { | |
| return TextUtils.isEmpty(charSequence); | |
| } | |
| }), | |
| RxTextView.textChanges(etPassword) | |
| .map(new Func1<CharSequence, Boolean>() { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Observable<Boolean> passwordConfirmationStream = Observable.merge( | |
| RxTextView.textChanges(etPassword) | |
| .map(new Func1<CharSequence, Boolean>() { | |
| @Override | |
| public Boolean call(CharSequence charSequence) { | |
| return !charSequence.toString().trim().equals(etPasswordConfirmation.getText().toString()); | |
| } | |
| }), | |
| RxTextView.textChanges(etPasswordConfirmation) | |
| .map(new Func1<CharSequence, Boolean>() { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Return true jika password yang diketik user < 6 karakter | |
| Observable<Boolean> passwordStream = RxTextView.textChanges(etPassword) | |
| .map(new Func1<CharSequence, Boolean>() { | |
| @Override | |
| public Boolean call(CharSequence charSequence) { | |
| return !TextUtils.isEmpty(charSequence) | |
| && charSequence.toString().trim().length() < 6; | |
| } | |
| }); | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public void showEmailExistAlert(boolean value){ | |
| if(value) { | |
| textEmailAlert.setText(getString(R.string.email_exist_alert)); | |
| textEmailAlert.setVisibility(View.VISIBLE); | |
| } else { | |
| textEmailAlert.setVisibility(View.GONE); | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Return true jika email user sudah terpakai | |
| Observable<Boolean> emailStream = RxTextView.textChanges(etEmail) | |
| .map(new Func1<CharSequence, String>() { | |
| @Override | |
| public String call(CharSequence charSequence) { | |
| return charSequence.toString(); | |
| } | |
| }) | |
| .filter(new Func1<String, Boolean>() { | |
| @Override |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Ambil daftar email dari APi, kemudian cek apakah email user sudah dipakai | |
| public Observable<Boolean> checkIfEmailExistFromAPI(final String input){ | |
| return service.getEmails() | |
| .flatMap(new Func1<List<String>, Observable<String>>() { // Mengubah stream of List<String> menjadi stream of String | |
| @Override | |
| public Observable<String> call(List<String> strings) { | |
| return Observable.from(strings); | |
| } | |
| }).contains(input); // Cek apakah email di emit oleh stream sebelumnya | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Return true jika email user sudah terpakai | |
| Observable<Boolean> emailStream = RxTextView.textChanges(etEmail) | |
| .map(new Func1<CharSequence, String>() { | |
| @Override | |
| public String call(CharSequence charSequence) { | |
| return charSequence.toString(); | |
| } | |
| }) | |
| .filter(new Func1<String, Boolean>() { | |
| @Override |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package com.rohmanhakim.androidreactivedemo; | |
| import android.support.v7.app.AppCompatActivity; | |
| import android.os.Bundle; | |
| import android.text.Editable; | |
| import android.text.TextWatcher; | |
| import android.util.Log; | |
| import android.view.View; | |
| import android.widget.Button; | |
| import android.widget.EditText; |