HomeButtonBannerView.kt 2.26 KB
Newer Older
徐健 committed
1 2 3 4 5 6 7 8
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.LinearLayout
import com.yidianling.home.R
9
import com.yidianling.home.event.IHomeBaseEvent
徐健 committed
10
import com.yidianling.common.tools.RxDeviceTool
konghaorui committed
11
import kotlinx.android.synthetic.ydl.home_button_banner_view.view.*
徐健 committed
12 13 14 15 16 17 18 19

/**
 * @author <a href="https://www.jianshu.com/u/c1e5310dd724">xujian</a>
 * @描述: 顶部预约专家,即时倾诉,心理课堂,心理测试按钮模块
 * @Copyright Copyright (c) 2019
 * @Company 壹点灵
 * @date 2019/02/13
 */
20
class HomeButtonBannerView(private val mContext: Context, private var homeEvent: IHomeBaseEvent?) : LinearLayout(mContext) {
徐健 committed
21 22 23 24 25 26 27 28 29 30

    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
31
        View.inflate(mContext, R.layout.home_button_banner_view, this)
徐健 committed
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 57 58 59 60 61 62 63 64

        initButtonView()

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

    /**
     * 初始化四个按钮
     */
    private fun initButtonView() {
        if (null == buttonParams) {
            var screenWidth = RxDeviceTool.getScreenWidth(mContext)
            var viewWidth = ((screenWidth - 2 * 9 * RxDeviceTool.getScreenDensity(mContext)) / 4).toInt()
            var viewHeight = viewWidth * 78 / 80
            buttonParams = LinearLayout.LayoutParams(viewWidth, viewHeight)
            homeModuleButtonBannerFirst.layoutParams = buttonParams
            homeModuleButtonBannerSecond.layoutParams = buttonParams
            homeModuleButtonBannerThird.layoutParams = buttonParams
            homeModuleButtonBannerFourth.layoutParams = buttonParams
        }
    }
}