Created
July 31, 2019 10:33
-
-
Save tmaxxdd/4deb74ae5ce43e542335f1a5a6506812 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
... | |
private Disposable textWatcher; | |
@Override | |
protected void onCreate(Bundle savedInstanceState) { | |
super.onCreate(savedInstanceState); | |
setContentView(R.layout.activity_main); | |
AppCompatEditText input = findViewById(R.id.password); | |
AppCompatTextView message = findViewById(R.id.message); | |
textWatcher = RxTextView.textChanges(input) // Tworzy strumien na podstawie zmian EditText | |
.debounce(300, TimeUnit.MILLISECONDS) // Ogranicza emisje na odstepy co 300 milisekund | |
.map(this::isPasswordValid) // Zamienia wprowadzony tekst na rezultat logiczny | |
.subscribeOn(Schedulers.io()) // Powyzsze operacje wykonuje w tle na watku I/O | |
.observeOn(AndroidSchedulers.mainThread()) // Rezultat jest zwracany do UI | |
.subscribe( // Subskrybcja, ktora przechwytuje emisje czyli (true/false) | |
valid -> { | |
if (valid) { //Haslo zgodne ze schematem | |
message.setText("Haslo jest prawidłowe."); | |
message.setTextColor(Color.GREEN); | |
} else { //Haslo niezgodne ze schematem | |
message.setText("Haslo niezgodne z wymaganiami."); | |
message.setTextColor(Color.RED); | |
} | |
}); | |
} | |
... |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment