HomeTestItemView.kt 2.13 KB
Newer Older
1 2 3
package com.yidianling.home.ui.view

import android.content.Context
严久程 committed
4
import android.text.TextUtils
5 6 7 8
import android.view.View
import android.view.ViewGroup
import android.widget.LinearLayout
import com.ydl.ydl_image.manager.YDLImageCacheManager
严久程 committed
9
import com.ydl.ydlcommon.data.PlatformDataManager
10 11 12 13
import com.yidianling.common.tools.RxImageTool
import com.yidianling.home.R
import com.yidianling.home.event.IHomeBaseEvent
import com.yidianling.home.model.bean.HomeTestItemBean
konghaorui committed
14
import kotlinx.android.synthetic.xlzx.home_test_item_view.view.*
15 16 17

/**
 * @author <a href="https://www.jianshu.com/u/c1e5310dd724">xujian</a>
ydl committed
18
 * @描述: 测评模块item
19 20 21 22 23 24
 * @Copyright Copyright (c) 2019
 * @Company 壹点灵
 * @date 2019/02/14
 */
class HomeTestItemView(private val mContext: Context, private var homeEvent: IHomeBaseEvent?) :
    LinearLayout(mContext) {
ydl committed
25
    private var params: LayoutParams? = null
26 27 28 29 30 31 32

    init {
        initView()
    }

    private fun initView() {
        orientation = VERTICAL
ydl committed
33
        params = LayoutParams(
34 35 36 37
            ViewGroup.LayoutParams.MATCH_PARENT,
            ViewGroup.LayoutParams.WRAP_CONTENT
        )
        layoutParams = params
konghaorui committed
38
        View.inflate(mContext, R.layout.home_test_item_view, this)
39 40 41 42 43 44 45 46

    }

    /**
     * 刷新数据
     */
    fun updateData(bean: HomeTestItemBean, isLast: Boolean) {
        tv_test_item_name.text = bean.name
ydl committed
47 48 49 50 51 52 53
        var numStr = ""
        if (bean.testNum >= 10000) {
            numStr = String.format("%.1f", (bean.testNum / 10000.0)) + "万"
        } else {
            numStr = bean.testNum.toString()
        }
        tv_tested_count.text = numStr
54 55 56 57 58 59 60 61 62 63 64 65
        YDLImageCacheManager.showImage(mContext, bean?.shareImage, iv_test_item)

        this.setOnClickListener {
            homeEvent?.testItemClick(bean.recommendLinkUrl)

        }
    }

    /**
     * 电台第二个item会有一个marginTop值
     */
    fun setTopMargin() {
ydl committed
66
        params?.topMargin = RxImageTool.dp2px(15f)
67 68 69 70 71 72 73
        layoutParams = params
    }

    /**
     * 电台最后一个item会有一个marginBottom值
     */
    fun setBottomMargin() {
ydl committed
74
        params?.bottomMargin = RxImageTool.dp2px(15f)
75 76 77
        layoutParams = params
    }
}