2
我想實現一個Rx搜索視圖,該視圖將使用該字符串過濾回收視圖並檢查本地Realm數據庫並作出改進請求,然後結合所有結果而不重複?換句話說:我想在搜索視圖中使用輸入字符串進行網絡請求,使用數據庫查詢並結合結果而不重複如何創建一個Rx搜索視圖,該視圖將用查詢過濾回收站視圖
這是我的初始代碼:
RxSearchView.queryTextChanges(searchView)
.filter(charSequence -> !TextUtils.isEmpty(charSequence))
.throttleLast(100, TimeUnit.MILLISECONDS)
.debounce(200, TimeUnit.MILLISECONDS)
.onBackpressureLatest()
.flatMap(charSequence -> userListPresenter.search(charSequence))
.observeOn(AndroidSchedulers.mainThread())
.subscribeOn(Schedulers.io())
.onErrorResumeNext(Observable.empty())
.subscribe((Action1) response -> userListPresenter.showSearchResult((List<UserModel>) response));
的userListPresenter.search(CharSequence的))應返回可觀察到的沒有重複的級聯反應,謝謝:)
userListPresenter.search(CharSequence中)):
Observable.create(subscriber -> {
if (Utils.isNetworkAvailable(getContext())) {
if (!subscriber.isUnsubscribed()) {
subscriber.onNext(restApi.search(query));
subscriber.onCompleted();
}
}).mergeWith(
Observable.create(subscriber -> {
if (!subscriber.isUnsubscribed()) {
subscriber.onNext(realmManager.getWhere(query));
subscriber.onCompleted();
}
})).collect(HashSet::new, HashSet::add)
.flatMap(Observable::from);