package com.example.smart.ui.query.view
|
|
import android.content.Context
|
import android.util.AttributeSet
|
import android.view.LayoutInflater
|
import android.widget.FrameLayout
|
import androidx.core.view.isVisible
|
import com.example.smart.R
|
import com.example.smart.databinding.ItemQueryTagBinding
|
import com.example.smart.ui.query.bean.QueryTagBean
|
import com.example.smart.ui.query.event.ITagEvent
|
|
|
class QueryTagView @JvmOverloads constructor(
|
context: Context,
|
private val tagData: QueryTagBean,
|
val showIcon: Boolean = false,
|
attrs: AttributeSet? = null,
|
defStyleAttr: Int = 0,
|
) : FrameLayout(context, attrs, defStyleAttr) {
|
|
private var tagEvent: ITagEvent? = null
|
|
companion object {
|
fun create(context: Context, tagData: QueryTagBean, showIcon: Boolean = false) =
|
QueryTagView(context, tagData, showIcon)
|
}
|
|
fun setTagEvent(tagEvent: ITagEvent) {
|
this.tagEvent = tagEvent
|
}
|
|
|
private val binding by lazy(LazyThreadSafetyMode.NONE) {
|
ItemQueryTagBinding.bind(this)
|
}
|
|
|
init {
|
LayoutInflater.from(context).inflate(R.layout.item_query_tag, this)
|
|
binding.run {
|
tagNameTv.text = tagData.name
|
|
//showIcon表示是否是已选tag
|
tagNameTv.setOnClickListener {
|
if (!showIcon) {
|
tagEvent?.onAdd(tagData)
|
} else{
|
tagEvent?.onRemove(tagData)
|
}
|
|
}
|
|
deleteImg.isVisible = showIcon
|
|
deleteImg.setOnClickListener {
|
if (showIcon) {
|
tagEvent?.onRemove(tagData)
|
}
|
}
|
}
|
}
|
|
|
fun showIcon() = showIcon
|
|
|
}
|