MsgViewHolderPhoneCallSystemNotice.java 5.58 KB
Newer Older
konghaorui committed
1 2 3 4 5 6 7 8 9 10 11 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
package com.yidianling.im.session.viewholder;

import android.text.TextUtils;
import android.widget.TextView;

import com.yidianling.uikit.business.session.helper.MessageListPanelHelper;
import com.yidianling.uikit.business.session.viewholder.MsgViewHolderBase;
import com.yidianling.uikit.custom.bridge.ActionHandlerStorage;
import com.yidianling.nimbase.common.ui.recyclerview.adapter.BaseMultiItemFetchLoadAdapter;
import com.netease.nimlib.sdk.NIMClient;
import com.netease.nimlib.sdk.RequestCallback;
import com.netease.nimlib.sdk.msg.MessageBuilder;
import com.netease.nimlib.sdk.msg.MsgService;
import com.netease.nimlib.sdk.msg.attachment.MsgAttachment;
import com.netease.nimlib.sdk.msg.constant.SessionTypeEnum;
import com.netease.nimlib.sdk.msg.model.IMMessage;
import com.yidianling.common.tools.ToastUtil;
import com.yidianling.im.R;
import com.yidianling.im.session.extension.CustomAttachmentPhoneCallSystemNotice;
import com.ydl.ydlcommon.router.YdlCommonRouterManager;
import com.ydl.ydlcommon.utils.StringUtils;
import com.ydl.ydlcommon.utils.YDLCacheUtils;

/**
 * @author jiucheng
 * @描述: 倾述流程中,根据老师状态(在线、不在线、开通倾述、未开通倾述)发送的自定义消息
 * @Copyright Copyright (c) 2018
 * @Company 壹点灵
 * @date 2018/12/25
 */
public class MsgViewHolderPhoneCallSystemNotice extends MsgViewHolderBase {

    private TextView tpisTv;
    private TextView clickTv;
    private String msgType;//根据此字段显示不同文字  1:邀请开通  2:留言

    public MsgViewHolderPhoneCallSystemNotice(BaseMultiItemFetchLoadAdapter adapter) {
        super(adapter);
    }

    @Override
    protected int getContentResId() {
konghaorui committed
43
        return R.layout.im_ui_message_phone_call_system_notice;
konghaorui committed
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
    }

    @Override
    protected void inflateContentView() {
        tpisTv = view.findViewById(R.id.tv_msg_receive);
        clickTv = view.findViewById(R.id.tv_click_msg);
    }

    @Override
    protected void bindContentView() {
        MsgAttachment attachment = message.getAttachment();
        if (attachment instanceof CustomAttachmentPhoneCallSystemNotice) {
            msgType = ((CustomAttachmentPhoneCallSystemNotice) attachment).getMsgType();
            if (TextUtils.equals("1", msgType)) {
                tpisTv.setText("老师目前没有开通倾诉服务");
                clickTv.setText("邀请开通");
            } else {
                tpisTv.setText("老师现在不便聆听");
                clickTv.setText("给老师留言");
            }
        }
        hideHead();
        hideItemBg();
    }

    @Override
    protected void onItemClick() {
        String localTime;

        //判断今天是否有给老师留过言
        if (TextUtils.equals("1", msgType)) {//邀请开通
            localTime = YDLCacheUtils.Companion.getInviteTime(YdlCommonRouterManager.INSTANCE.getYdlCommonRoute().getUid() + "", ActionHandlerStorage.getL(message.getSessionId()).getInfo().toUid);
        } else {
            localTime = YDLCacheUtils.Companion.getSendMsgTime(YdlCommonRouterManager.INSTANCE.getYdlCommonRoute().getUid() + "", ActionHandlerStorage.getL(message.getSessionId()).getInfo().toUid);
        }


        //是否是同一天
        if (StringUtils.compareTime(localTime)) {//是同一天
            if (TextUtils.equals("1", msgType)) {//邀请开通
                ToastUtil.toastShort("已邀请");
            } else {// 留言
                ToastUtil.toastShort("已留言");
            }
            return;
        }

        String text;
        String toast;
        if (TextUtils.equals("1", msgType)) {//发送邀请开通   老师好,我想邀请您开通倾诉务,您可以联系客服申请开通
            text = "老师好,我想邀请您开通倾诉服务,您可以联系客服申请开通";
            toast = "已邀请";
        } else {// 发送留言   老师好,我想找您倾诉,请尽快上线私聊我,我在等您
            text = "老师好,我想找您倾诉,请尽快上线私聊我,我在等您";
            toast = "已留言";
        }

        IMMessage textMessage = MessageBuilder.createTextMessage(ActionHandlerStorage.getL(message.getSessionId()).getInfo().toUid, SessionTypeEnum.P2P, text);
        NIMClient.getService(MsgService.class)
                .sendMessage(textMessage, false).setCallback(new RequestCallback<Void>() {
            @Override
            public void onSuccess(Void aVoid) {
                if (TextUtils.equals("1", msgType)) {//邀请开通
                    YDLCacheUtils.Companion.saveInviteTime(YdlCommonRouterManager.INSTANCE.getYdlCommonRoute().getUid() + "", ActionHandlerStorage.getL(message.getSessionId()).getInfo().toUid, System.currentTimeMillis() + "");
                } else {
                    YDLCacheUtils.Companion.saveSendMsgTime(YdlCommonRouterManager.INSTANCE.getYdlCommonRoute().getUid() + "", ActionHandlerStorage.getL(message.getSessionId()).getInfo().toUid, System.currentTimeMillis() + "");
                }
//                ToastUtil.toastShort(toast);
            }

            @Override
            public void onFailed(int i) {
                if (i == 7101) {
                    ToastUtil.toastShort("您已被对方拉黑!");
                } else if (i == 404) {
                } else {
                    //上传至后台
                    ActionHandlerStorage.getL(message.getSessionId()).uploadSendMessageError(i);
                }
            }

            @Override
            public void onException(Throwable throwable) {

            }
        });
        MessageListPanelHelper.getInstance().notifyAddMessage(textMessage);
    }
}