I am using RxBinding in my current Android application and wish to implement a text search feature.
My code is as follows:-
compositeDisposable.add(RxTextView.textChangeEvents(searchEditText)
.skipInitialValue()
.subscribeOn(Schedulers.io())
.debounce(200, TimeUnit.MILLISECONDS)
.filter(textViewTextChangeEvent -> (textViewTextChangeEvent.text().length() == 0 || textViewTextChangeEvent.text().length() > 2))
.map(event -> event.text().toString())
.distinct()
.observeOn(AndroidSchedulers.mainThread())
.subscribe(charactersResponse -> {
articlesLiveData = viewModel.textSearch(charactersResponse);
textLiveData.removeObserver(TextFragment.this);
textLiveData.observe(TextFragment.this, TextFragment.this);
}));
I want to only search for distinct values, however the code above makes duplicate search requests.
Why isn't distinct removing duplicate strings?
For example when I type "chilean" into my Search EditText
my search code is called with the following strings
chi
chi
chil
chil
chil
chile
chile
chilea
chilean
chilean
What am I doing wrong?