[opt 3.0]

[Change]
[1、修改msgbox--》datacenter]

Signed-off-by: donghongyu <donghongyu@zhidaoauto.com>
This commit is contained in:
donghongyu
2022-12-22 10:44:53 +08:00
parent 733c4d3f3d
commit 704200d03f
14 changed files with 2 additions and 2 deletions

View File

@@ -0,0 +1 @@
/build

View File

@@ -0,0 +1,70 @@
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.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
} else {
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')
}
}
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,292 @@
package com.mogo.eagle.core.function.msgbox
import android.content.Context
import android.os.Looper
import com.mogo.eagle.core.data.msgbox.*
import com.mogo.eagle.core.data.notice.NoticeNormalData
import com.mogo.eagle.core.data.report.ReportEntity
import com.mogo.eagle.core.function.call.msgbox.CallerMsgBoxListenerManager
import com.mogo.eagle.core.function.msgbox.db.MsgBoxDb
import com.mogo.eagle.core.function.msgbox.db.MsgBoxInfo
import com.mogo.eagle.core.utilcode.kotlin.lifeCycleScope
import com.mogo.eagle.core.utilcode.util.GsonUtils
import com.mogo.eagle.core.utilcode.util.Utils
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext
object DataManager {
// private val msgBoxMap: EnumMap<MsgBoxType, MutableList<MsgBoxBean>> = EnumMap(MsgBoxType::class.java)
// 消失时间5000ms
const val DISMISS_TIME = 5000L
private val notifyList by lazy {
mutableListOf<MsgBoxBean>()
}
/**
* 当天缓存的通知消息
*/
private val cacheNotifyList by lazy {
mutableListOf<MsgBoxBean>()
}
private val sysInfoList by lazy {
mutableListOf<MsgBoxBean>()
}
/**
* 当天缓存的系统消息
*/
private val cacheSysInfoList by lazy {
mutableListOf<MsgBoxBean>()
}
private val recordBagList by lazy {
mutableListOf<MsgBoxBean>()
}
/**
* 当天缓存的录包消息
*/
private val cacheRecordList by lazy {
mutableListOf<MsgBoxBean>()
}
private val scope by lazy {
Utils.getApp().lifeCycleScope
}
/**
* 用户取消给录制的Bag包打标签
*/
private val removedRecordMap by lazy {
HashMap<String, Any>()
}
/**
* 存储时保证按时序排列
*/
fun saveMsg(bean: MsgBoxBean) {
if (Thread.currentThread() == Looper.getMainLooper().thread) {
scope.launch {
withContext(Dispatchers.Default) {
realSaveMsg(bean)
}
}
} else {
realSaveMsg(bean)
}
}
private fun realSaveMsg(msg: MsgBoxBean) {
val type = msg.type
msg.timestamp = System.currentTimeMillis()
msg.bean2Json = GsonUtils.toJson(msg.bean)
when (type) {
MsgBoxType.V2X, MsgBoxType.OBU, MsgBoxType.NOTICE, MsgBoxType.OPERATION -> {
synchronized(this) {
notifyList.add(msg)
}
CallerMsgBoxListenerManager.invokeListener(MsgCategory.NOTICE, msg)
}
MsgBoxType.REPORT -> {
synchronized(this) {
sysInfoList.add(msg)
}
CallerMsgBoxListenerManager.invokeListener(MsgCategory.SYS_INFO, msg)
}
MsgBoxType.RECORD -> {
synchronized(this) {
recordBagList.add(msg)
}
CallerMsgBoxListenerManager.invokeListener(MsgCategory.RECORD_BAG, msg)
}
else -> {}
}
}
/**
* 通知消息V2X、云公告、运营信息
*/
fun getNotifyData(): List<MsgBoxBean> {
return cacheNotifyList
}
/**
* 工控机Report信息
*/
fun getSysInfoData(): List<MsgBoxBean> {
return cacheSysInfoList
}
/**
* 录包信息
*/
fun getRecordBagData(): List<MsgBoxBean> {
return cacheRecordList
}
fun removeRecordInfo(key: String, value: Any) {
removedRecordMap[key] = value
}
/**
* 从本地数据库中查询数据
*/
fun queryAllMessages(context: Context) {
scope.launch {
initCache()
getCacheMessages(context)
}
}
private fun initCache() {
if (cacheNotifyList.isNotEmpty()) {
cacheNotifyList.clear()
}
if (cacheRecordList.isNotEmpty()) {
cacheRecordList.clear()
}
if (cacheSysInfoList.isNotEmpty()) {
cacheSysInfoList.clear()
}
}
private suspend fun getCacheMessages(context: Context): List<MsgBoxBean> = withContext(Dispatchers.IO) {
return@withContext MsgBoxDb.getDb(context)
.monitorDao()
.getAllCachedMessages()
.map { msgInfo ->
val json = msgInfo.bean2Json
when (msgInfo.obj2JsonType) {
MsgBoxType.V2X.ordinal -> {
return@map MsgBoxBean(
MsgBoxType.V2X,
GsonUtils.fromJson(json, V2XMsg::class.java)
).apply {
this.timestamp = msgInfo.timeStamp
withContext(Dispatchers.Main) {
cacheNotifyList.add(this@apply)
}
}
}
MsgBoxType.OBU.ordinal -> {
return@map MsgBoxBean(
MsgBoxType.OBU,
GsonUtils.fromJson(json, V2XMsg::class.java)
).apply {
this.timestamp = msgInfo.timeStamp
withContext(Dispatchers.Main) {
cacheNotifyList.add(this@apply)
}
}
}
MsgBoxType.OPERATION.ordinal -> {
return@map MsgBoxBean(
MsgBoxType.OPERATION,
GsonUtils.fromJson(json, OperationMsg::class.java)
).apply {
this.timestamp = msgInfo.timeStamp
withContext(Dispatchers.Main) {
cacheNotifyList.add(this@apply)
}
}
}
MsgBoxType.REPORT.ordinal -> {
return@map MsgBoxBean(
MsgBoxType.REPORT,
GsonUtils.fromJson(json, ReportEntity::class.java)
).apply {
this.timestamp = msgInfo.timeStamp
withContext(Dispatchers.Main) {
cacheSysInfoList.add(this@apply)
}
}
}
MsgBoxType.RECORD.ordinal -> {
return@map MsgBoxBean(
MsgBoxType.RECORD,
GsonUtils.fromJson(json, RecordBagMsg::class.java)
).apply {
this.timestamp = msgInfo.timeStamp
withContext(Dispatchers.Main) {
cacheRecordList.add(this@apply)
}
}
}
MsgBoxType.NOTICE.ordinal -> {
return@map MsgBoxBean(
MsgBoxType.NOTICE,
GsonUtils.fromJson(json, NoticeFrCloudMsg::class.java)
).apply {
this.timestamp = msgInfo.timeStamp
withContext(Dispatchers.Main) {
cacheNotifyList.add(this@apply)
}
}
}
else -> {
return@map MsgBoxBean(MsgBoxType.V2X, V2XMsg())
}
}
}
}
/**
* 存储到本地数据库
*/
fun saveAllMessages2Disk(context: Context) {
synchronized(this) {
val msgInfoList = ArrayList<MsgBoxInfo>()
if (notifyList.isNotEmpty()) {
notifyList.forEach {
msgInfoList.add(MsgBoxInfo(it.bean2Json, it.type.ordinal, it.timestamp))
}
notifyList.clear()
}
if (sysInfoList.isNotEmpty()) {
sysInfoList.forEach {
msgInfoList.add(MsgBoxInfo(it.bean2Json, it.type.ordinal, it.timestamp))
}
sysInfoList.clear()
}
if (recordBagList.isNotEmpty()) {
recordBagList.forEach {
var recordKey = ""
if (it.bean is RecordBagMsg) {
recordKey = (it.bean as RecordBagMsg).key.toString()
}
// 用户未处理的Bag包才存本地
if (!removedRecordMap.contains(recordKey)) {
msgInfoList.add(MsgBoxInfo(it.bean2Json, it.type.ordinal, it.timestamp))
} else {// 用户已处理的Bag包
removedRecordMap.remove(recordKey)
}
}
recordBagList.clear()
}
if (msgInfoList.isNotEmpty()) {
MsgBoxDb.getDb(context)
.monitorDao()
.insertMessages(*msgInfoList.toTypedArray())
}
}
}
fun delMsgBoxBean(context: Context, msgBoxBean: MsgBoxBean) {
scope.launch {
withContext(Dispatchers.Default) {
val msgBoxInfo = MsgBoxInfo(msgBoxBean.bean2Json, msgBoxBean.type.ordinal, msgBoxBean.timestamp)
MsgBoxDb.getDb(context)
.monitorDao()
.deleteMsg(msgBoxInfo)
}
}
}
}

View File

@@ -0,0 +1,42 @@
package com.mogo.eagle.core.function.msgbox
import com.mogo.eagle.core.data.msgbox.MsgBoxBean
import com.mogo.eagle.core.utilcode.util.SPUtils
/**
* @author XuXinChao
* @description 消息盒子配置
* @since: 2022/12/1
*/
class MsgBoxConfig {
companion object{
//当前用户的Tab选择记录
private const val userRecord = "USER_RECORD"
/**
* 获取当前用户Tab选择记录
*/
fun getUserRecord(): Int{
return SPUtils.getInstance().getInt(userRecord,0)
}
/**
* 设置当前用户Tab选择记录
*/
fun setUserRecord(record: Int){
SPUtils.getInstance().put(userRecord,record)
}
//通知消息缓存列表
@JvmField
var noticeList: ArrayList<MsgBoxBean> = ArrayList()
//车辆系统信息缓存列表
@JvmField
var systemInfoList: ArrayList<MsgBoxBean> = ArrayList()
//录包信息缓存列表
@JvmField
var recordBagList: ArrayList<MsgBoxBean> = ArrayList()
}
}

View File

@@ -0,0 +1,61 @@
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
import com.mogo.eagle.core.function.msgbox.DataManager.saveAllMessages2Disk
@Route(path = PATH_MSG_BOX_MODULE)
class MsgBoxProvider : IMsgBoxProvider {
override val functionName: String
get() = "MsgBoxProvider"
override fun init(context: Context) {
Thread {
while (true) {
try {
saveAllMessages2Disk(context)
Thread.sleep(3000)
} catch (e: Exception) {
e.printStackTrace()
}
}
}.start()
}
override fun queryAllMessages(context: Context) {
DataManager.queryAllMessages(context)
}
override fun saveMsg(bean: MsgBoxBean) {
DataManager.saveMsg(bean)
}
override fun getCachedNotifyData(): List<MsgBoxBean> {
return DataManager.getNotifyData()
}
override fun getCachedSysInfoData(): List<MsgBoxBean> {
return DataManager.getSysInfoData()
}
override fun getCachedRecordBagData(): List<MsgBoxBean> {
return DataManager.getRecordBagData()
}
override fun removeRecordInfo(context: Context, msgBoxBean: MsgBoxBean, key: String) {
DataManager.removeRecordInfo(key, key)
DataManager.delMsgBoxBean(context, msgBoxBean)
}
override fun getDismissTime(): Long {
return DataManager.DISMISS_TIME
}
override fun onDestroy() {
}
}

View File

@@ -0,0 +1,18 @@
package com.mogo.eagle.core.function.msgbox.db
import androidx.room.*
@Dao
interface MsgBoxDao {
@Insert(onConflict = OnConflictStrategy.REPLACE)
fun insertMessage(info: MsgBoxInfo)
@Insert(onConflict = OnConflictStrategy.REPLACE)
fun insertMessages(vararg info: MsgBoxInfo)
@Delete
suspend fun deleteMsg(info: MsgBoxInfo)
@Query("SELECT * FROM t_msg_box")
fun getAllCachedMessages(): List<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,18 @@
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
@ColumnInfo(name = "obj_json")
val bean2Json: String,
@ColumnInfo(name = "json_obj_type")
val obj2JsonType: Int = 0,
@ColumnInfo(name = "time_stamp")
val timeStamp: Long = 0
)