Search in sources :

Example 1 with SearchResult

use of com.xinshang.audient.model.entities.SearchResult in project Audient by komamj.

the class SearchPresenter method loadSearchResults.

@Override
public void loadSearchResults(String keyword) {
    LogUtils.i(TAG, "loadSearchResults :" + keyword);
    mDisposables.clear();
    if (isInvalid(keyword)) {
        if (mView.isActive()) {
            mView.showEmpty(true);
        }
        return;
    }
    if (mView != null) {
        mView.showProgressBar(true);
    }
    Disposable disposable = mRepository.getSearchReult(keyword).map(new Function<SearchResult, List<Audient>>() {

        @Override
        public List<Audient> apply(SearchResult searchResult) throws Exception {
            return searchResult.dataBean.audients;
        }
    }).subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).subscribeWith(new DisposableSubscriber<List<Audient>>() {

        @Override
        public void onNext(List<Audient> audients) {
            if (mView.isActive()) {
                mView.showProgressBar(false);
                mView.showAudients(audients);
                mView.showEmpty(audients.isEmpty());
            }
        }

        @Override
        public void onError(Throwable t) {
            LogUtils.e(TAG, "loadSearchResults error :" + t.toString());
            if (mView.isActive()) {
                mView.showProgressBar(false);
                mView.showLoadingError();
            }
        }

        @Override
        public void onComplete() {
        }
    });
    mDisposables.add(disposable);
}
Also used : CompositeDisposable(io.reactivex.disposables.CompositeDisposable) Disposable(io.reactivex.disposables.Disposable) Function(io.reactivex.functions.Function) SearchResult(com.xinshang.audient.model.entities.SearchResult) List(java.util.List) Audient(com.xinshang.audient.model.entities.Audient)

Aggregations

Audient (com.xinshang.audient.model.entities.Audient)1 SearchResult (com.xinshang.audient.model.entities.SearchResult)1 CompositeDisposable (io.reactivex.disposables.CompositeDisposable)1 Disposable (io.reactivex.disposables.Disposable)1 Function (io.reactivex.functions.Function)1 List (java.util.List)1