[6.7.0][FSM] refactor: 弹框修改成dialog 以便有蒙层;
This commit is contained in:
@@ -1,157 +0,0 @@
|
||||
package com.mogo.eagle.core.function.hmi.bone.status.fsm
|
||||
|
||||
import android.content.Context
|
||||
import android.graphics.Color
|
||||
import android.util.AttributeSet
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.widget.FrameLayout
|
||||
import android.widget.ImageView
|
||||
import android.widget.LinearLayout
|
||||
import android.widget.ScrollView
|
||||
import android.widget.TextView
|
||||
import com.mogo.eagle.core.function.hmi.R
|
||||
import com.mogo.eagle.core.utilcode.kotlin.onClick
|
||||
import com.mogo.eagle.core.utilcode.mogo.logger.Logger
|
||||
import com.zhjt.mogo_core_function_devatools.status.StatusManager
|
||||
import com.zhjt.mogo_core_function_devatools.status.entity.FSMStateCode
|
||||
import com.zhjt.mogo_core_function_devatools.status.entity.FSMStatus
|
||||
import com.zhjt.mogo_core_function_devatools.status.entity.Status
|
||||
|
||||
/**
|
||||
* FSM状态展示 View
|
||||
*/
|
||||
class FSMStatusDetailView @JvmOverloads constructor(
|
||||
context: Context,
|
||||
attrs: AttributeSet? = null,
|
||||
defStyleAttr: Int = 0
|
||||
) : FrameLayout(
|
||||
context,
|
||||
attrs,
|
||||
defStyleAttr
|
||||
), StatusManager.IStatusListener {
|
||||
companion object {
|
||||
private const val TAG = "FSMStatusDetailView"
|
||||
}
|
||||
|
||||
private var tvTitle: TextView? = null
|
||||
private var scrollLayout: ScrollView? = null
|
||||
private var llFsmMsgContainerLayout: LinearLayout? = null
|
||||
private var tvCloseBtn: TextView? = null
|
||||
|
||||
init {
|
||||
LayoutInflater.from(context).inflate(R.layout.view_status_fsm_layout, this, true)
|
||||
initView()
|
||||
}
|
||||
|
||||
private fun initView() {
|
||||
tvTitle = findViewById(R.id.tvTitle)
|
||||
scrollLayout = findViewById(R.id.scrollLayout)
|
||||
llFsmMsgContainerLayout = findViewById(R.id.fsmMsgContainerLayout)
|
||||
tvCloseBtn = findViewById(R.id.btnClose)
|
||||
tvCloseBtn?.onClick {
|
||||
FSMStatusDetailWindowManager.fsmStatusDetailWindowManager.dismiss()
|
||||
}
|
||||
}
|
||||
|
||||
fun setFsmErrorStatus(msgArray: List<String>) {
|
||||
tvTitle?.text = "FSM异常"
|
||||
runCatching {
|
||||
val c = Color.parseColor("#FF4E41")
|
||||
tvTitle?.setTextColor(c)
|
||||
}
|
||||
addFsmMsgItemView(msgArray, true)
|
||||
|
||||
//监听最新 FSM 状态
|
||||
StatusManager.addListener(TAG, this)
|
||||
}
|
||||
|
||||
private fun setFsmNormalStatus() {
|
||||
tvTitle?.text = "FSM正常"
|
||||
runCatching {
|
||||
val c = Color.parseColor("#26C14F")
|
||||
tvTitle?.setTextColor(c)
|
||||
}
|
||||
addFsmMsgItemView(ArrayList<String>().also { it += "FSM异常状态已恢复" }, false)
|
||||
}
|
||||
|
||||
private fun setFsmUnknownStatus() {
|
||||
tvTitle?.text = "FSM状态未知"
|
||||
runCatching {
|
||||
val c = Color.parseColor("#FFCD3D")
|
||||
tvTitle?.setTextColor(c)
|
||||
}
|
||||
removeFsmMsgItemView()
|
||||
}
|
||||
|
||||
private fun setFsmNotExistStatus() {
|
||||
tvTitle?.text = "FSM不存在"
|
||||
runCatching {
|
||||
val c = Color.parseColor("#FFFFFF")
|
||||
tvTitle?.setTextColor(c)
|
||||
}
|
||||
removeFsmMsgItemView()
|
||||
}
|
||||
|
||||
private fun addFsmMsgItemView(msgArray: List<String>, isError: Boolean) {
|
||||
if (llFsmMsgContainerLayout == null) {
|
||||
Logger.e(TAG, "addFsmMsmItemView llFsmMsgContainerLayout is null")
|
||||
return
|
||||
}
|
||||
scrollLayout?.visibility = View.VISIBLE
|
||||
llFsmMsgContainerLayout?.removeAllViews()
|
||||
msgArray.forEach {
|
||||
val itemView: View = LayoutInflater.from(context)
|
||||
.inflate(R.layout.view_status_fsm_item_layout, llFsmMsgContainerLayout, false)
|
||||
val leftImageView: ImageView = itemView.findViewById(R.id.leftImageView)
|
||||
leftImageView.setImageResource(if (isError) R.drawable.icon_fsm_error_red_arrow else R.drawable.icon_fsm_error_green_arrow)
|
||||
val rightTextView: TextView = itemView.findViewById(R.id.rightTextView)
|
||||
rightTextView.text = it
|
||||
llFsmMsgContainerLayout?.addView(itemView)
|
||||
}
|
||||
}
|
||||
|
||||
private fun removeFsmMsgItemView() {
|
||||
llFsmMsgContainerLayout?.removeAllViews()
|
||||
//scrollLayout?.visibility = View.GONE
|
||||
}
|
||||
|
||||
/**
|
||||
* @param changed: 变化的数据
|
||||
* @param all: 所有状态数据
|
||||
*/
|
||||
override fun onStatusChanged(changed: List<Status>, all: List<Status>) {
|
||||
changed.filterIsInstance<FSMStatus>().forEach { status ->
|
||||
when (status) {
|
||||
is FSMStatus -> {
|
||||
handleFSMStatus(status)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun handleFSMStatus(status: FSMStatus) {
|
||||
when (status.state) {
|
||||
FSMStateCode.NotExist -> {
|
||||
setFsmNotExistStatus()
|
||||
}
|
||||
|
||||
FSMStateCode.UnKnown -> {
|
||||
setFsmUnknownStatus()
|
||||
}
|
||||
|
||||
FSMStateCode.ExistNormal -> {
|
||||
setFsmNormalStatus()
|
||||
}
|
||||
|
||||
FSMStateCode.ExistError -> {
|
||||
setFsmErrorStatus(status.descList)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun onDetachedFromWindow() {
|
||||
super.onDetachedFromWindow()
|
||||
StatusManager.removeListener(TAG)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user