HomeConfideExpertInfoView.kt 8.8 KB
Newer Older
徐健 committed
1 2 3 4 5 6 7 8
package com.yidianling.home.ui.view

import android.annotation.SuppressLint
import android.content.Context
import android.text.TextUtils
import android.view.View
import android.view.ViewGroup
import android.widget.FrameLayout
范玉宾 committed
9 10 11 12
import com.blankj.utilcode.util.SpanUtils
import com.bumptech.glide.Glide
import com.bumptech.glide.load.engine.DiskCacheStrategy
import com.ydl.ydl_image.module.GlideApp
徐健 committed
13
import com.yidianling.common.tools.RxImageTool
万齐军 committed
14 15 16
import com.yidianling.home.R
import com.yidianling.home.event.IHomeBaseEvent
import com.yidianling.home.model.bean.HomeConfideBean
范玉宾 committed
17
import kotlinx.android.synthetic.ydl.home_confide_item_layout.view.*
徐健 committed
18 19 20 21 22 23 24 25

/**
 * @author jiucheng
 * @描述:首页倾诉模块--专家个人信息view
 * @Copyright Copyright (c) 2018
 * @Company 壹点灵
 * @date 2019/2/16
 */
26
class HomeConfideExpertInfoView(private var mContext: Context, private var homeEvent: IHomeBaseEvent?) : FrameLayout(mContext) {
徐健 committed
27 28 29 30 31 32 33 34 35 36 37
    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
范玉宾 committed
38
        View.inflate(context, R.layout.home_confide_item_layout, this)
徐健 committed
39 40 41 42 43 44 45 46 47
    }

    fun setData(bean: HomeConfideBean.BodyBean?, position: Int, isLast: Boolean) {
        if (bean == null) {
            visibility = View.GONE
            return
        }
        //设置头像
        setHead(bean)
范玉宾 committed
48 49 50

        setListenAndScore(bean)

范玉宾 committed
51 52
        setFreeStatus(bean)

范玉宾 committed
53 54 55 56
        setConfideTag(bean)

        setLineStatus(bean)

徐健 committed
57 58
        //设置名称
        tv_name.text = bean.confidedName
59
        //设置倾诉标签View的最大宽度
范玉宾 committed
60
//        tag_view.setConfideWidth()
徐健 committed
61
        //咨询师标签
范玉宾 committed
62
//        tag_view.initData(bean.confidedTag as MutableList<String>)
徐健 committed
63 64 65 66 67 68 69
        //设置向TA倾诉人数
        setConfideNum(bean)
        //设置接通率文案
        setConnection(bean)
        //设置向TA倾诉按钮状态
        setConfideButton(bean)
        //设置红包、原价
范玉宾 committed
70
//        setCoupon(bean)
范玉宾 committed
71 72 73 74

        //设置咨询师简介
        tv_content.text = bean.confideContent

徐健 committed
75 76
        //最后一项显示分割线
        if (isLast) {
范玉宾 committed
77
            view_line.visibility = View.GONE
徐健 committed
78
        } else {
范玉宾 committed
79
            view_line.visibility = View.VISIBLE
徐健 committed
80 81
        }
        this.setOnClickListener {
万齐军 committed
82
            homeEvent!!.confideClick(bean.linkUrl, bean.confidedId.toString(), bean.doctorId, bean.uid.toString())
徐健 committed
83 84 85 86 87 88 89
        }
    }

    /**
     * 设置头像
     */
    private fun setHead(bean: HomeConfideBean.BodyBean) {
范玉宾 committed
90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105
//        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)


        //这样处理 是防止 滑动过程中 反复去加载图片
        if (!TextUtils.isEmpty(bean.confidedIcon) && img_head.getTag(R.id.img_head) != bean.confidedIcon) {
            GlideApp.with(context)
                .load(bean.confidedIcon)
//                .override(dp96, dp96)
                .into(img_head)
            img_head.setTag(R.id.img_head, bean.confidedIcon)
        }

徐健 committed
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
    }

    /**
     * 设置向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
            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
142
                tv_confide.setBackgroundResource(R.drawable.home_confide_line_1)
徐健 committed
143 144
            }
            2 -> {
konghaorui committed
145
                tv_confide.setBackgroundResource(R.drawable.home_confide_line_2)
徐健 committed
146 147
            }
            3 -> {
konghaorui committed
148
                tv_confide.setBackgroundResource(R.drawable.home_confide_line_3)
徐健 committed
149 150
            }
            4 -> {
konghaorui committed
151
                tv_confide.setBackgroundResource(R.drawable.home_confide_line_4)
徐健 committed
152 153 154 155 156 157
            }
        }
        tv_confide.setOnClickListener {
            if (bodyBean.confideLine == 2) {//喊他上线  私聊
                homeEvent!!.toChatForMsg(bodyBean.uid.toString())
            } else {
万齐军 committed
158
                homeEvent!!.confideClick(bodyBean.linkUrl, bodyBean.confidedId.toString(), bodyBean.doctorId, bodyBean.uid.toString())
徐健 committed
159 160 161 162
            }
        }
    }

范玉宾 committed
163 164 165 166 167 168 169 170 171 172 173 174

    private fun setListenAndScore(bodyBean: HomeConfideBean.BodyBean) {
        SpanUtils.with(price_content).append(bodyBean.confideFee)
            .setForegroundColor(resources.getColor(R.color.home_confide_fe6040)).setFontSize(18, true)
            .append("元").setForegroundColor(resources.getColor(R.color.home_confide_fe6040))
            .setFontSize(11, true)
            .append("/25分钟").setForegroundColor(resources.getColor(R.color.home_confide_aaaeba))
            .setFontSize(11, true)
            .create()
        tv_score.text = bodyBean.confidePraiseScore
    }

徐健 committed
175
    /**
范玉宾 committed
176
     * 设置在线状态
徐健 committed
177
     */
范玉宾 committed
178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193
    private fun setLineStatus(bodyBean: HomeConfideBean.BodyBean) {
        when (bodyBean.confideLine) {//1在线 2离线 3通话中
            1, 4 -> {
                tv_online.text = "在线"
                tv_online.setBackgroundResource(R.drawable.home_confide_online_main)
            }
            2 -> {
                tv_online.text = "离线"
                tv_online.setBackgroundResource(R.drawable.home_confide_offline_bg)
            }
            3 -> {
                tv_online.text = "通话中"
                tv_online.setBackgroundResource(R.drawable.home_confide_online_main)
            }
        }
    }
徐健 committed
194

范玉宾 committed
195 196 197
    private fun setConfideTag(bodyBean: HomeConfideBean.BodyBean) {
        if (null == bodyBean.confidedTag || bodyBean.confidedTag!!.isEmpty()) {
            return
徐健 committed
198
        }
范玉宾 committed
199 200 201 202 203 204
        var i = 0
        val sb = StringBuilder()
        for (tag in bodyBean.confidedTag!!) {
            if (i > 4) break
            sb.append(tag).append(" | ")
            i++
徐健 committed
205
        }
范玉宾 committed
206 207
        if (sb.length > 3) {
            sb.setLength(sb.length - 3)
徐健 committed
208
        }
范玉宾 committed
209 210 211
        flowlayout_tag.text = sb.toString()
    }

范玉宾 committed
212 213 214 215 216 217 218 219 220 221 222 223
    private fun setFreeStatus(bodyBean: HomeConfideBean.BodyBean) {
        if (bodyBean.listenFree == true && bodyBean.confideLine == 1) {
            confide_free_logo.visibility = VISIBLE
            Glide.with(context)
                .load(R.drawable.home_confide__free)
                .diskCacheStrategy(DiskCacheStrategy.RESOURCE)
                .into(confide_free_logo)
        } else {
            confide_free_logo.visibility = GONE
        }
    }

范玉宾 committed
224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258
    /**
     * 设置红包、原价
     */
    @SuppressLint("SetTextI18n")
    private fun setCoupon(bodyBean: HomeConfideBean.BodyBean) {

//        if(!TextUtils.isEmpty(bodyBean.couponText)){
//            tvCoupon.text = bodyBean.couponText
//            tvCoupon.visibility = View.VISIBLE
//        }else{
//            tvCoupon.visibility = View.GONE
//        }
//        if (TextUtils.isEmpty(bodyBean.confideFee) || TextUtils.isEmpty(bodyBean.couponMoney) || bodyBean.couponMoney!!.toFloat() <= 0){
//            tvOriginalPrice.visibility = View.GONE
//        }else{
//            tvOriginalPrice.visibility = View.VISIBLE
//            val originalBuffer = StringBuffer()
//            originalBuffer.append(bodyBean.confideFee).append("元/次")
//            tvOriginalPrice.text = originalBuffer.toString()
//            //添加删除线
//            tvOriginalPrice.paint.flags = Paint.STRIKE_THRU_TEXT_FLAG
//        }
//        try {
//            val couponMoney = bodyBean.couponMoney!!.toFloat().toInt()
//            val confideFee = bodyBean.confideFee!!.toFloat().toInt()
//
//            if (couponMoney >= confideFee){
//                tv_price.text = "¥0"
//            }else{
//                val price = confideFee - couponMoney
//                tv_price.text = "¥"+price.toString()
//            }
//        }catch (e:Exception){
//            //防止数据类型变化引起奔溃
//        }
徐健 committed
259 260 261

    }
}