HomeConsultItemView.kt 3.86 KB
Newer Older
1 2 3 4
package com.yidianling.home.ui.view

import android.content.Context
import android.text.TextUtils
5
import android.view.LayoutInflater
6 7 8 9 10 11 12 13 14
import android.view.View
import android.view.ViewGroup
import android.widget.FrameLayout
import com.ydl.ydl_image.manager.YDLImageCacheManager
import com.ydl.ydlcommon.utils.URLUtils
import com.yidianling.common.tools.RxImageTool
import com.yidianling.home.R
import com.yidianling.home.event.IHomeBaseEvent
import com.yidianling.home.model.bean.HomeConsultBean
konghaorui committed
15
import kotlinx.android.synthetic.xlzx.home_consult_item_view.view.*
16
import kotlinx.android.synthetic.xlzx.home_item_tag.view.*
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40

/**
 * @author jiucheng
 * @描述:首页咨询理解模块--专家个人信息view
 * @Copyright Copyright (c) 2018
 * @Company 壹点灵
 * @date 2019/2/16
 */
class HomeConsultItemView(private var mContext: Context, private var homeEvent: IHomeBaseEvent?) :
    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
41
        View.inflate(context, R.layout.home_consult_item_view, this)
42 43 44 45 46 47 48 49 50 51
    }

    fun setData(bean: HomeConsultBean.ListBean?, position: Int, isLast: Boolean, cateId: String?) {
        if (bean == null) {
            visibility = View.GONE
            return
        }
        //设置头像
        setHead(bean)
        //设置名称
52
        tv_consult_name.text = bean.name
53
        //咨询师标签
54 55 56 57 58 59 60 61 62 63 64 65 66 67
        setTag(bean)
        //设置接通率文案
        setConnection(bean)
        //设置向TA咨询人数
        setConfideNum(bean)

        setOnClickListener {
            val url = URLUtils.appendParmas(bean.linkUrl, "cateId", cateId)
            homeEvent!!.consultItemClick(url, bean.doctorId)
        }
    }

    /**咨询师标签*/
    private fun setTag(bean: HomeConsultBean.ListBean) {
68 69 70
        ll_tags.removeAllViews()
        if (!TextUtils.isEmpty(bean.tags)) {
            val tagList = bean.tags?.split("|")
71 72
            tagList.forEachIndexed { index, tag ->
                if (index < 2 && !TextUtils.isEmpty(tag)) {
73 74 75 76 77 78 79
                    val view = LayoutInflater.from(context)
                        .inflate(R.layout.home_item_tag, ll_tags, false)
                    view.tvTag.text = tag
                    ll_tags.addView(view)
                }
            }
        }
80 81 82 83 84 85
    }

    /**
     * 设置头像
     */
    private fun setHead(bean: HomeConsultBean.ListBean) {
86
        YDLImageCacheManager.showImage(mContext, bean?.head, img_consult_head)
87 88 89
    }

    /**
ydl committed
90
     * 设置向TA咨询人数
91 92 93 94
     */
    private fun setConfideNum(bodyBean: HomeConsultBean.ListBean) {
        if (TextUtils.isEmpty(bodyBean.zixunOrderNum.toString())) {
            tv_consult_num.visibility = View.GONE
95
            tv_tv_consult_num_content.visibility = View.GONE
96 97
        } else {
            tv_consult_num.visibility = View.VISIBLE
98 99
            tv_tv_consult_num_content.visibility = View.VISIBLE
            tv_consult_num.text = bodyBean.zixunOrderNum.toString()
100 101 102 103 104 105 106 107 108
        }
    }

    /**
     * 设置接通率文案
     */
    private fun setConnection(bodyBean: HomeConsultBean.ListBean) {
        if (TextUtils.isEmpty(bodyBean.feedbackRate.toString())) {
            tv_feedback_rate.visibility = View.INVISIBLE
109
            tv_feedback_rate_content.visibility = View.INVISIBLE
110 111
        } else {
            tv_feedback_rate.visibility = View.VISIBLE
112
            tv_feedback_rate_content.visibility = View.VISIBLE
113
            try {
114 115
                val dd = bodyBean.feedbackRate/5.00f
                val str = String.format("%.0f",dd*100f)+"%"
116
                tv_feedback_rate.text = str
117
            }catch (e:Exception){
118 119 120 121 122 123
                e.printStackTrace()
            }
        }
    }

}