package com.dlc.chemical.ui.widget

import android.content.Context
import android.util.AttributeSet
import android.view.LayoutInflater
import androidx.cardview.widget.CardView
import androidx.constraintlayout.widget.ConstraintLayout
import com.dlc.chemical.R
import com.dlc.chemical.databinding.WidgetHomeMenuBinding

/**
 * info
 *
 * @author ReiChin_
 */
class HomeMenuView @JvmOverloads constructor(
        context: Context,
        attrs: AttributeSet? = null,
        defStyleAttr: Int = 0
) :
    CardView(context, attrs, defStyleAttr) {

    private val viewBinding =
            WidgetHomeMenuBinding.inflate(LayoutInflater.from(context), this, true)

    init {
        val typeArray = context.obtainStyledAttributes(attrs, R.styleable.HomeMenuView)
        viewBinding.menuName.text = typeArray.getString(R.styleable.HomeMenuView_menuName)
        typeArray.getDrawable(R.styleable.HomeMenuView_menuBackgroundRes)?.let {
            viewBinding.menuLayout.background = it
        }
        typeArray.getDrawable(R.styleable.HomeMenuView_menuImageRes)?.let {
            viewBinding.menuImage.setImageDrawable(it)
        }
        typeArray.recycle()
    }

}