package com.yidian.bcommon.widget

import android.content.Context
import android.util.AttributeSet
import android.view.View
import androidx.constraintlayout.widget.ConstraintLayout
import com.yidian.bcommon.R
import com.yidian.bcommon.databinding.ViewCommonEmptyPageBinding

/**
 * author: yinjiacheng
 * date: 7/9/21 8:06 PM
 * description: 空视图
 */
class CommonEmptyPageView @JvmOverloads constructor(
  context: Context,
  attrs: AttributeSet? = null,
  defStyle: Int = 0
) : ConstraintLayout(context, attrs, defStyle) {

  private val viewBinding by lazy {
    ViewCommonEmptyPageBinding.bind(
      View.inflate(
        getContext(),
        R.layout.view_common_empty_page,
        this
      )
    )
  }

  init {
    val typeArray = context.obtainStyledAttributes(attrs, R.styleable.CommonEmptyPageView)
    viewBinding.ivPlaceHolder.setImageResource(
      typeArray.getResourceId(
        R.styleable.CommonEmptyPageView_CommonEmptyPageView_place_holder_img,
        -1
      )
    )
    viewBinding.tvEmptyContent.text = typeArray.getText(R.styleable.CommonEmptyPageView_CommonEmptyPageView_empty_content_text)
    viewBinding.tvEmptyTips.text = typeArray.getText(R.styleable.CommonEmptyPageView_CommonEmptyPageView_empty_tips_text)
    typeArray.recycle()
  }

}
