fix problem

This commit is contained in:
zhongchao
2022-09-09 10:01:57 +08:00
parent 4e1b4fa9d1
commit 2e2c7612d7

View File

@@ -5,15 +5,16 @@ import android.util.AttributeSet
import android.view.LayoutInflater
import androidx.appcompat.content.res.AppCompatResources
import androidx.constraintlayout.widget.ConstraintLayout
import com.mogo.eagle.core.data.autopilot.AutopilotStatusInfo
import com.mogo.eagle.core.data.autopilot.pnc.PncActionsHelper
import com.mogo.eagle.core.data.trafficlight.TrafficLightResult
import com.mogo.eagle.core.data.trafficlight.currentRoadTrafficLight
import com.mogo.eagle.core.data.trafficlight.isRed
import com.mogo.eagle.core.function.api.autopilot.IMoGoAutopilotPlanningActionsListener
import com.mogo.eagle.core.function.api.autopilot.IMoGoAutopilotStatusListener
import com.mogo.eagle.core.function.api.autopilot.IMoGoAutopilotStatusListener.Companion.STATUS_AUTOPILOT_RUNNING
import com.mogo.eagle.core.function.api.trafficlight.IMoGoTrafficLightListener
import com.mogo.eagle.core.function.call.autopilot.CallerAutoPilotStatusListenerManager
import com.mogo.eagle.core.function.call.autopilot.CallerAutoPilotStatusListenerManager.getAutoPilotStatusInfo
import com.mogo.eagle.core.function.call.autopilot.CallerAutopilotPlanningActionsListenerManager
import com.mogo.eagle.core.function.call.trafficlight.CallerTrafficLightListenerManager
import com.mogo.eagle.core.function.hmi.R
@@ -26,7 +27,7 @@ class PncActionsView @JvmOverloads constructor(
attrs: AttributeSet? = null,
defStyleAttr: Int = 0
) : ConstraintLayout(context, attrs, defStyleAttr), IMoGoAutopilotPlanningActionsListener,
IMoGoTrafficLightListener {
IMoGoTrafficLightListener, IMoGoAutopilotStatusListener {
companion object {
const val TAG = "PncActionsView"
@@ -35,57 +36,68 @@ class PncActionsView @JvmOverloads constructor(
@Volatile
private var mTrafficLightResult: TrafficLightResult? = null
private var mAutoPilotStatusInfo: AutopilotStatusInfo? = null
init {
LayoutInflater.from(context).inflate(R.layout.view_pnc_actions, this, true)
}
override fun onAttachedToWindow() {
super.onAttachedToWindow()
CallerAutoPilotStatusListenerManager.addListener(TAG, this)
CallerAutopilotPlanningActionsListenerManager.addListener(TAG, this)
CallerTrafficLightListenerManager.registerTrafficLightListener(TAG, this)
}
override fun onDetachedFromWindow() {
super.onDetachedFromWindow()
CallerAutoPilotStatusListenerManager.removeListener(TAG)
CallerAutopilotPlanningActionsListenerManager.removeListener(TAG)
CallerTrafficLightListenerManager.unRegisterTrafficLightListener(TAG)
}
override fun pncActions(planningActionMsg: MessagePad.PlanningActionMsg) {
if(getAutoPilotStatusInfo().state != STATUS_AUTOPILOT_RUNNING){
return
}
UiThreadHandler.post {
var actions: String? = null
planningActionMsg.actionMsg?.let {
actions =
PncActionsHelper.getAction(it.drivingState.number, it.drivingAction.number)
//如果是存在云端红绿灯数据条件下,设置云端数据
if (PncActionsHelper.isWaitingTrafficlight(
it.drivingState.number,
it.drivingAction.number
)
&& mTrafficLightResult != null
&& getWaitTrafficlightTime().isNotBlank()
) {
actions += ",预计${getWaitTrafficlightTime()}秒后通过"
} else {
mTrafficLightResult = null
}
}
// update view
if (actions.isNullOrEmpty()) {
override fun onAutopilotStatusResponse(autoPilotStatusInfo: AutopilotStatusInfo) {
super.onAutopilotStatusResponse(autoPilotStatusInfo)
mAutoPilotStatusInfo = autoPilotStatusInfo
if (mAutoPilotStatusInfo!!.state != STATUS_AUTOPILOT_RUNNING) {
UiThreadHandler.post {
this.background = null
tvHmiPncActions.text = ""
} else {
this.background = AppCompatResources.getDrawable(context, R.drawable.pnc_actions_bg)
tvHmiPncActions.text = actions
}
}
}
override fun pncActions(planningActionMsg: MessagePad.PlanningActionMsg) {
mAutoPilotStatusInfo?.let {
if (it.state == STATUS_AUTOPILOT_RUNNING) {
UiThreadHandler.post {
var actions: String? = null
planningActionMsg.actionMsg?.let {
actions = PncActionsHelper.getAction(it.drivingState.number, it.drivingAction.number)
//如果是存在云端红绿灯数据条件下,设置云端数据
if (PncActionsHelper.isWaitingTrafficlight(it.drivingState.number, it.drivingAction.number)
&& mTrafficLightResult != null
&& getWaitTrafficlightTime().isNotBlank()) {
actions += ",预计${getWaitTrafficlightTime()}秒后通过"
} else {
mTrafficLightResult = null
}
}
// update view
if (actions.isNullOrEmpty()) {
this.background = null
tvHmiPncActions.text = ""
} else {
this.background = AppCompatResources.getDrawable(context, R.drawable.pnc_actions_bg)
tvHmiPncActions.text = actions
}
}
}
}
}
override fun onTrafficLightStatus(trafficLightResult: TrafficLightResult) {
mTrafficLightResult = trafficLightResult
}