[Feat]新增消息盒子数据中心
This commit is contained in:
@@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
package="com.mogo.eagle.core.function.msgbox">
|
||||
<application>
|
||||
</application>
|
||||
</manifest>
|
||||
@@ -0,0 +1,95 @@
|
||||
package com.mogo.eagle.core.function.msgbox
|
||||
|
||||
import android.os.Looper
|
||||
import com.mogo.eagle.core.data.msgbox.MsgBoxBean
|
||||
import com.mogo.eagle.core.data.msgbox.MsgBoxType
|
||||
import com.mogo.eagle.core.data.msgbox.MsgCategory
|
||||
import com.mogo.eagle.core.function.call.msgbox.CallerMsgBoxListenerManager
|
||||
import com.mogo.eagle.core.utilcode.kotlin.lifeCycleScope
|
||||
import com.mogo.eagle.core.utilcode.util.Utils
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.launch
|
||||
|
||||
object DataManager {
|
||||
|
||||
// private val msgBoxMap: EnumMap<MsgBoxType, MutableList<MsgBoxBean>> = EnumMap(MsgBoxType::class.java)
|
||||
|
||||
private val notifyList by lazy {
|
||||
mutableListOf<MsgBoxBean>()
|
||||
}
|
||||
|
||||
private val sysInfoList by lazy {
|
||||
mutableListOf<MsgBoxBean>()
|
||||
}
|
||||
|
||||
private val recordBagList by lazy {
|
||||
mutableListOf<MsgBoxBean>()
|
||||
}
|
||||
|
||||
@Volatile
|
||||
private var isUpdate = false
|
||||
|
||||
private val scope by lazy {
|
||||
Utils.getApp().lifeCycleScope
|
||||
}
|
||||
|
||||
/**
|
||||
* 存储时保证按时序排列
|
||||
*/
|
||||
fun saveMsg(bean: MsgBoxBean) {
|
||||
if (Thread.currentThread() == Looper.getMainLooper().thread) {
|
||||
scope.launch(Dispatchers.Default) {
|
||||
realSaveMsg(bean)
|
||||
}
|
||||
} else {
|
||||
realSaveMsg(bean)
|
||||
}
|
||||
}
|
||||
|
||||
fun realSaveMsg(bean: MsgBoxBean) {
|
||||
val type = bean.type
|
||||
bean.timestamp = System.currentTimeMillis()
|
||||
when(type) {
|
||||
MsgBoxType.V2X, MsgBoxType.OBU, MsgBoxType.NOTICE, MsgBoxType.OPERATION -> {
|
||||
synchronized(this) {
|
||||
notifyList.add(bean)
|
||||
}
|
||||
CallerMsgBoxListenerManager.invokeListener(MsgCategory.NOTICE, bean)
|
||||
}
|
||||
MsgBoxType.REPORT -> {
|
||||
synchronized(this) {
|
||||
sysInfoList.add(bean)
|
||||
}
|
||||
CallerMsgBoxListenerManager.invokeListener(MsgCategory.SYS_INFO, bean)
|
||||
}
|
||||
MsgBoxType.RECORD -> {
|
||||
synchronized(this) {
|
||||
recordBagList.add(bean)
|
||||
}
|
||||
CallerMsgBoxListenerManager.invokeListener(MsgCategory.RECORD_BAG, bean)
|
||||
}
|
||||
else -> {}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 通知消息:V2X、云公告、运营信息
|
||||
*/
|
||||
fun getNotifyData(): List<MsgBoxBean> {
|
||||
return notifyList
|
||||
}
|
||||
|
||||
/**
|
||||
* 工控机Report信息
|
||||
*/
|
||||
fun getSysInfoData(): List<MsgBoxBean> {
|
||||
return sysInfoList
|
||||
}
|
||||
|
||||
/**
|
||||
* 录包信息
|
||||
*/
|
||||
fun getRecordBagData(): List<MsgBoxBean> {
|
||||
return recordBagList
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
package com.mogo.eagle.core.function.msgbox
|
||||
|
||||
import android.content.Context
|
||||
import com.alibaba.android.arouter.facade.annotation.Route
|
||||
import com.mogo.eagle.core.data.constants.MogoServicePaths.PATH_MSG_BOX_MODULE
|
||||
import com.mogo.eagle.core.data.msgbox.MsgBoxBean
|
||||
import com.mogo.eagle.core.function.api.msgbox.IMsgBoxProvider
|
||||
|
||||
@Route(path = PATH_MSG_BOX_MODULE)
|
||||
class MsgBoxProvider : IMsgBoxProvider {
|
||||
|
||||
override val functionName: String
|
||||
get() = "MsgBoxProvider"
|
||||
|
||||
override fun init(context: Context) {
|
||||
context
|
||||
}
|
||||
|
||||
override fun saveMsg(bean: MsgBoxBean) {
|
||||
DataManager.saveMsg(bean)
|
||||
}
|
||||
|
||||
override fun getNotifyData(): List<MsgBoxBean> {
|
||||
return DataManager.getNotifyData()
|
||||
}
|
||||
|
||||
override fun getSysInfoData(): List<MsgBoxBean> {
|
||||
return DataManager.getSysInfoData()
|
||||
}
|
||||
|
||||
override fun getRecordBagData(): List<MsgBoxBean> {
|
||||
return DataManager.getRecordBagData()
|
||||
}
|
||||
|
||||
override fun onDestroy() {
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
package com.mogo.eagle.core.function.msgbox.db
|
||||
|
||||
import androidx.room.*
|
||||
|
||||
@Dao
|
||||
interface MsgBoxDao {
|
||||
@Insert(onConflict = OnConflictStrategy.REPLACE)
|
||||
fun saveMsg(info: MsgBoxInfo)
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
package com.mogo.eagle.core.function.msgbox.db
|
||||
|
||||
import android.content.Context
|
||||
import androidx.room.Database
|
||||
import androidx.room.Room
|
||||
import androidx.room.RoomDatabase
|
||||
|
||||
@Database(entities = [MsgBoxInfo::class], version = 1, exportSchema = false)
|
||||
abstract class MsgBoxDb: RoomDatabase() {
|
||||
abstract fun monitorDao(): MsgBoxDao
|
||||
|
||||
companion object {
|
||||
const val INTERNAL_DB_NAME = "msg_box.db"
|
||||
|
||||
private var db: MsgBoxDb? = null
|
||||
|
||||
@JvmStatic
|
||||
fun getDb(context: Context): MsgBoxDb {
|
||||
if (db == null) {
|
||||
db = Room.databaseBuilder(context.applicationContext, MsgBoxDb::class.java, INTERNAL_DB_NAME)
|
||||
.fallbackToDestructiveMigration()
|
||||
.build()
|
||||
}
|
||||
return db!!
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
package com.mogo.eagle.core.function.msgbox.db
|
||||
|
||||
import androidx.room.ColumnInfo
|
||||
import androidx.room.Entity
|
||||
import androidx.room.PrimaryKey
|
||||
|
||||
@Entity(tableName = "t_msg_box")
|
||||
data class MsgBoxInfo(
|
||||
@PrimaryKey(autoGenerate = true)
|
||||
@ColumnInfo(name = "id")
|
||||
val uuid: Long = 0,
|
||||
|
||||
@ColumnInfo(name = "obj_str")
|
||||
val objString: String
|
||||
)
|
||||
Reference in New Issue
Block a user