package com.example.smart.ui.query.view
|
|
import android.content.Context
|
import android.util.AttributeSet
|
import android.view.LayoutInflater
|
import android.widget.LinearLayout
|
import com.example.basecore.util.dp2px
|
import com.example.smart.R
|
import com.example.smart.databinding.QueryTagLayoutBinding
|
import com.example.smart.ui.query.bean.QueryInfoBean
|
import com.example.smart.ui.query.event.ITagEvent
|
|
|
class QueryTagLayout @JvmOverloads constructor(
|
context: Context,
|
private val infoBean: QueryInfoBean,
|
private val mITagEvent: ITagEvent,
|
attrs: AttributeSet? = null,
|
defStyleAttr: Int = 0,
|
) : LinearLayout(context, attrs, defStyleAttr) {
|
|
companion object {
|
fun create(context: Context, infoBean: QueryInfoBean, mITagEvent: ITagEvent) =
|
QueryTagLayout(context, infoBean, mITagEvent)
|
}
|
|
private val binding by lazy(LazyThreadSafetyMode.NONE) {
|
QueryTagLayoutBinding.bind(this)
|
}
|
|
|
init {
|
LayoutInflater.from(context).inflate(R.layout.query_tag_layout, this)
|
orientation = VERTICAL
|
|
setBackgroundResource(R.drawable.shape_layout)
|
|
binding.run {
|
tabNameTv.text = infoBean.tabName
|
}
|
|
if (infoBean.list.isNotEmpty()) {
|
buildTagView()
|
}
|
|
post {
|
if (layoutParams != null) {
|
val params = layoutParams as LayoutParams
|
params.topMargin = dp2px(18)
|
layoutParams = params
|
}
|
}
|
}
|
|
|
private fun buildTagView() {
|
for (tagInfo in infoBean.list) {
|
val tagView = QueryTagView.create(context, tagInfo)
|
tagView.setTagEvent(mITagEvent)
|
binding.flexBox.addView(tagView)
|
}
|
}
|
|
fun getFlexView() = binding.flexBox
|
|
|
}
|