fix vip cancel bug and add new interface of trafficCrossRoad event

This commit is contained in:
zhongchao
2021-11-25 21:27:17 +08:00
parent 80efeb0bf2
commit 96cfc293fe
7 changed files with 87 additions and 20 deletions

View File

@@ -119,10 +119,10 @@ class MogoTrafficLightManager : IMogoCarLocationChangedListener2 {
mLocation?.let { loc ->
roadIDResult?.let {
// 检测是否开过路口,开过路口则停止读灯。并重置 trafficLightResult 值为 null
// trafficLightResult != null &&
if (it.isInRange(loc.latitude, loc.longitude)) {
if (trafficLightResult != null && it.isInRange(loc.latitude, loc.longitude)) {
inRange = true
Logger.d("arrowtest", "进入路口")
CallTrafficLightListenerManager.invokeEnterCrossRoad()
return
}
if (inRange) {

View File

@@ -88,11 +88,7 @@ class VipCarManager : IMogoOnMessageListener<VipMessage>, IMoGoTrafficLightListe
TAG,
"设置handler超时时间 " + ", time : ${System.currentTimeMillis() - vipMessage.timeOut}"
)
handler.sendEmptyMessageDelayed(
MSG_WHAT_VIP_CANCEL,
System.currentTimeMillis() - vipMessage.timeOut
)
setVip()
setVip(vipMessage.timeOut)
}
}
}
@@ -150,8 +146,12 @@ class VipCarManager : IMogoOnMessageListener<VipMessage>, IMoGoTrafficLightListe
// }
}
private fun setVip() {
private fun setVip(cancelDelayTime: Long) {
vip = true
handler.sendEmptyMessageDelayed(
MSG_WHAT_VIP_CANCEL,
cancelDelayTime - System.currentTimeMillis()
)
CallerHmiManager.vipIdentification(true)
CallVipSetListenerManager.invokeVipSetStatus(true)
CallTrafficLightListenerManager.registerTrafficLightListener(TAG, this)
@@ -159,6 +159,9 @@ class VipCarManager : IMogoOnMessageListener<VipMessage>, IMoGoTrafficLightListe
private fun cancelVip() {
vip = false
if(handler.hasMessages(MSG_WHAT_VIP_CANCEL)){
handler.removeMessages(MSG_WHAT_VIP_CANCEL)
}
CallerHmiManager.vipIdentification(false)
CallVipSetListenerManager.invokeVipSetStatus(false)
CallTrafficLightListenerManager.unRegisterTrafficLightListener(TAG)
@@ -189,8 +192,8 @@ class VipCarManager : IMogoOnMessageListener<VipMessage>, IMoGoTrafficLightListe
if (handler.hasMessages(MSG_WHAT_VIP_SEARCH)) {
handler.removeMessages(MSG_WHAT_VIP_SEARCH)
}
if (it) {
setVip()
if (it.vipStatus) {
setVip(it.cancelDelayTime)
} else {
cancelVip()
}

View File

@@ -1,14 +1,13 @@
package com.mogo.eagle.core.function.v2x.vip.network
import com.mogo.eagle.core.data.BaseResponse
import com.mogo.eagle.core.data.trafficlight.RoadIDResult
import com.mogo.eagle.core.data.trafficlight.TrafficLightResult
import com.mogo.eagle.core.data.v2x.VipRequest
import retrofit2.http.*
interface VipApiService {
//查询是否为VIP车辆
@GET("/dataService/carUser/getVipStatusBySn")
suspend fun requestVip(@Query("sn") sn: String): BaseResponse<Boolean>
suspend fun requestVip(@Query("sn") sn: String): BaseResponse<VipRequest>
}

View File

@@ -2,6 +2,7 @@ package com.mogo.eagle.core.function.v2x.vip.network
import com.mogo.cloud.passport.MoGoAiCloudClientConfig
import com.mogo.eagle.core.data.BaseResponse
import com.mogo.eagle.core.data.v2x.VipRequest
import com.mogo.module.common.MogoApisHandler
import com.mogo.module.common.constants.HostConst.DATA_SERVICE_HOST
import com.mogo.utils.network.apiCall
@@ -15,8 +16,8 @@ class VipNetWorkModel {
)
}
fun requestVip(onSuccess: ((Boolean) -> Unit), onError: ((String) -> Unit)) {
request<BaseResponse<Boolean>> {
fun requestVip(onSuccess: ((VipRequest) -> Unit), onError: ((String) -> Unit)) {
request<BaseResponse<VipRequest>> {
loader {
apiCall {
getNetWorkApi().requestVip(MoGoAiCloudClientConfig.getInstance().sn)
@@ -24,11 +25,7 @@ class VipNetWorkModel {
}
onSuccess {
if (it.result != null) {
if (it.result) {
onSuccess.invoke(true)
} else {
onSuccess.invoke(false)
}
onSuccess.invoke(it.result)
} else {
onError.invoke("requestRoadID result is null")
}

View File

@@ -0,0 +1,10 @@
package com.mogo.eagle.core.data.v2x
/**
* 查询是否为VIP
* timeOut: 超时时间
* vipType: Vip --1 变成VIP--0 撤销VIP
* content: VIP消息
*/
data class VipRequest(val cancelDelayTime: Long, val vipStatus:Boolean) {
}

View File

@@ -9,4 +9,11 @@ interface IMoGoTrafficLightListener {
*/
fun onTrafficLightStatus(trafficLightResult: TrafficLightResult)
/**
* 车辆进入路口回调
*/
fun onEnterCrossRoad(){
}
}

View File

@@ -62,6 +62,50 @@ object CallTrafficLightListenerManager {
}
}
/**
* 添加监听
* @param tag 标记,用来注销监听使用
* @param listener 监听回调
*/
fun registerEnterCrossRoadListener(
@Nullable tag: String,
@Nullable listener: IMoGoTrafficLightListener
) {
if (M_TRAFFIC_LIGHT_LISTENER.containsKey(tag)) {
LogUtils.eTag(TAG, "Tag:$tag already exists,please use other tag")
return
}
M_TRAFFIC_LIGHT_LISTENER[tag] = listener
}
/**
* 删除监听
* @param tag 标记,用来注销监听使用
*/
fun unRegisterEnterCrossRoadListener(@Nullable tag: String) {
if (!M_TRAFFIC_LIGHT_LISTENER.containsKey(tag)) {
LogUtils.eTag(TAG, "Tag:$tag not exists")
return
}
M_TRAFFIC_LIGHT_LISTENER.remove(tag)
}
/**
* 删除监听
* @param listener 要删除的监听对象
*/
fun unRegisterEnterCrossRoadListener(@Nullable listener: IMoGoTrafficLightListener) {
if (!M_TRAFFIC_LIGHT_LISTENER.containsValue(listener)) {
LogUtils.eTag(TAG, "listener:$listener not exists")
return
}
M_TRAFFIC_LIGHT_LISTENER.forEach {
if (it.value == listener) {
M_TRAFFIC_LIGHT_LISTENER.remove(it.key)
}
}
}
fun invokeTrafficLightStatus(trafficLightResult: TrafficLightResult) {
this.trafficLightResult = trafficLightResult
M_TRAFFIC_LIGHT_LISTENER.forEach {
@@ -72,6 +116,13 @@ object CallTrafficLightListenerManager {
}
}
fun invokeEnterCrossRoad(){
M_TRAFFIC_LIGHT_LISTENER.forEach {
val listener = it.value
listener.onEnterCrossRoad()
}
}
fun resetTrafficLightData() {
trafficLightResult = null
}