package com.yidian.common.widget

import android.content.Context
import android.util.AttributeSet
import android.view.View
import androidx.constraintlayout.widget.ConstraintLayout
import com.yidian.common.R
import com.yidian.common.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()
  }

}
