HomeIntelligentTopItemView.kt 2.05 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11
package com.yidianling.home.ui.view

import android.content.Context
import android.view.View
import android.widget.LinearLayout
import com.ydl.ydl_image.manager.YDLImageCacheManager
import com.yidianling.common.tools.RxDeviceTool
import com.yidianling.common.tools.RxImageTool
import com.yidianling.home.R
import com.yidianling.home.event.IHomeBaseEvent
import com.yidianling.home.model.bean.HomeFMBean
konghaorui committed
12
import kotlinx.android.synthetic.xlzx.home_intelligent_top_item_view.view.*
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37

/**
 * @author <a href="https://www.jianshu.com/u/c1e5310dd724">xujian</a>
 * @描述: 心灵电台模块item--顶部item
 * @Copyright Copyright (c) 2019
 * @Company 壹点灵
 * @date 2019/02/15
 */
class HomeIntelligentTopItemView(
    private val mContext: Context,
    private var homeEvent: IHomeBaseEvent?
) : LinearLayout(mContext) {

    init {
        initView()
    }

    private fun initView() {
        orientation = VERTICAL

        var screenWidth = RxDeviceTool.getScreenWidth(mContext)
        var viewWidth = (screenWidth - 2 * 15 * RxDeviceTool.getScreenDensity(mContext)).toInt()
        var viewHeight = viewWidth * 143 / 345
        val params = LinearLayout.LayoutParams(viewWidth, viewHeight)
        layoutParams = params
konghaorui committed
38
        View.inflate(mContext, R.layout.home_intelligent_top_item_view, this)
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64

    }

    /**
     * 刷新数据
     */
    fun updateData(bean: HomeFMBean.ListBean) {
        var screenWidth = RxDeviceTool.getScreenWidth(mContext)
        var viewWidth = (screenWidth - RxImageTool.dip2px(30f))
        var viewHeight = viewWidth * 143 / 345

        YDLImageCacheManager.showImage(
            mContext,
            bean?.imageUrl,
            homeModuleIntelligentTopViewImage,
            viewWidth,
            viewHeight
        )

        homeModuleIntelligentTopViewTitle.text = bean.name
        homeModuleIntelligentTopViewAuthor.text = bean.author
        homeModuleIntelligentTopViewHits.text = bean.hits.toString()
        this.setOnClickListener { homeEvent?.fmItemClick(bean) }
        iv_play_fm.setOnClickListener { homeEvent?.fmPlayClick(bean) }
    }
}