I am trying to use .distinctUntilChanged() and its not passing value to switchmap() after first time.
RxTextView.textChanges(etUserQuery).debounce(300, TimeUnit.MILLISECONDS)
.observeOn(AndroidSchedulers.mainThread()).filter(charSequence -> {
if (charSequence.toString().isEmpty()) {
etUserQuery.setHint("Please type username");
return false;
} else
return true;
}).distinctUntilChanged()
.switchMap(charSequence -> vm.dataFromNetwork(charSequence.toString()))
.subscribe(fetchUserResponce -> {
noDataText.setVisibility(fetchUserResponce.getItems().size() == 0 ? View.VISIBLE : View.GONE);
mUsersListAdapter.updateData(fetchUserResponce.getItems());
}));
Is it correct place to use .distinctUntilChanged()?
From the comments:
The CharSequence the textChanges gives you is mutable and should be turned into String before it is passed along.
textChanges gives you the same CharSequence reference and distinctUntilChange relying on Object.equals() will find it equal to itself all the time.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With