Search in sources :

Example 1 with HomeNewsInfos

use of com.seven.seven.home.model.HomeNewsInfos in project seven_develop by seven123456.

the class HomeFragment method disposeHomeFragmentData.

@Subscribe(threadMode = ThreadMode.MAIN, priority = 0, sticky = true)
public void disposeHomeFragmentData(HomeEvents homeEvents) {
    switch(homeEvents.getWhat()) {
        case Constans.HOMEDATA:
            HomeNewsInfos homeNewsInfos = (HomeNewsInfos) homeEvents.getData();
            newsInfosList = homeNewsInfos.getDatas();
            if (newsInfosList != null) {
                errorLayoutView.hide();
            }
            if (!isRefresh) {
                homeCommonAdapter.setNewData(newsInfosList);
                isRefresh = true;
                homeCommonAdapter.setEnableLoadMore(true);
            } else {
                if (newsInfosList != null) {
                    homeCommonAdapter.addData(newsInfosList);
                } else {
                    homeCommonAdapter.loadMoreEnd(true);
                }
            }
            PAGE_COUNT = homeNewsInfos.getPageCount();
            break;
        case Constans.HOMEBANNER:
            homeBannerInfos = (List<HomeBannerInfos>) homeEvents.getData();
            initRecyclerHeadView(homeBannerInfos);
            if (homeBannerInfos != null) {
                errorLayoutView.hide();
            }
            break;
        case Constans.HOMEERROR:
            showErrorToast((String) homeEvents.getData());
            errorLayoutView.showErrorView();
            break;
        case Constans.HOMEDASUCCESS:
            errorLayoutView.hide();
            break;
    }
    // }
    swipeRefreshLayout.setRefreshing(false);
}
Also used : HomeBannerInfos(com.seven.seven.home.model.HomeBannerInfos) HomeNewsInfos(com.seven.seven.home.model.HomeNewsInfos) Subscribe(org.greenrobot.eventbus.Subscribe)

Example 2 with HomeNewsInfos

use of com.seven.seven.home.model.HomeNewsInfos in project seven_develop by seven123456.

the class HomePresenter method getHomeBanner.

@Override
public void getHomeBanner() {
    /*io.reactivex.Observable observable = HttpObservable.getObservable(apiRetrofit.getHomeNewsInfos());
        io.reactivex.Observable observable1 = HttpObservable.getObservable(apiRetrofit.getBannerInfos());
        io.reactivex.Observable.mergeDelayError(observable, observable1).retryWhen(new BaseRetryWhen(3, 3000))
        .subscribe(new HttpResultObserver<ResponseCustom<Object>>() {
            @Override
            protected void onLoading(Disposable d) {

            }

            @Override
            protected void onSuccess(ResponseCustom<Object> responseCustom) {
                if (getView() != null) {
                    if (responseCustom.getData() != null) {
                        count++;
                    }
                    if (responseCustom.getData() instanceof HomeNewsInfos) {
                        EventBus.getDefault().post(new HomeEvents(Constans.HOMEDATA, responseCustom.getData()));
                    } else if (responseCustom.getData() instanceof List) {
                        EventBus.getDefault().post(new HomeEvents(Constans.HOMEBANNER, responseCustom.getData()));
                    }
                    if (count == 2) {
                        count = 0;
                        EventBus.getDefault().post(new HomeEvents(Constans.HOMEDASUCCESS, "成功"));
                    } */
    /*else {
                        EventBus.getDefault().post(new HomeEvents(Constans.HOMEERROR, "只有一次"));
                    }*/
    /*
                }
            }

            @Override
            protected void onFail(ApiException error) {
                EventBus.getDefault().post(new HomeEvents(Constans.HOMEERROR, error.getMsg()));
            }
        });*/
    Flowable flowable1 = apiRetrofit.getHomeNewsInfos();
    Flowable flowable2 = apiRetrofit.getBannerInfos();
    Flowable.concat(flowable1, flowable2).subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).subscribeWith(new HttpResultSubscriber<ResponseCustom<Object>>() {

        @Override
        protected void onLoading(Disposable d) {
            if (getView() != null) {
            }
        }

        @Override
        protected void onSuccess(ResponseCustom<Object> responseCustom) {
            if (getView() != null) {
                if (responseCustom.getData() != null) {
                    count++;
                }
                if (responseCustom.getData() instanceof HomeNewsInfos) {
                    EventBus.getDefault().post(new HomeEvents(Constans.HOMEDATA, responseCustom.getData()));
                } else if (responseCustom.getData() instanceof List) {
                    EventBus.getDefault().post(new HomeEvents(Constans.HOMEBANNER, responseCustom.getData()));
                }
                if (count == 2) {
                    count = 0;
                    EventBus.getDefault().post(new HomeEvents(Constans.HOMEDASUCCESS, "成功"));
                }
            }
        }

        @Override
        protected void onFail(ApiException e) {
            EventBus.getDefault().post(new HomeEvents(Constans.HOMEERROR, e.getMsg()));
        }
    });
}
Also used : Disposable(io.reactivex.disposables.Disposable) HomeNewsInfos(com.seven.seven.home.model.HomeNewsInfos) List(java.util.List) ResponseCustom(com.seven.seven.common.network.ResponseCustom) HomeEvents(com.seven.seven.home.events.HomeEvents) Flowable(io.reactivex.Flowable) ApiException(com.seven.seven.common.network.ApiException)

Aggregations

HomeNewsInfos (com.seven.seven.home.model.HomeNewsInfos)2 ApiException (com.seven.seven.common.network.ApiException)1 ResponseCustom (com.seven.seven.common.network.ResponseCustom)1 HomeEvents (com.seven.seven.home.events.HomeEvents)1 HomeBannerInfos (com.seven.seven.home.model.HomeBannerInfos)1 Flowable (io.reactivex.Flowable)1 Disposable (io.reactivex.disposables.Disposable)1 List (java.util.List)1 Subscribe (org.greenrobot.eventbus.Subscribe)1