Created
September 23, 2019 03:20
-
-
Save li2/68b8523f8711ad3610fff78c6c9a07cf to your computer and use it in GitHub Desktop.
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 query text changes observable. | |
* | |
* - filter: to filter undesired text like blank text to avoid unnecessary API call. | |
* - debounce: to ignore the previous items in the given time and only emit the last one, to avoid too much API calls. | |
* - distinctUntilChanged: to avoid the duplicate API call. | |
*/ | |
fun EditText.queryTextChanges(): Observable<String> { | |
return textChanges() | |
.map { it.toString() } | |
.filter { it.isNotBlank() } | |
.debounce(300, TimeUnit.MILLISECONDS) | |
.distinctUntilChanged() | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment