Created
April 10, 2016 14:23
-
-
Save Orange168/ab5784b27fec8ee8e2614a189c094636 to your computer and use it in GitHub Desktop.
RxDebounceSearch Fragment
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
@Override | |
public void onActivityCreated(@Nullable Bundle savedInstanceState) { | |
super.onActivityCreated(savedInstanceState); | |
_setupLogger(); | |
_subscription = RxTextView.textChangeEvents(_inputSearchText)// | |
.debounce(400, TimeUnit.MILLISECONDS)// default Scheduler is Computation | |
.filter(new Func1<TextViewTextChangeEvent, Boolean>() { | |
@Override | |
public Boolean call(TextViewTextChangeEvent changes) { | |
return CoreNullnessUtils.isNotNullOrEmpty(_inputSearchText.getText().toString()); | |
} | |
}) | |
.observeOn(AndroidSchedulers.mainThread())// | |
.subscribe(_getSearchObserver()); | |
} | |
// ----------------------------------------------------------------------------------- | |
// Main Rx entities | |
private Observer<TextViewTextChangeEvent> _getSearchObserver() { | |
return new Observer<TextViewTextChangeEvent>() { | |
@Override | |
public void onCompleted() { | |
Timber.d("--------- onComplete"); | |
} | |
@Override | |
public void onError(Throwable e) { | |
Timber.e(e, "--------- Woops on error!"); | |
_log("Dang error. check your logs"); | |
} | |
@Override | |
public void onNext(TextViewTextChangeEvent onTextChangeEvent) { | |
_log(format("Searching for %s", onTextChangeEvent.text().toString())); | |
} | |
}; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment