[Feat]新增消息盒子数据中心

This commit is contained in:
chenfufeng
2022-11-22 16:32:20 +08:00
parent 64c448a4d6
commit 0c0ff743bb
21 changed files with 482 additions and 0 deletions

View File

@@ -0,0 +1,87 @@
package com.mogo.eagle.core.function.call.msgbox
import androidx.annotation.Nullable
import com.mogo.eagle.core.data.msgbox.MsgBoxBean
import com.mogo.eagle.core.data.msgbox.MsgCategory
import com.mogo.eagle.core.function.api.msgbox.IMsgBoxListener
import com.mogo.eagle.core.function.call.base.CallerBase
import java.util.concurrent.ConcurrentHashMap
/**
* @author chenfufeng
* @date 2022/11/17
* 消息盒子数据监听管理
*/
object CallerMsgBoxListenerManager : CallerBase() {
private val statusListeners: ConcurrentHashMap<String, IMsgBoxListener> =
ConcurrentHashMap()
// private val key2CategoryMap by lazy {
// ConcurrentHashMap<String, MsgCategory>()
// }
/**
* 添加数据监听
* @param tag 标记,用来注销监听使用
* @param listener 监听回调
*/
fun addListener(
@Nullable tag: String,
@Nullable listener: IMsgBoxListener
) {
if (statusListeners.containsKey(tag)) {
return
}
statusListeners[tag] = listener
}
// fun addListenerByCategory(
// @Nullable tag: String,
// @Nullable category: MsgCategory,
// @Nullable listener: IMsgBoxListener
// ) {
// addListener(tag, listener)
// key2CategoryMap[tag] = category
// }
/**
* 删除 OBU状态 监听
* @param tag 标记,用来注销监听使用
*/
fun removeListener(@Nullable tag: String) {
if (!statusListeners.containsKey(tag)) {
return
}
statusListeners.remove(tag)
}
/**
* 删除 OBU状态 监听
* @param listener 要删除的监听对象
*/
fun removeListener(@Nullable listener: IMsgBoxListener) {
if (!statusListeners.containsValue(listener)) {
return
}
var tag = ""
statusListeners.forEach {
if (it.value == listener) {
tag = it.key
statusListeners.remove(it.key)
}
}
// key2CategoryMap.remove(tag)
}
/**
* 触发监听
*/
fun invokeListener(category: MsgCategory, msgBox: MsgBoxBean) {
statusListeners.forEach {
val tag = it.key
val listener = it.value
listener.onDataChanged(category, msgBox)
}
}
}

View File

@@ -0,0 +1,45 @@
package com.mogo.eagle.core.function.call.msgbox
import com.mogo.eagle.core.data.constants.MogoServicePaths
import com.mogo.eagle.core.data.msgbox.MsgBoxBean
import com.mogo.eagle.core.function.api.msgbox.IMsgBoxProvider
import com.mogo.eagle.core.function.call.base.CallerBase
object CallerMsgBoxManager {
private val TAG = "CallerMsgBoxManager"
private val providerApi: IMsgBoxProvider?
get() = CallerBase.getApiInstance(
IMsgBoxProvider::class.java,
MogoServicePaths.PATH_MSG_BOX_MODULE
)
/**
* 存储数据到消息盒子
*/
fun saveMsgBox(bean: MsgBoxBean) {
providerApi?.saveMsg(bean)
}
/**
* 通知消息V2X、云公告、运营信息
*/
fun getNotifyData(): List<MsgBoxBean>? {
return providerApi?.getNotifyData()
}
/**
* 工控机Report信息
*/
fun getSysInfoData(): List<MsgBoxBean>? {
return providerApi?.getSysInfoData()
}
/**
* 录包信息
*/
fun getRecordBagData(): List<MsgBoxBean>? {
return providerApi?.getRecordBagData()
}
}