[change] 统计回调添加注册取消注册

This commit is contained in:
xinfengkun
2022-11-09 14:22:00 +08:00
parent 2633e93fc4
commit 8ba6f22c19
3 changed files with 78 additions and 1 deletions

View File

@@ -0,0 +1,60 @@
package com.mogo.eagle.core.function.call.autopilot
import androidx.annotation.Nullable
import com.mogo.eagle.core.function.api.autopilot.IMoGoAutopilotStatisticsListener
import com.mogo.eagle.core.function.call.base.CallerBase
import com.zhidao.support.adas.high.bean.AutopilotStatistics
import java.util.concurrent.ConcurrentHashMap
object CallerAutopilotStatisticsListenerManager : CallerBase() {
private val M_AUTOPILOT_STATISTICS_LISTENER: ConcurrentHashMap<String, IMoGoAutopilotStatisticsListener> =
ConcurrentHashMap()
/**
* 添加监听
* @param tag 标记,用来注销监听使用
* @param listener 监听回调
*/
fun addListener(
@Nullable tag: String,
@Nullable listener: IMoGoAutopilotStatisticsListener
) {
if (M_AUTOPILOT_STATISTICS_LISTENER.containsKey(tag)) {
return
}
M_AUTOPILOT_STATISTICS_LISTENER[tag] = listener
}
/**
* 删除监听
* @param tag 标记,用来注销监听使用
*/
fun removeListener(@Nullable tag: String) {
if (!M_AUTOPILOT_STATISTICS_LISTENER.containsKey(tag)) {
return
}
M_AUTOPILOT_STATISTICS_LISTENER.remove(tag)
}
/**
* 删除自动驾驶按钮选中监听
* @param listener 要删除的监听对象
*/
fun removeListener(@Nullable listener: IMoGoAutopilotStatisticsListener) {
M_AUTOPILOT_STATISTICS_LISTENER.forEach {
if (it.value == listener) {
M_AUTOPILOT_STATISTICS_LISTENER.remove(it.key)
}
}
}
@Synchronized
fun invokeAutopilotStatistics(statistics: AutopilotStatistics?) {
M_AUTOPILOT_STATISTICS_LISTENER.forEach {
val listener = it.value
listener.onAutopilotStatistics(statistics)
}
}
}