Reputation: 749
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()
?
Upvotes: 2
Views: 2999
Reputation: 69997
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.
Upvotes: 10