Created
January 4, 2017 04:46
-
-
Save rohmanhakim/afd542e0775965f2580b3e27c2606f15 to your computer and use it in GitHub Desktop.
This file contains 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 | |
public Boolean call(String input) { | |
return input.length() > 3; | |
} | |
}) | |
.debounce(100,TimeUnit.MILLISECONDS) | |
.flatMap(new Func1<String, Observable<Boolean>>() { | |
@Override | |
public Observable<Boolean> call(String input) { | |
return checkIfEmailExistFromAPI(input); | |
} | |
}); | |
// 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 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment