ITrendsDetailPresenterImpl.java 8.3 KB
Newer Older
konghaorui committed
1 2 3
package com.yidianling.dynamic.trendsDetail;


YKai committed
4
import androidx.appcompat.app.AppCompatActivity;
konghaorui committed
5 6 7 8 9 10

import com.ydl.ydlcommon.data.http.BaseAPIResponse;
import com.ydl.ydlcommon.data.http.BaseResponse;
import com.ydl.ydlcommon.mvp.base.SimplePresenter;
import com.ydl.ydlcommon.utils.UserInfoCache;
import com.yidianling.common.tools.LogUtil;
11
import com.yidianling.dynamic.bean.DynamicConstants;
konghaorui committed
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246
import com.yidianling.dynamic.common.net.DynamicApiUtils;
import com.yidianling.dynamic.model.CommentBean;
import com.yidianling.dynamic.model.ExpertBuild;
import com.yidianling.dynamic.model.Focus;
import com.yidianling.dynamic.model.Reply;
import com.yidianling.dynamic.model.TrendsDetailInfoBean;
import com.yidianling.dynamic.model.ZanResult;
import com.yidianling.dynamic.router.DynamicIn;

import java.util.List;

/**
 * Created by Jim on 2017/10/10 0010.
 */

public class ITrendsDetailPresenterImpl extends SimplePresenter<ITrendsDetailView> implements ITrendsDetailPresenter, ITrendsDetailPresenter.OnTrendsDetailDataLoadFinishedListenner {

    private TrendsDetailInteractor mTrendsDetailInteractor;

    public ITrendsDetailPresenterImpl() {
        mTrendsDetailInteractor = new TrendsDetailInteractor();
        mTrendsDetailInteractor.setCallBack(this);
    }

    public void fetchTrendsDetails(int id) {
        if (mView != null) {
            mView.showLoadingView("");
        }
        mTrendsDetailInteractor.fetchTrendsDetails(id);
    }


    public void fetchCommentsDatas(int id, int page, int lastId, int direction) {
        mTrendsDetailInteractor.fetchCommentsDatas(id, page, lastId, direction);
    }

    public void fetchCommentsDatas(int page) {
        mTrendsDetailInteractor.fetchCommentsDatas(page);
    }

    /**
     * 点赞
     */
    public void doLikeAction(int type, int id) {
        mTrendsDetailInteractor.doLikeAction(type, id);
    }


    public void focus(String uid) {
        if (mView != null) {
            mView.showLoadingView("");
        }
        mTrendsDetailInteractor.focus(uid);
    }

    /**
     * //获取举报的内容列表
     */
    public void fetchReportReasonContent(int answerId, String commentContent) {
        if (mView != null) {
            mView.showLoadingView("");
        }
        mTrendsDetailInteractor.fetchReportReasonContent(answerId, commentContent);
    }


    //举报帖子评论
    public void report(int trendId, int type, int reasonId, int answerId, String answerContent) {
        if (mView != null) {
            mView.showLoadingView("");
        }
        mTrendsDetailInteractor.report(trendId, type, reasonId, answerId, answerContent);
    }


    /**
     * //删除帖子或评论
     *
     * @param type 移除类型:1移除评论,2移除动态
     * @param id   评论的id,动态id
     */
    public void delTrendsReply(int type, int id, int position) {
        if (mView != null) {
            mView.showLoadingView("");
        }
        mTrendsDetailInteractor.delTrendsReply(type, id, position);
    }

    public void getExpert(AppCompatActivity activity, String expertUid) {
        mTrendsDetailInteractor.getExpert(activity, expertUid);
    }

    public void commitOrReply(int type, String tid, String content, String replyContent, String toName) {
        if (mView != null) {
            mView.showLoadingView("");
        }
        mTrendsDetailInteractor.commitOrReply(type, tid, content, replyContent, toName);
    }

    @Override
    public void onTrendsDetailFetched(BaseAPIResponse<TrendsDetailInfoBean> trendsDetailInfoBean) {
        mView.hideRefreshProgress();
        mView.hideLoadingView();
        if ("200".equals(trendsDetailInfoBean.code)) {
            mView.showTrendsBodyContent(trendsDetailInfoBean.data.active);
            mView.showZanList(trendsDetailInfoBean.data.members);
            mView.showAds(trendsDetailInfoBean.data.adsData);
//            mView.showCommentsList(trendsDetailInfoBean.data.comments);
        } else if ("-300011".equals(trendsDetailInfoBean.code)) {  //帖子被删除
            mView.showTrendsNotExsitView();
        } else {
            mView.showToast(trendsDetailInfoBean.msg);
        }
    }

    @Override
    public void onTrendsDetailFetchFailed(Throwable e) {
        LogUtil.i("onTrendsDetailFetchFailed: " + e);
        mView.hideRefreshProgress();
        mView.hideLoadingView();
        mView.showTrendsLoadErrorView();
        DynamicApiUtils.handleError((TrendsDetailActivity) mView, e);
    }

    @Override
    public void onCommentsListFetched(List<CommentBean> commentsBean) {
        mView.hideRefreshProgress();
        mView.hideLoadingView();
        mView.showCommentsList(commentsBean);
    }

    @Override
    public void onCommentsListFetchedFailed(Throwable e) {
        LogUtil.i("onCommentsListFetchedFailed: " + e);
        mView.hideRefreshProgress();
        mView.showCommentsLoadError();
        DynamicApiUtils.handleError((TrendsDetailActivity) mView, e);
    }

    @Override
    public void ondoLikeActionFetchedResult(BaseResponse<ZanResult> zanResultBaseBean, int type) {
        mView.hideLoadingView();
        if (zanResultBaseBean.code == 0) {
            if (type == 2) {       //帖子点赞
                switch (zanResultBaseBean.data.status) {
                    case 1:         //已赞
                        LogUtil.d("like state 2");
                        mView.showLikedView();
                        break;
                    case 2:     //未赞
                        LogUtil.d("like state 2");
                        mView.showUnLikeView();
                        break;
                }
            } else if (type == 3) {     //动态回复点赞
                mView.showCommentsItemLikeStatus(zanResultBaseBean.data.status);
            }
        } else {
            mView.showToast(zanResultBaseBean.msg);
        }
    }

    @Override
    public void onFoucusActionSuccessed(BaseResponse<Focus> response) {
        if (response.code == 0) {
            mView.hideLoadingView();
            mView.showFousChangeView();
        } else {
            mView.hideLoadingView();
            mView.showToast(response.msg);
        }

    }

    @Override
    public void onReportContentFetched(BaseResponse response, int answerId, String commentContent) {
        if (response.code == 0) {
            mView.hideLoadingView();
            mView.showReportContentView(response, answerId, commentContent);
        } else {
            mView.showToast(response.msg);
        }
    }

    @Override
    public void onReportSuccessed(BaseResponse<Object> response) {
        mView.hideLoadingView();
        if (response.code == 0) {
            mView.showToast("举报信息已提交 谢谢");
        } else {
            mView.showToast(response.msg);
        }
    }

    @Override
    public void onGetExpertSuccesssed(BaseResponse<ExpertBuild> response) {
        if (response.code == 0 || response.code == 200) {
            ExpertBuild expert = response.data;
            UserInfoCache.getInstance().saveYDLUser(expert.shareData.toUid, expert.shareData.name, expert.shareData.cover);
            DynamicIn.INSTANCE.startChat((AppCompatActivity) mView, expert.shareData.toUid);
        } else {
            mView.showToast(response.msg);
        }
    }

    @Override
    public void onCommentOrReplySuccessed(BaseResponse<Reply> replyBaseResponse, int type, String content, String replyContent, String toName) {
        mView.hideLoadingView();
        if (replyBaseResponse.code == 0) {
            mView.refreshCommentListAfterComment(replyBaseResponse, type, content, replyContent, toName);
        } else if (replyBaseResponse.code == DynamicConstants.SILENCED_CODE) {
            mView.showSilencedDialog(replyBaseResponse.data.tips, replyBaseResponse.data.url);
        } else {
            mView.showToast(replyBaseResponse.msg);
        }
    }

    @Override
    public void onDeleteSuccessed(BaseResponse<Object> response, int type, int position) {
        mView.hideLoadingView();
        if (response.code == 0) {
            mView.showDeleteReplyOrTrendView(response, type, position);
        } else {
            mView.showToast(response.msg);
        }
    }

    @Override
    public void showDataLoadErrorView(Throwable e) {
        LogUtil.d("showDataLoadErrorView: " + e);
        mView.hideLoadingView();
        mView.hideRefreshProgress();
        DynamicApiUtils.handleError((TrendsDetailActivity) mView, e);
    }
}