[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 @@
/build

View File

@@ -0,0 +1,76 @@
plugins {
id 'com.android.library'
id 'kotlin-android'
id 'kotlin-android-extensions'
id 'kotlin-kapt'
id 'com.alibaba.arouter'
}
android {
compileSdkVersion rootProject.ext.android.compileSdkVersion
defaultConfig {
minSdkVersion rootProject.ext.android.minSdkVersion
targetSdkVersion rootProject.ext.android.targetSdkVersion
versionCode Integer.valueOf(VERSION_CODE)
versionName getValueFromRootProperties("${project.name.replace("-", "_").toUpperCase()}_VERSION")
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
consumerProguardFiles 'consumer-rules.pro'
//ARouter apt 参数
kapt {
useBuildCache = false
arguments {
arg("AROUTER_MODULE_NAME", project.getName())
}
}
javaCompileOptions {
annotationProcessorOptions {
arguments = ["room.schemaLocation": "$projectDir/schemas".toString()]
}
}
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation rootProject.ext.dependencies.androidxccorektx
implementation rootProject.ext.dependencies.androidxappcompat
implementation rootProject.ext.dependencies.arouter
implementation rootProject.ext.dependencies.rxandroid
kapt rootProject.ext.dependencies.aroutercompiler
implementation rootProject.ext.dependencies.androidxroomruntime
kapt rootProject.ext.dependencies.androidxroomcompiler
implementation rootProject.ext.dependencies.androidxroomktx
if (Boolean.valueOf(USE_MAVEN_PACKAGE)) {
// implementation rootProject.ext.dependencies.modulecommon
// implementation rootProject.ext.dependencies.moduleservice
implementation rootProject.ext.dependencies.mogo_core_data
implementation rootProject.ext.dependencies.mogo_core_utils
implementation rootProject.ext.dependencies.mogo_core_function_api
implementation rootProject.ext.dependencies.mogo_core_function_call
implementation rootProject.ext.dependencies.mogo_core_res
} else {
// implementation project(':modules:mogo-module-common')
// implementation project(':modules:mogo-module-service')
implementation project(':core:mogo-core-data')
implementation project(':core:mogo-core-utils')
implementation project(':core:mogo-core-function-api')
implementation project(':core:mogo-core-function-call')
implementation project(':core:mogo-core-res')
}
}
apply from: new File(rootProject.rootDir, "gradle/upload.gradle").toString()

View File

@@ -0,0 +1,3 @@
GROUP=com.mogo.eagle.core.function.impl
POM_ARTIFACT_ID=msgbox
VERSION_CODE=1

View File

@@ -0,0 +1,21 @@
# Add project specific ProGuard rules here.
# You can control the set of applied configuration files using the
# proguardFiles setting in build.gradle.
#
# For more details, see
# http://developer.android.com/guide/developing/tools/proguard.html
# If your project uses WebView with JS, uncomment the following
# and specify the fully qualified class name to the JavaScript interface
# class:
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
# public *;
#}
# Uncomment this to preserve the line number information for
# debugging stack traces.
#-keepattributes SourceFile,LineNumberTable
# If you keep the line number information, uncomment this to
# hide the original source file name.
#-renamesourcefileattribute SourceFile

View File

@@ -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>

View File

@@ -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
}
}

View File

@@ -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() {
}
}

View File

@@ -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)
}

View File

@@ -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!!
}
}
}

View File

@@ -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
)