我的RxBinding2
中有View
,如下所示:
@Override
public Observable<SearchViewQueryTextEvent> searchIntent()
{
return RxSearchView.queryTextChangeEvents(searchView)
.debounce(500, java.util.concurrent.TimeUnit.MILLISECONDS)
.filter(searchViewQueryTextEvent -> searchViewQueryTextEvent.queryText().length() > 2);
}
我想要随后调用的方法如下:
return discogsService.getSearchResults(searchTerm, mContext.getString(R.string.token))
.subscribeOn(Schedulers.io())
.flatMapIterable(RootSearchResponse::getSearchResults)
.observeOn(Schedulers.io())
.flatMap(searchResult ->
{
if (searchResult.getType().equals("release"))
{
Log.e("DiscogsInteractor", "In release");
return discogsService.getRelease(searchResult.getId(), mContext.getString(R.string.token));
}
else if (searchResult.getType().equals("artist"))
{
Log.e("DiscogsInteractor", "In artist");
return discogsService.getArtist(searchResult.getId(), mContext.getString(R.string.token));
}
Log.e("DiscogsInteractor", "EmptyObject");
return new EmptyObject();
});
我想在Presenter
中设置它,以便它会被动地调用方法。当我在Presenter中单独调用下面的内容时,它可以正常工作:
mInteractor.searchDiscogs(searchQuery)
.subscribe(o -> Log.e(TAG, o.toString()));
但是,我正在努力将RxBinding
链接起来,然后使用SearchView
中的输入调用上述方法。这是我尝试过的:
CompositeDisposable disposable = new CompositeDisposable();
disposable.add(mView.searchIntent()
.subscribeWith(new DisposableObserver<SearchViewQueryTextEvent>()
{
@Override
public void onNext(SearchViewQueryTextEvent searchViewQueryTextEvent)
{
mInteractor.searchDiscogs(searchViewQueryTextEvent.toString()).subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).subscribe(new Observer<Object>()
{
@Override
public void onSubscribe(Disposable d)
{
Log.e(TAG, "test"); <--- ObservableObserveOn
}
...
@Override
public void onComplete()
{
Log.e(TAG, "test");
}
});
}
...
onNext()
被正确调用,但当传入searchDiscogs(...)
时,它将执行到.flatMap(...)
的行(但不在其中),然后将ObservableObserveOn
返回到onSubscribe(...)
{1}}。
我错过了什么?
答案 0 :(得分:0)
mInteractor.searchDiscogs(searchViewQueryTextEvent.queryText().toString())
应该是
recolic@RECOLICPC ~/D/b/bin> yaourt -Q google-chrome chromium
local/google-chrome 57.0.2987.110-1
extra/chromium 57.0.2987.110-1
recolic@RECOLICPC ~/D/b/bin> uname -a
Linux RECOLICPC 4.10.4-1-ARCH #1 SMP PREEMPT Sat Mar 18 19:39:18 CET 2017 x86_64 GNU/Linux