package com.swago.baseswago.cusview

import android.content.Context
import android.util.AttributeSet
import android.view.LayoutInflater
import android.view.ViewGroup
import android.widget.FrameLayout
import androidx.constraintlayout.widget.ConstraintLayout
import androidx.core.content.ContextCompat
import com.swago.baseswago.R
import com.swago.baseswago.databinding.ViewLiangBinding
import com.swago.baseswago.util.AppContext
import com.swago.baseswago.util.DpPxUtil

class LiangView : FrameLayout {

    private var binding:ViewLiangBinding? = null

    constructor(context: Context) : this(context, null)
    constructor(context: Context, attrs: AttributeSet?) : this(context, attrs, 0)

    constructor(context: Context, attrs: AttributeSet?, defStyleAttr: Int) : super(
        context,
        attrs,
        defStyleAttr
    ){
        initView()
    }

    private fun initView() {
        binding = ViewLiangBinding.inflate(LayoutInflater.from(context),this,true)
    }

    fun setUserId(isPrettyId:Boolean,id:String){
        binding?.apply {
            if (isPrettyId){
                tvID.text = id
                tvID.setTextColor(ContextCompat.getColor(AppContext.getContext(), R.color._ffffff))
                tvID.setBackgroundResource(R.mipmap.icon_liang_bg)
                tvID.setPadding(DpPxUtil.dip2px(25f),0,DpPxUtil.dip2px(8f),DpPxUtil.dip2px(2f))
            }else{
                tvID.text = AppContext.getContext().resources.getString(R.string.id_x).format(id)
                tvID.setTextColor(ContextCompat.getColor(AppContext.getContext(), R.color._868686))
                tvID.setBackgroundColor(ContextCompat.getColor(AppContext.getContext(), android.R.color.transparent))
                tvID.setPadding(0,0,0,0)
            }
        }

    }

}