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

import android.content.Context
import android.view.View
import android.view.ViewGroup
import android.widget.RelativeLayout
import com.yidianling.home.R
8
import com.yidianling.home.event.IHomeBaseEvent
徐健 committed
9 10
import com.yidianling.home.model.bean.HomeCourseBean
import com.ydl.ydl_image.manager.YDLImageCacheManager
konghaorui committed
11
import kotlinx.android.synthetic.ydl.home_course_item_view.view.*
徐健 committed
12 13 14 15 16 17 18 19

/**
 * @author <a href="https://www.jianshu.com/u/c1e5310dd724">xujian</a>
 * @描述: 课程成长模块item
 * @Copyright Copyright (c) 2019
 * @Company 壹点灵
 * @date 2019/02/14
 */
20
class HomeCourseItemView(private val mContext: Context, private var homeEvent: IHomeBaseEvent?): RelativeLayout(mContext) {
徐健 committed
21 22 23 24 25 26 27 28

    init {
        initView()
    }

    private fun initView() {
        val params = RelativeLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT)
        layoutParams = params
konghaorui committed
29
        View.inflate(mContext, R.layout.home_course_item_view, this)
徐健 committed
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56
    }

    /**
     * 刷新数据
     */
    fun updateData(bean: HomeCourseBean.ListBean?) {

        YDLImageCacheManager.showImage(mContext,bean?.pic,homeModuleCourseItemViewImg)
        homeModuleCourseItemViewTitle.text = bean?.title
        homeModuleCourseItemViewPersonNum.text = bean?.readNums.toString()

        if (bean?.applyFee == 0f) {
            homeModuleCourseItemViewFreePrice.visibility = View.VISIBLE
            homeModuleCourseItemViewExpensePriceHideView.visibility = View.GONE
        }else {
            if (bean?.isPromotion == 1) {
                homeModuleCourseItemViewExpensePrice.text = "¥" + String.format("%.2f", bean?.promotionApplyFee!!)
            }else {
                homeModuleCourseItemViewExpensePrice.text = "¥" + String.format("%.2f", bean?.applyFee!!)
            }
        }

        setOnClickListener {
            homeEvent?.courseItemClick(bean)
        }
    }
}