ShowIntroduceDialogFragment.java 6.79 KB
Newer Older
konghaorui committed
1 2 3 4
package com.yidianling.dynamic.thank;

import android.graphics.Color;
import android.os.Bundle;
YKai committed
5
import androidx.annotation.Nullable;
konghaorui committed
6 7 8 9 10 11 12 13 14 15 16 17 18 19
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.ydl.webview.H5Params;
import com.ydl.webview.NewH5Activity;
import com.ydl.ydl_image.module.GlideApp;
import com.ydl.ydl_image.transform.GlideCircleTransform;
import com.ydl.ydlcommon.base.BaseDialogFragment;
import com.ydl.ydlcommon.bean.ShareData;
import com.ydl.ydlcommon.view.dialog.CommonDialog;
import com.yidianling.common.tools.ToastUtil;
20
import com.yidianling.dynamic.bean.DynamicConstants;
konghaorui committed
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35
import com.yidianling.dynamic.R;
import com.yidianling.dynamic.common.net.DynamicApiUtils;
import com.yidianling.dynamic.model.Command;
import com.yidianling.dynamic.router.DynamicIn;
import com.yidianling.dynamic.thank.data.ZJservice;

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

/**
 * Created by jinkai on 16/5/10.
 */
public class ShowIntroduceDialogFragment extends BaseDialogFragment {


万齐军 committed
36 37 38 39 40
    private ImageView mHead;
    private TextView mName;
    private TextView mIntroduce;
    private ImageView mChangeImg;
    private TextView mChangeText;
konghaorui committed
41 42 43 44 45 46 47 48 49 50 51 52 53 54

    String docid;

    String UId;

    String listener_id;

    String name;

    String headUrl;

    String goodAt;

    private ZJservice zjservice;
万齐军 committed
55 56 57
    private View mLlBtn1;
    private View mLlBtn2;
    private View mIvClose;
konghaorui committed
58 59 60 61 62


    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
konghaorui committed
63
        View view = inflater.inflate(R.layout.dynamic_fragment_dialog_show_introduce, container, false);
万齐军 committed
64
        bindView(view);
konghaorui committed
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83
        init();
        return view;
    }

    public ShowIntroduceDialogFragment setPamrams(String docid, String UId, String listener_id, String name, String headUrl, String goodAt) {
        this.docid = docid;
        this.UId = UId;
        this.listener_id = listener_id;
        this.name = name;
        this.headUrl = headUrl;
        this.goodAt = goodAt;
        return this;
    }

    void init() {
        getService();
    }


万齐军 committed
84
    private void click(View view) {
konghaorui committed
85 86 87 88 89 90 91 92 93
        if (view.getId() == R.id.ll_btn1) {
            if (zjservice.is_online.equals("1")) {

                H5Params h5Params = new H5Params(DynamicConstants.Companion.getZHUANJIA() + listener_id, null);
                ShareData shareData = new ShareData(DynamicConstants.Companion.getZHUANJIA() + listener_id, name, headUrl, goodAt);
                h5Params.setShareData(shareData);
                NewH5Activity.start(getActivity(), h5Params);
            } else if (zjservice.is_online.equals("2")) {

94
                if (!DynamicIn.INSTANCE.loginByOneKeyLogin(getActivity(),true)) {
konghaorui committed
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
                    return;
                }
                H5Params h5Params = new H5Params(DynamicConstants.Companion.getWWWXIADAN() + docid, null);
                NewH5Activity.start(getActivity(), h5Params);
            } else if (zjservice.is_online.equals("3")) {
                ToastUtil.toastShort("未开通微问诊");
            } else if (zjservice.is_online.equals("4")) {
                ToastUtil.toastShort("微问诊已满");
            }

        } else if (view.getId() == R.id.ll_btn2) {
            H5Params h5Params = new H5Params(DynamicIn.INSTANCE.getExpertHost() + docid, null);
            ShareData shareData = new ShareData(DynamicIn.INSTANCE.getShareExpertHost()+ docid, name + "咨询工作室", headUrl, goodAt);
            h5Params.setShareData(shareData);
            NewH5Activity.start(getActivity(), h5Params);
        } else if (view.getId() == R.id.iv_close) {
            dismiss();
        }
    }


    public void getService() {
        Command.Service service = new Command.Service(UId);
        DynamicApiUtils.getService(service)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(resp -> {
                    if (resp.code == 0) {
                        zjservice = resp.data;
                        mIntroduce.setText(zjservice.subhead);
                        mName.setText(name);
                        GlideApp.with(this)
                                .load(headUrl)
                                .transform(new GlideCircleTransform(getDialog().getContext()))
                                .into(mHead);

                        if (zjservice.is_online.equals("2")) {
konghaorui committed
132
                            mChangeImg.setImageResource(R.drawable.dynamic_icon_layer_chat);
konghaorui committed
133 134 135
                            mChangeText.setText("私聊");
                        }
                        if (zjservice.is_online.equals("3") || zjservice.is_online.equals("4")) {
konghaorui committed
136
                            mChangeImg.setImageResource(R.drawable.dynamic_icon_layer_chat_off);
konghaorui committed
137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155
                            mChangeText.setText("私聊");
                            mChangeText.setTextColor(Color.parseColor("#888888"));
                        }
                    } else {
                        ToastUtil.toastShort(resp.msg);
                    }
                }, throwable -> DynamicApiUtils.handleError(getActivity(), throwable));
    }

    private void showDialog(final String needRecharge) {

        new CommonDialog(getActivity())
                .setMessage("当前余额不足\n本次连接最少需要充值" +
                        needRecharge + "元")
                .setLeftOnclick("放弃", null)
                .setRightClick("充值", new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
//                        OuterEmptyImp.jumpToRechargeActivity(getActivity(),needRecharge+"");
konghaorui committed
156
                        DynamicIn.INSTANCE.rechargeIntent(getActivity());
konghaorui committed
157 158 159 160 161 162
//                        Intent intent = new Intent(getActivity(), RechargeActivity.class);
//                        intent.putExtra("money", needRecharge + "");
//                        startActivity(intent);
                    }
                }).show();
    }
万齐军 committed
163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182

    private void bindView(View bindSource) {
        mHead = bindSource.findViewById(R.id.sdv_head);
        mName = bindSource.findViewById(R.id.name);
        mIntroduce = bindSource.findViewById(R.id.introduce);
        mChangeImg = bindSource.findViewById(R.id.changeimg);
        mChangeText = bindSource.findViewById(R.id.changtext);
        mLlBtn1 = bindSource.findViewById(R.id.ll_btn1);
        mLlBtn2 = bindSource.findViewById(R.id.ll_btn2);
        mIvClose = bindSource.findViewById(R.id.iv_close);
        mLlBtn1.setOnClickListener(v -> {
            click(v);
        });
        mLlBtn2.setOnClickListener(v -> {
            click(v);
        });
        mIvClose.setOnClickListener(v -> {
            click(v);
        });
    }
konghaorui committed
183
}