HomeConfideExpertInfoView.kt 6.17 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
package com.yidianling.home.ui.view

import android.annotation.SuppressLint
import android.content.Context
import android.graphics.Paint
import android.text.TextUtils
import android.view.View
import android.view.ViewGroup
import android.widget.FrameLayout
import com.ydl.ydl_image.config.SimpleImageOpConfiger
import com.ydl.ydl_image.manager.YDLImageCacheManager
import com.yidianling.common.tools.RxImageTool
import com.yidianling.home.R
import com.yidianling.home.event.HomeImpl
import com.yidianling.home.event.IHomeBaseEvent
import com.yidianling.home.event.IHomeEvent
import com.yidianling.home.model.bean.HomeConfideBean
konghaorui committed
18
import kotlinx.android.synthetic.xlzx.home_confide_expert_info_view.view.*
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


/**
 * @author jiucheng
 * @描述:首页倾诉模块--专家个人信息view
 * @Copyright Copyright (c) 2018
 * @Company 壹点灵
 * @date 2019/2/16
 */
class HomeConfideExpertInfoView(
    private var mContext: Context,
    private var homeEvent: HomeImpl?
) : FrameLayout(mContext) {
    private var dp70 = 0

    init {
        initView()

        dp70 = RxImageTool.dip2px(70f)
    }

    private fun initView() {
        var params = FrameLayout.LayoutParams(
            ViewGroup.LayoutParams.MATCH_PARENT,
            ViewGroup.LayoutParams.WRAP_CONTENT
        )
        layoutParams = params
konghaorui committed
46
        View.inflate(context, R.layout.home_confide_expert_info_view, this)
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
    }

    fun setData(bean: HomeConfideBean.BodyBean?, position: Int, isLast: Boolean) {
        if (bean == null) {
            visibility = View.GONE
            return
        }
        //设置头像
        setHead(bean)
        //设置名称
        tv_name.text = bean.confidedName
        //设置倾诉标签View的最大宽度
        tag_view.setConfideWidth()
        //咨询师标签
        tag_view.initData(bean.confidedTag as MutableList<String>)
        //设置向TA倾诉人数
        setConfideNum(bean)
        //设置接通率文案
        setConnection(bean)
        //设置向TA倾诉按钮状态
        setConfideButton(bean)
        //设置红包、原价
        setCoupon(bean)
        //最后一项显示分割线
        if (isLast) {
            view_line.visibility = View.GONE
        } else {
            view_line.visibility = View.VISIBLE
        }
        this.setOnClickListener {
            homeEvent!!.confideClick(bean.linkUrl, bean.doctorId)
        }

        iv_confide_voice.setOnClickListener {
            homeEvent!!.confidePlayClick(iv_confide_voice, bean)
        }
    }

    /**
     * 设置头像
     */
    private fun setHead(bean: HomeConfideBean.BodyBean) {
        val op = SimpleImageOpConfiger()
        op.errorPic = R.drawable.platform_head_place_hold_pic
        op.loadingPic = R.drawable.platform_head_place_hold_pic
        op.transform = 0
        YDLImageCacheManager.showImage(mContext, bean.confidedIcon, img_head, op)
    }

    /**
     * 设置向TA倾诉人数
     */
    private fun setConfideNum(bodyBean: HomeConfideBean.BodyBean) {
        if (TextUtils.isEmpty(bodyBean.confideNum)) {
            tv_confideNum.visibility = View.GONE
            tv_tv_confideNumContent.visibility = View.GONE
        } else {
            tv_confideNum.visibility = View.VISIBLE
            tv_tv_confideNumContent.visibility = View.VISIBLE
            if (bodyBean.confideNum?.indexOf("人") != -1) {
                bodyBean.confideNum =
                    bodyBean.confideNum?.substring(0, bodyBean.confideNum?.length!! - 1)
            }
            tv_confideNum.text = bodyBean.confideNum
        }
    }

    /**
     * 设置接通率文案
     */
    private fun setConnection(bodyBean: HomeConfideBean.BodyBean) {
        if (TextUtils.isEmpty(bodyBean.confideConnection)) {
            tv_Connection.visibility = View.INVISIBLE
            tv_ConnectionContent.visibility = View.INVISIBLE
        } else {
            tv_Connection.visibility = View.VISIBLE
            tv_ConnectionContent.visibility = View.VISIBLE
            tv_Connection.text = bodyBean.confideConnection
        }
    }

    /**
     * 设置向TA倾诉按钮状态
     */
    private fun setConfideButton(bodyBean: HomeConfideBean.BodyBean) {
        when (bodyBean.confideLine) {//1在线 2离线 3通话中  4继续倾诉
            1 -> {
konghaorui committed
134
                tv_confide.setBackgroundResource(R.drawable.home_confide_line_1)
135 136
            }
            2 -> {
konghaorui committed
137
                tv_confide.setBackgroundResource(R.drawable.home_confide_line_2)
138 139
            }
            3 -> {
konghaorui committed
140
                tv_confide.setBackgroundResource(R.drawable.home_confide_line_3)
141 142
            }
            4 -> {
konghaorui committed
143
                tv_confide.setBackgroundResource(R.drawable.home_confide_line_4)
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
            }
        }
        tv_confide.setOnClickListener {
            if (bodyBean.confideLine == 2) {//喊他上线  私聊
                homeEvent!!.toChatForMsg(bodyBean.uid.toString())
            } else {
                homeEvent!!.confideClick(bodyBean.linkUrl,bodyBean.doctorId)
            }
        }
    }

    /**
     * 设置红包、原价
     */
    @SuppressLint("SetTextI18n")
    private fun setCoupon(bodyBean: HomeConfideBean.BodyBean) {
        if (bodyBean.couponMoney.toFloat().toInt() <= 0) {//优惠金额
            tvCoupon.visibility = View.GONE
            tvOriginalPrice.visibility = View.GONE
            tv_price.text = "¥${bodyBean.confideFee}"
        } else {
            val couponMoney = bodyBean.couponMoney.toFloat().toInt()
            val confideFee = bodyBean.confideFee.toFloat().toInt()
            val sb = StringBuilder()
            sb.append("立减").append(couponMoney).append("元")
            tvCoupon.text = sb.toString()
            tvCoupon.visibility = View.VISIBLE
            tvOriginalPrice.visibility = View.VISIBLE
            val originalBuffer = StringBuilder()
            originalBuffer.append("原价¥").append(bodyBean.confideFee)
            tvOriginalPrice.text = originalBuffer.toString()
            //添加删除线
            tvOriginalPrice.paint.flags = Paint.STRIKE_THRU_TEXT_FLAG
            if (couponMoney >= confideFee) {
                tv_price.text = "¥0"
            } else {
                val price = confideFee - couponMoney
                tv_price.text = "¥$price"
            }
        }
    }
}