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> invalidFieldsStream = Observable.combineLatest( | |
emailStream, | |
passwordStream, | |
passwordConfirmationStream, | |
emptyFieldStream, new Func4<Boolean, Boolean, Boolean, Boolean, Boolean>() { | |
@Override | |
public Boolean call(Boolean emailInvalid, Boolean passwordInvalid, Boolean passwordConfirmationInvalid, Boolean emptyFieldExist) { | |
return !emailInvalid && !passwordInvalid && !passwordConfirmationInvalid && !emptyFieldExist; | |
} | |
}); |
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
emailStream.subscribe(emailObserver); |
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
// Inisialisasi observer untuk field email | |
// subscribe ke stream email, menampilkan peringatan ketika email yg diketik user sudah dipakai di backend | |
Observer<Boolean> emailObserver = new Observer<Boolean>() { | |
@Override | |
public void onCompleted() { | |
Log.d("rx","Email stream completed"); | |
} | |
@Override | |
public void onError(Throwable e) { |
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 |