package com.swago.room.widget

import android.content.Context
import android.util.AttributeSet
import android.view.LayoutInflater
import androidx.constraintlayout.widget.ConstraintLayout
import com.bumptech.glide.Glide
import com.bumptech.glide.request.RequestOptions
import com.swago.baseswago.baseroom.RoomTimer
import com.swago.baseswago.baseroom.SwagoRoomManager
import com.swago.baseswago.model.im.AnchorRoomClosedBean
import com.swago.baseswago.util.AppContext
import com.swago.baseswago.util.NoDoubleClickListener
import com.swago.room.R
import com.swago.room.databinding.DialogUserForAnchorCloseBinding
import jp.wasabeef.glide.transformations.BlurTransformation

/**
 *@date 2022/2/7 14:57
 *description:
 */
class UserShowAnchorCloseView : ConstraintLayout {

    private lateinit var binding : DialogUserForAnchorCloseBinding

    constructor(context: Context) : super(context)
    constructor(context: Context, mAttributeSet: AttributeSet?) : super(context, mAttributeSet){
        initView(context)
    }

    private fun initView(context: Context) {
        binding = DialogUserForAnchorCloseBinding.inflate(LayoutInflater.from(context), this, true)
        binding.tvBack.setOnClickListener(object : NoDoubleClickListener() {
            override fun onClick() {
                SwagoRoomManager.closeRoom()
            }
        })
    }

    fun setData(anchorRoomClosedBean: AnchorRoomClosedBean){
        RoomTimer.clear()
        binding.tvName.text = anchorRoomClosedBean.senderName
        binding.tvID.text = AppContext.getContext().resources.getString(R.string.id_x)
            .format(anchorRoomClosedBean.userCode)
        Glide.with(this).load(anchorRoomClosedBean.userAvatar)
            .placeholder(R.mipmap.default_avatar)
            .error(R.mipmap.default_avatar).into(binding.ivAvatar)
        Glide.with(this)
            .load(anchorRoomClosedBean.userAvatar)
            .placeholder(R.mipmap.default_avatar)
            .error(R.mipmap.default_avatar)
            .dontAnimate()
            .apply(RequestOptions.bitmapTransform(BlurTransformation(5, 100)))
            .into(binding.ivCloseBg)
    }

}