package com.zcy.ghost.vivideo.presenter;
import android.support.annotation.NonNull;
import com.zcy.ghost.vivideo.base.RxPresenter;
import com.zcy.ghost.vivideo.model.bean.VideoRes;
import com.zcy.ghost.vivideo.model.net.RetrofitHelper;
import com.zcy.ghost.vivideo.model.net.VideoHttpResponse;
import com.zcy.ghost.vivideo.presenter.contract.RecommendContract;
import com.zcy.ghost.vivideo.utils.Preconditions;
import com.zcy.ghost.vivideo.utils.RxUtil;
import com.zcy.ghost.vivideo.utils.StringUtils;
import rx.Subscription;
import rx.functions.Action1;
/**
* Description: RecommendPresenter
* Creator: yxc
* date: 2016/9/21 16:26
*/
public class RecommendPresenter extends RxPresenter implements RecommendContract.Presenter {
RecommendContract.View mView;
int page = 0;
public RecommendPresenter(@NonNull RecommendContract.View oneView) {
mView = Preconditions.checkNotNull(oneView);
mView.setPresenter(this);
}
@Override
public void onRefresh() {
page = 0;
getPageHomeInfo();
}
private void getPageHomeInfo() {
Subscription rxSubscription = RetrofitHelper.getVideoApi().getHomePage()
.compose(RxUtil.<VideoHttpResponse<VideoRes>>rxSchedulerHelper())
.compose(RxUtil.<VideoRes>handleResult())
.subscribe(new Action1<VideoRes>() {
@Override
public void call(final VideoRes res) {
if (res != null) {
if (mView.isActive()) {
mView.showContent(res);
}
}
}
}, new Action1<Throwable>() {
@Override
public void call(Throwable throwable) {
mView.refreshFaild(StringUtils.getErrorMsg(throwable.getMessage()));
}
});
addSubscribe(rxSubscription);
}
}