add new func of dispatch to uploading routing and fix bug of read vip info
This commit is contained in:
@@ -44,14 +44,11 @@ class MogoTrafficLightManager : IMogoCarLocationChangedListener2 {
|
||||
.registerCenterApi.registerCarLocationChangedListener(TAG, this)
|
||||
mThreadHandler =
|
||||
TrafficLightThreadHandler(Looper.getMainLooper(), {
|
||||
Logger.d(TAG, "loop search roadID , mLocation : $mLocation")
|
||||
|
||||
//查询路口时,如果红绿灯显示,则隐藏掉
|
||||
if (TrafficLightHMIManager.INSTANCE.isWarningTrafficLightShow()) {
|
||||
TrafficLightHMIManager.INSTANCE.hideTrafficLight()
|
||||
CallTrafficLightListenerManager.resetTrafficLightData()
|
||||
}
|
||||
|
||||
mLocation?.let { it ->
|
||||
val tileId = MogoApisHandler.getInstance().apis
|
||||
.mapServiceApi.mapUIController.getTileId(it.longitude, it.latitude)
|
||||
@@ -61,7 +58,7 @@ class MogoTrafficLightManager : IMogoCarLocationChangedListener2 {
|
||||
roadId = it
|
||||
},
|
||||
{
|
||||
Logger.d(TAG, "request road id error : $it")
|
||||
Logger.e(TAG, "request road id error : $it")
|
||||
})
|
||||
}
|
||||
}, {
|
||||
@@ -81,7 +78,7 @@ class MogoTrafficLightManager : IMogoCarLocationChangedListener2 {
|
||||
},
|
||||
{ errorMsg ->
|
||||
//如果没有获取到正确的红绿灯数据,则取消读灯,继续读路口,防止出现一直读灯的情况
|
||||
Logger.d(TAG, "request Traffic Light error : $errorMsg")
|
||||
Logger.e(TAG, "request Traffic Light error : $errorMsg")
|
||||
//stop loop traffic light
|
||||
trafficLightNetWorkModel.cancelRequestTrafficLight()
|
||||
//未查到红绿灯,加入2秒延时请求路口ID
|
||||
|
||||
@@ -2,6 +2,9 @@ package com.mogo.eagle.core.function.v2x.vip
|
||||
|
||||
import android.content.Context
|
||||
import android.location.Location
|
||||
import android.os.Handler
|
||||
import android.os.Looper
|
||||
import android.os.Message
|
||||
import com.mogo.cloud.commons.utils.CoordinateUtils
|
||||
import com.mogo.eagle.core.data.map.MogoLatLng
|
||||
import com.mogo.eagle.core.data.trafficlight.TrafficLightResult
|
||||
@@ -13,7 +16,7 @@ import com.mogo.eagle.core.function.api.trafficlight.IMoGoTrafficLightListener
|
||||
import com.mogo.eagle.core.function.call.hmi.CallerHmiManager
|
||||
import com.mogo.eagle.core.function.call.trafficlight.CallTrafficLightListenerManager
|
||||
import com.mogo.eagle.core.function.v2x.trafficlight.core.MogoTrafficLightManager
|
||||
import com.mogo.eagle.core.utilcode.util.SPUtils
|
||||
import com.mogo.eagle.core.function.v2x.vip.network.VipNetWorkModel
|
||||
import com.mogo.map.navi.IMogoCarLocationChangedListener2
|
||||
import com.mogo.module.common.MogoApisHandler
|
||||
import com.mogo.module.common.enums.EventTypeEnum
|
||||
@@ -22,11 +25,13 @@ import com.mogo.utils.logger.Logger
|
||||
import kotlin.math.abs
|
||||
|
||||
class VipCarManager : IMogoOnMessageListener<VipMessage>, IMoGoTrafficLightListener,
|
||||
IMogoCarLocationChangedListener2 {
|
||||
IMogoCarLocationChangedListener2, Handler.Callback {
|
||||
|
||||
companion object {
|
||||
|
||||
const val TAG = "VipCarManager"
|
||||
private const val MSG_WHAT_VIP_SEARCH = 1
|
||||
private const val MSG_WHAT_VIP_CANCEL = 2
|
||||
|
||||
val INSTANCE: VipCarManager by lazy(mode = LazyThreadSafetyMode.SYNCHRONIZED) {
|
||||
VipCarManager()
|
||||
@@ -39,6 +44,8 @@ class VipCarManager : IMogoOnMessageListener<VipMessage>, IMoGoTrafficLightListe
|
||||
private var turnLightEnd = true
|
||||
private var result: TrafficLightResult? = null
|
||||
private var vip: Boolean = false
|
||||
private val vipNetWorkModel = VipNetWorkModel()
|
||||
private val handler = Handler(Looper.getMainLooper(), this)
|
||||
|
||||
fun initServer(context: Context) {
|
||||
mContext = context
|
||||
@@ -48,21 +55,20 @@ class VipCarManager : IMogoOnMessageListener<VipMessage>, IMoGoTrafficLightListe
|
||||
.apis.getSocketManagerApi(context)
|
||||
.registerOnMessageListener(401025, this)
|
||||
|
||||
val vipSetTime = SPUtils.getInstance().getLong("vip")
|
||||
if (vipSetTime == -1L) {
|
||||
return
|
||||
}
|
||||
//首次进入应用查询是否为VIP车辆
|
||||
requestVip()
|
||||
}
|
||||
|
||||
//todo 后续改成接口调用查询,防止清除缓存造成状态不统一
|
||||
if (vipSetTime > 0 && System.currentTimeMillis() - vipSetTime < 0) { //未超时,需要设置VIP
|
||||
vip = true
|
||||
CallerHmiManager.vipIdentification(true)
|
||||
CallTrafficLightListenerManager.registerTrafficLightListener(TAG, this)
|
||||
} else {
|
||||
vip = false
|
||||
CallerHmiManager.vipIdentification(false)
|
||||
SPUtils.getInstance().remove("vip") //超时
|
||||
override fun handleMessage(msg: Message): Boolean {
|
||||
when (msg.what) {
|
||||
MSG_WHAT_VIP_SEARCH -> {
|
||||
requestVip()
|
||||
}
|
||||
MSG_WHAT_VIP_CANCEL -> {
|
||||
cancelVip()
|
||||
}
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
override fun target(): Class<VipMessage> {
|
||||
@@ -74,16 +80,18 @@ class VipCarManager : IMogoOnMessageListener<VipMessage>, IMoGoTrafficLightListe
|
||||
vipMessage?.let {
|
||||
when (it.vipType) {
|
||||
0 -> { //取消VIP
|
||||
vip = false
|
||||
SPUtils.getInstance().remove("vip")
|
||||
CallerHmiManager.vipIdentification(false)
|
||||
CallTrafficLightListenerManager.unRegisterTrafficLightListener(TAG)
|
||||
cancelVip()
|
||||
}
|
||||
1 -> { //设置VIP
|
||||
vip = true
|
||||
SPUtils.getInstance().put("vip", vipMessage.timeOut)
|
||||
CallerHmiManager.vipIdentification(true)
|
||||
CallTrafficLightListenerManager.registerTrafficLightListener(TAG, this)
|
||||
Logger.d(
|
||||
TAG,
|
||||
"设置handler超时时间 " + ", time : ${System.currentTimeMillis() - vipMessage.timeOut}"
|
||||
)
|
||||
handler.sendEmptyMessageDelayed(
|
||||
MSG_WHAT_VIP_CANCEL,
|
||||
System.currentTimeMillis() - vipMessage.timeOut
|
||||
)
|
||||
setVip()
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -122,7 +130,10 @@ class VipCarManager : IMogoOnMessageListener<VipMessage>, IMoGoTrafficLightListe
|
||||
object : IMoGoWarningStatusListener {
|
||||
override fun onShow() {}
|
||||
override fun onDismiss() {
|
||||
Logger.d(TAG, "showWarningV2X vip dismiss , reset turnLightFirst to false ")
|
||||
Logger.d(
|
||||
TAG,
|
||||
"showWarningV2X vip dismiss , reset turnLightFirst to false "
|
||||
)
|
||||
turnLightFirst = false
|
||||
turnLightEnd = true
|
||||
}
|
||||
@@ -138,6 +149,18 @@ class VipCarManager : IMogoOnMessageListener<VipMessage>, IMoGoTrafficLightListe
|
||||
// }
|
||||
}
|
||||
|
||||
private fun setVip() {
|
||||
vip = true
|
||||
CallerHmiManager.vipIdentification(true)
|
||||
CallTrafficLightListenerManager.registerTrafficLightListener(TAG, this)
|
||||
}
|
||||
|
||||
private fun cancelVip() {
|
||||
vip = false
|
||||
CallerHmiManager.vipIdentification(false)
|
||||
CallTrafficLightListenerManager.unRegisterTrafficLightListener(TAG)
|
||||
}
|
||||
|
||||
private fun canGetThroughCross(
|
||||
it: Location,
|
||||
trafficLightResult: TrafficLightResult
|
||||
@@ -158,6 +181,22 @@ class VipCarManager : IMogoOnMessageListener<VipMessage>, IMoGoTrafficLightListe
|
||||
}
|
||||
}
|
||||
|
||||
private fun requestVip() {
|
||||
vipNetWorkModel.requestVip({
|
||||
if (handler.hasMessages(MSG_WHAT_VIP_SEARCH)) {
|
||||
handler.removeMessages(MSG_WHAT_VIP_SEARCH)
|
||||
}
|
||||
if (it) {
|
||||
setVip()
|
||||
} else {
|
||||
cancelVip()
|
||||
}
|
||||
}, {
|
||||
Logger.e(TAG, "获取VIP信息失败, 准备间隔5秒重新获取")
|
||||
handler.sendEmptyMessageDelayed(MSG_WHAT_VIP_SEARCH, 5_000L)
|
||||
})
|
||||
}
|
||||
|
||||
private fun turnLight() {
|
||||
result?.let {
|
||||
MogoTrafficLightManager.INSTANCE.turnLightToGreen(
|
||||
@@ -166,7 +205,7 @@ class VipCarManager : IMogoOnMessageListener<VipMessage>, IMoGoTrafficLightListe
|
||||
mLocation!!.bearing.toDouble(), {
|
||||
Logger.d(TAG, "变灯请求成功")
|
||||
}, { errorMsg ->
|
||||
Logger.d(TAG, "变灯请求失败 msg : $errorMsg")
|
||||
Logger.e(TAG, "变灯请求失败 msg : $errorMsg")
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,26 @@
|
||||
package com.mogo.eagle.core.function.v2x.vip
|
||||
|
||||
import com.mogo.commons.debug.DebugConfig
|
||||
|
||||
class VipConst {
|
||||
|
||||
companion object {
|
||||
const val MODULE_NAME = "MODULE_V2X_VIP"
|
||||
|
||||
private const val HOST_DEV = "http://dzt-test.zhidaozhixing.com"
|
||||
private const val HOST_TEST = "http://dzt-test.zhidaozhixing.com"
|
||||
private const val HOST_DEMO = "http://dzt-show.zhidaozhixing.com"
|
||||
private const val HOST_PRODUCT = "http://dzt.zhidaozhixing.com"
|
||||
|
||||
fun getNetHost(): String {
|
||||
return when (DebugConfig.getNetMode()) {
|
||||
DebugConfig.NET_MODE_DEV -> HOST_DEV
|
||||
DebugConfig.NET_MODE_QA -> HOST_TEST
|
||||
DebugConfig.NET_MODE_DEMO -> HOST_DEMO
|
||||
else -> HOST_PRODUCT
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,14 @@
|
||||
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 retrofit2.http.*
|
||||
|
||||
interface VipApiService {
|
||||
|
||||
//查询是否为VIP车辆
|
||||
@GET("/dataService/carUser/getVipStatusBySn")
|
||||
suspend fun requestVip(@Query("sn") sn: String): BaseResponse<Boolean>
|
||||
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
package com.mogo.eagle.core.function.v2x.vip.network
|
||||
|
||||
import com.mogo.cloud.network.RetrofitFactory
|
||||
import com.mogo.cloud.passport.MoGoAiCloudClientConfig
|
||||
import com.mogo.eagle.core.data.BaseResponse
|
||||
import com.mogo.eagle.core.function.v2x.vip.VipConst
|
||||
import com.mogo.utils.network.apiCall
|
||||
import com.mogo.utils.network.request
|
||||
|
||||
class VipNetWorkModel {
|
||||
|
||||
private fun getNetWorkApi(baseUrl: String = VipConst.getNetHost()): VipApiService {
|
||||
return RetrofitFactory.getInstanceNoCallAdapter(baseUrl)!!
|
||||
.create(VipApiService::class.java)
|
||||
}
|
||||
|
||||
fun requestVip(onSuccess: ((Boolean) -> Unit), onError: ((String) -> Unit)) {
|
||||
request<BaseResponse<Boolean>> {
|
||||
loader {
|
||||
apiCall {
|
||||
getNetWorkApi().requestVip(MoGoAiCloudClientConfig.getInstance().sn)
|
||||
}
|
||||
}
|
||||
onSuccess {
|
||||
if (it.result != null) {
|
||||
if (it.result) {
|
||||
onSuccess.invoke(true)
|
||||
} else {
|
||||
onSuccess.invoke(false)
|
||||
}
|
||||
} else {
|
||||
onError.invoke("requestRoadID result is null")
|
||||
}
|
||||
}
|
||||
onError {
|
||||
if (it.message != null) {
|
||||
onError.invoke(it.message!!)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user