MsgViewHolderShareMsg.java 5.16 KB
Newer Older
konghaorui committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
package com.yidianling.im.session.viewholder;

import android.annotation.SuppressLint;
import android.widget.TextView;

import com.netease.nimlib.sdk.msg.attachment.MsgAttachment;
import com.ydl.webview.H5Params;
import com.ydl.webview.NewH5Activity;
import com.ydl.ydlcommon.utils.Utils;
import com.ydl.ydlcommon.utils.remind.HttpErrorUtils;
import com.yidianling.common.tools.ToastUtil;
import com.yidianling.im.R;
import com.yidianling.im.bean.PushConfideStatusBean;
import com.yidianling.im.http.ImRetrofitApi;
import com.yidianling.im.router.ImIn;
import com.yidianling.im.session.extension.CustomAttachmentShareMsg;
import com.yidianling.nimbase.common.ui.recyclerview.adapter.BaseMultiItemFetchLoadAdapter;
konghaorui committed
18
import com.yidianling.user.api.bean.UserResponseBean;
konghaorui committed
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
import com.yidianling.uikit.business.session.viewholder.MsgViewHolderBase;

import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.disposables.Disposable;
import io.reactivex.schedulers.Schedulers;

/**
 * Created by haorui on 2019-11-06 .
 * Des: 分享 消息
 * 分享的类型,0:测试;1,课程;2,文章;3:倾诉
 */
public class MsgViewHolderShareMsg extends MsgViewHolderBase {

    private TextView tv_confide_money;
    private TextView tv_confide;
    public String mShareUrl;
    public String mPrice;
    private int mShareType;
    private Disposable mSubscribe;

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

    @Override
    protected int getContentResId() {
        MsgAttachment attachment = message.getAttachment();
        if (attachment instanceof CustomAttachmentShareMsg) {
            CustomAttachmentShareMsg customMsg = (CustomAttachmentShareMsg) attachment;
            switch (customMsg.getShareType()) {
                //0:测试;
                case 0:
konghaorui committed
51
                    return R.layout.im_ui_message_custom_confide;
konghaorui committed
52 53
                //1,课程;
                case 1:
konghaorui committed
54
                    return R.layout.im_ui_message_custom_confide;
konghaorui committed
55 56
                //2,文章;
                case 2:
konghaorui committed
57
                    return R.layout.im_ui_message_custom_confide;
konghaorui committed
58 59
                //3:倾诉
                case 3:
konghaorui committed
60
                    return R.layout.im_ui_message_custom_confide;
konghaorui committed
61 62 63
            }

        }
konghaorui committed
64
        return R.layout.im_ui_message_custom_confide;
konghaorui committed
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
    }

    @Override
    protected void inflateContentView() {
        tv_confide_money = view.findViewById(R.id.tv_confide_money);
        tv_confide = view.findViewById(R.id.tv_confide);

    }

    @Override
    protected void bindContentView() {
        MsgAttachment attachment = message.getAttachment();
        if (attachment instanceof CustomAttachmentShareMsg) {
            mShareUrl = ((CustomAttachmentShareMsg) attachment).getShareUrl();
            mPrice = ((CustomAttachmentShareMsg) attachment).getSharePrice();
            mShareType = ((CustomAttachmentShareMsg) attachment).getShareType();
        }

        if (isReceivedMessage()) {
            setAvatarRightInVisibity();
        } else {
            setAvatarLeftInVisibity();
        }

        switch (mShareType) {
            //0:测试;
            case 0:
                break;
            //1,课程;
            case 1:
                break;
            //2,文章;
            case 2:
                break;
            //3:倾诉
            case 3:
                tv_confide_money.setText(mPrice);
                break;
        }
    }

    @Override
    protected void onItemClick() {
        super.onItemClick();
        if (Utils.isFastClick()) {
            //防止连击
            return;
        }
        requestConfideStatus();
    }

    @SuppressLint("CheckResult")
    private void requestConfideStatus() {
        if(mSubscribe != null && !mSubscribe.isDisposed()){
            mSubscribe.dispose();
        }
konghaorui committed
121
        UserResponseBean userInfo = ImIn.INSTANCE.getUserResponse();
konghaorui committed
122 123 124 125 126
        mSubscribe = ImRetrofitApi.Companion.getImJavaApi().getPushConfideStatus(userInfo.getUid(), message.getFromAccount()).subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).subscribe(it -> {
            if ("200".equals(it.code)) {
                PushConfideStatusBean data = it.data;

                if (data.getIsOpen() != 1) {
konghaorui committed
127
                    ToastUtil.toastShort(view.getContext().getString(R.string.im_push_confide_msg_unopened));
konghaorui committed
128 129 130 131
                    return;
                }

                if (data.getIsOnline() != 1) {
konghaorui committed
132
                    ToastUtil.toastShort(view.getContext().getString(R.string.im_push_confide_msg_offline));
konghaorui committed
133 134 135 136 137
                    return;
                }


                if (data.getIsReducible() != 1) {
konghaorui committed
138
                    ToastUtil.toastShort(view.getContext().getString(R.string.im_push_confide_msg_busy));
konghaorui committed
139 140 141 142
                    return;
                }

                if (data.getIsStatus() != 1) {
konghaorui committed
143
                    ToastUtil.toastShort(view.getContext().getString(R.string.im_push_confide_msg_calling));
konghaorui committed
144 145 146 147 148 149 150 151 152 153
                    return;
                }
                NewH5Activity.start(view.getContext(), new H5Params(mShareUrl, null));
            }
        }, t -> {
            HttpErrorUtils.Companion.handleError(context, t);
        });

    }
}