From 2e2c7612d77a3416f07123a480ab7aa58978906b Mon Sep 17 00:00:00 2001 From: zhongchao Date: Fri, 9 Sep 2022 10:01:57 +0800 Subject: [PATCH] fix problem --- .../function/hmi/ui/pnc/PncActionsView.kt | 74 +++++++++++-------- 1 file changed, 43 insertions(+), 31 deletions(-) diff --git a/core/function-impl/mogo-core-function-hmi/src/main/java/com/mogo/eagle/core/function/hmi/ui/pnc/PncActionsView.kt b/core/function-impl/mogo-core-function-hmi/src/main/java/com/mogo/eagle/core/function/hmi/ui/pnc/PncActionsView.kt index 236d755d45..1d756041cf 100644 --- a/core/function-impl/mogo-core-function-hmi/src/main/java/com/mogo/eagle/core/function/hmi/ui/pnc/PncActionsView.kt +++ b/core/function-impl/mogo-core-function-hmi/src/main/java/com/mogo/eagle/core/function/hmi/ui/pnc/PncActionsView.kt @@ -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 }