ConfideHomeRecentView.kt 2.95 KB
Newer Older
洪国微 committed
1 2 3 4 5 6
package com.ydl.confide.home.widget

import android.content.Context
import android.text.TextUtils
import android.view.View
import android.view.ViewGroup
7 8
import androidx.cardview.widget.CardView
import androidx.recyclerview.widget.RecyclerView
洪国微 committed
9 10 11
import com.ydl.confide.R
import com.ydl.confide.home.bean.ConfideHomeDataBean
import com.ydl.confide.home.event.IConfideHomeEvent
12 13 14
import com.ydl.ydl_image.module.GlideApp
import com.ydl.ydl_image.transform.GlideRoundTransform
import com.yidianling.common.tools.RxImageTool
15
import kotlinx.android.synthetic.main.confide_recent_view.view.*
洪国微 committed
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36

/**
 * @author yuanwai
 * @描述:最近倾诉View
 * @Copyright Copyright (c) 2018
 * @Company 壹点灵
 * @date 2018/9/20
 */
class ConfideHomeRecentView(mContext: Context, private var confideHomeEvent: IConfideHomeEvent) : CardView(mContext) {

    private var dp42: Int = 0

    init {
        initView()
    }

    /**
     * 界面初始化
     */
    private fun initView() {
        initLayoutParam()
37
        View.inflate(context, R.layout.confide_recent_view, this)
洪国微 committed
38 39 40 41 42 43 44 45 46 47

    }

    private fun initLayoutParam() {
        dp42 = RxImageTool.dip2px(42f)
        var dp15 = RxImageTool.dip2px(15f)
        var params = RecyclerView.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, RxImageTool.dip2px(50f))
        params.setMargins(dp15, RxImageTool.dip2px(28f), dp15, RxImageTool.dip2px(24f))
        radius = RxImageTool.dip2px(23f).toFloat()
        layoutParams = params
48
        elevation = RxImageTool.dip2px(1f).toFloat()
洪国微 committed
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70
    }

    /**
     * 数据赋值
     */
    fun initData(bean: ConfideHomeDataBean?) {
        if (null == bean || null == bean.body || bean.body.isEmpty()) {
            visibility = View.GONE
            return
        }
        var bodyBean = bean.body[0]
        visibility = View.VISIBLE
        //这样处理 是防止 滑动过程中 反复去加载图片
        if (!TextUtils.isEmpty(bodyBean.confidedIcon) && img_icon.getTag(R.id.img_icon) != bodyBean.confidedIcon) {
            GlideApp.with(context)
                    .load(bodyBean.confidedIcon)
                    .override(dp42, dp42)
                    .transform(GlideRoundTransform(context, 21))
                    .into(img_icon)
            img_icon.setTag(R.id.img_icon, bodyBean.confidedIcon)
        }
        if (bodyBean.confideSex == 1) {
71
            img_sex.setImageResource(R.drawable.confide_new_male)
洪国微 committed
72
        } else {
73
            img_sex.setImageResource(R.drawable.confide_new_female)
洪国微 committed
74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91
        }
        tv_name.text = bodyBean.confidedName
        tv_history.text = bodyBean.confideHistory
        setOnClickListener {
            when (bodyBean.confideLine) {//1在线 2离线 3通话中
                1, 3,4 -> {
                    confideHomeEvent.latelyConfideClick(bodyBean.linkUrl)
                }
                2 -> {
                    //跳转私聊 并发送自定义消息
                    confideHomeEvent.toChatForMsg(""+bodyBean.uid)
                }
            }


        }
    }
}