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

import android.content.Context
import android.support.v7.widget.RecyclerView
import android.view.View
import android.view.ViewGroup
import android.widget.FrameLayout
import android.widget.LinearLayout
import com.yidianling.common.tools.RxImageTool
import com.yidianling.home.R
import com.yidianling.home.event.IHomeBaseEvent
import com.yidianling.home.model.bean.HomeHeaderBean
konghaorui committed
13
import kotlinx.android.synthetic.xlzx.home_button_banner_view.view.*
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 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

/**
 * @author <a href="https://www.jianshu.com/u/c1e5310dd724">xujian</a>
 * @描述: 顶部预约专家,即时倾诉,心理课堂,心理测试按钮模块
 * @Copyright Copyright (c) 2019
 * @Company 壹点灵
 * @date 2019/02/13
 */
class HomeButtonBannerView(private val mContext: Context, private var homeEvent: IHomeBaseEvent?) :
    LinearLayout(mContext) {
    /**
     * 数据缓存
     */
    var mDataList: ArrayList<HomeHeaderBean.AskCategoryDataBean>? = null
    /**
     * 间隔
     */
    var margin: Int = 0

    /**
     * 是否添加了实时测试状态View
     */
    var hasRealTestView: Boolean = false

    private var realTestView: HomePagerBannerRealView? = null
    /**
     * 线
     */
    private var lineView: View? = null
    private var buttonParams: LinearLayout.LayoutParams? = null

    init {
        initView()
    }

    private fun initView() {
        val params = RecyclerView.LayoutParams(
            ViewGroup.LayoutParams.MATCH_PARENT,
            ViewGroup.LayoutParams.WRAP_CONTENT
        )
        layoutParams = params
konghaorui committed
55
        View.inflate(mContext, R.layout.home_button_banner_view, this)
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103

//        initButtonView()

        homeModuleButtonBannerFirst.setOnClickListener {
            homeEvent?.reservationExpertsClick()
        }
        homeModuleButtonBannerSecond.setOnClickListener {
            homeEvent?.nowConfideClick()
        }
        homeModuleButtonBannerThird.setOnClickListener {
            homeEvent?.psychologyClassClick()
        }
        homeModuleButtonBannerFourth.setOnClickListener {
            homeEvent?.psychologyTestClick()
        }
    }


    fun initData(
        homeSaleData: List<HomeHeaderBean.HomeSaleDataBean>?,
        homeCategory: List<HomeHeaderBean.AskCategoryDataBean>?
    ) {
        setRealTextView(homeSaleData)
        homeEvent?.let { home_category_view.setEvent(it) };
        home_category_view.initData(homeCategory)
    }

    /**
     * 初始化实时测评状态View
     */
    private fun initRealTextView() {
        if (null == realTestView) {
            var realTestParam = FrameLayout.LayoutParams(
                ViewGroup.LayoutParams.MATCH_PARENT,
                ViewGroup.LayoutParams.WRAP_CONTENT
            )
            realTestView = HomePagerBannerRealView(context, homeEvent!!)
            realTestView!!.layoutParams = realTestParam
        }
    }

    private fun initLineView() {
        var lineParam =
            FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, RxImageTool.dip2px(0.5f))
        var dp15 = RxImageTool.dip2px(15f)
        lineParam.leftMargin = dp15
        lineParam.rightMargin = dp15
        lineView = View(context)
konghaorui committed
104
        lineView!!.setBackgroundColor(resources.getColor(R.color.home_category_view_test_line))
105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124
        lineView!!.layoutParams = lineParam
    }


    /**
     * 实时测评状态赋值
     */
    private fun setRealTextView(list: List<HomeHeaderBean.HomeSaleDataBean>?) {
        if (!hasRealTestView) {
            initLineView()
            ll_home_module_button.addView(lineView)
            initRealTextView()
            ll_home_module_button.addView(realTestView)

            val cutOffParams = FrameLayout.LayoutParams(
                ViewGroup.LayoutParams.MATCH_PARENT,
                RxImageTool.dip2px(0.5f)
            )
            cutOffParams.height = RxImageTool.dip2px(10f)
            val cutOffView = View(context)
konghaorui committed
125
            cutOffView.setBackgroundColor(resources.getColor(R.color.home_colorBg))
126 127 128 129 130 131 132 133 134 135
            cutOffView.layoutParams = cutOffParams

            ll_home_module_button.addView(cutOffView)

            hasRealTestView = true
        }
        realTestView!!.initData(list)
    }

}