diff --git a/core/function-impl/mogo-core-function-msgbox/.gitignore b/core/function-impl/mogo-core-function-msgbox/.gitignore new file mode 100644 index 0000000000..42afabfd2a --- /dev/null +++ b/core/function-impl/mogo-core-function-msgbox/.gitignore @@ -0,0 +1 @@ +/build \ No newline at end of file diff --git a/core/function-impl/mogo-core-function-msgbox/build.gradle b/core/function-impl/mogo-core-function-msgbox/build.gradle new file mode 100644 index 0000000000..ea1bfe7e00 --- /dev/null +++ b/core/function-impl/mogo-core-function-msgbox/build.gradle @@ -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() diff --git a/core/function-impl/mogo-core-function-msgbox/consumer-rules.pro b/core/function-impl/mogo-core-function-msgbox/consumer-rules.pro new file mode 100644 index 0000000000..e69de29bb2 diff --git a/core/function-impl/mogo-core-function-msgbox/gradle.properties b/core/function-impl/mogo-core-function-msgbox/gradle.properties new file mode 100644 index 0000000000..c2480b1b61 --- /dev/null +++ b/core/function-impl/mogo-core-function-msgbox/gradle.properties @@ -0,0 +1,3 @@ +GROUP=com.mogo.eagle.core.function.impl +POM_ARTIFACT_ID=msgbox +VERSION_CODE=1 diff --git a/core/function-impl/mogo-core-function-msgbox/proguard-rules.pro b/core/function-impl/mogo-core-function-msgbox/proguard-rules.pro new file mode 100644 index 0000000000..481bb43481 --- /dev/null +++ b/core/function-impl/mogo-core-function-msgbox/proguard-rules.pro @@ -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 \ No newline at end of file diff --git a/core/function-impl/mogo-core-function-msgbox/src/main/AndroidManifest.xml b/core/function-impl/mogo-core-function-msgbox/src/main/AndroidManifest.xml new file mode 100644 index 0000000000..d53664eb7c --- /dev/null +++ b/core/function-impl/mogo-core-function-msgbox/src/main/AndroidManifest.xml @@ -0,0 +1,6 @@ + + + + + \ No newline at end of file diff --git a/core/function-impl/mogo-core-function-msgbox/src/main/java/com/mogo/eagle/core/function/msgbox/DataManager.kt b/core/function-impl/mogo-core-function-msgbox/src/main/java/com/mogo/eagle/core/function/msgbox/DataManager.kt new file mode 100644 index 0000000000..385613203b --- /dev/null +++ b/core/function-impl/mogo-core-function-msgbox/src/main/java/com/mogo/eagle/core/function/msgbox/DataManager.kt @@ -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> = EnumMap(MsgBoxType::class.java) + + private val notifyList by lazy { + mutableListOf() + } + + private val sysInfoList by lazy { + mutableListOf() + } + + private val recordBagList by lazy { + mutableListOf() + } + + @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 { + return notifyList + } + + /** + * 工控机Report信息 + */ + fun getSysInfoData(): List { + return sysInfoList + } + + /** + * 录包信息 + */ + fun getRecordBagData(): List { + return recordBagList + } +} \ No newline at end of file diff --git a/core/function-impl/mogo-core-function-msgbox/src/main/java/com/mogo/eagle/core/function/msgbox/MsgBoxProvider.kt b/core/function-impl/mogo-core-function-msgbox/src/main/java/com/mogo/eagle/core/function/msgbox/MsgBoxProvider.kt new file mode 100644 index 0000000000..b58206e909 --- /dev/null +++ b/core/function-impl/mogo-core-function-msgbox/src/main/java/com/mogo/eagle/core/function/msgbox/MsgBoxProvider.kt @@ -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 { + return DataManager.getNotifyData() + } + + override fun getSysInfoData(): List { + return DataManager.getSysInfoData() + } + + override fun getRecordBagData(): List { + return DataManager.getRecordBagData() + } + + override fun onDestroy() { + + } +} \ No newline at end of file diff --git a/core/function-impl/mogo-core-function-msgbox/src/main/java/com/mogo/eagle/core/function/msgbox/db/MsgBoxDao.kt b/core/function-impl/mogo-core-function-msgbox/src/main/java/com/mogo/eagle/core/function/msgbox/db/MsgBoxDao.kt new file mode 100644 index 0000000000..1ffddc4182 --- /dev/null +++ b/core/function-impl/mogo-core-function-msgbox/src/main/java/com/mogo/eagle/core/function/msgbox/db/MsgBoxDao.kt @@ -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) +} \ No newline at end of file diff --git a/core/function-impl/mogo-core-function-msgbox/src/main/java/com/mogo/eagle/core/function/msgbox/db/MsgBoxDb.kt b/core/function-impl/mogo-core-function-msgbox/src/main/java/com/mogo/eagle/core/function/msgbox/db/MsgBoxDb.kt new file mode 100644 index 0000000000..1fb9f58ff9 --- /dev/null +++ b/core/function-impl/mogo-core-function-msgbox/src/main/java/com/mogo/eagle/core/function/msgbox/db/MsgBoxDb.kt @@ -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!! + } + } +} \ No newline at end of file diff --git a/core/function-impl/mogo-core-function-msgbox/src/main/java/com/mogo/eagle/core/function/msgbox/db/MsgBoxInfo.kt b/core/function-impl/mogo-core-function-msgbox/src/main/java/com/mogo/eagle/core/function/msgbox/db/MsgBoxInfo.kt new file mode 100644 index 0000000000..14dd1b667a --- /dev/null +++ b/core/function-impl/mogo-core-function-msgbox/src/main/java/com/mogo/eagle/core/function/msgbox/db/MsgBoxInfo.kt @@ -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 +) \ No newline at end of file diff --git a/core/mogo-core-data/src/main/java/com/mogo/eagle/core/data/constants/MogoServicePaths.java b/core/mogo-core-data/src/main/java/com/mogo/eagle/core/data/constants/MogoServicePaths.java index fb05de9da6..0b2ca7cbbe 100644 --- a/core/mogo-core-data/src/main/java/com/mogo/eagle/core/data/constants/MogoServicePaths.java +++ b/core/mogo-core-data/src/main/java/com/mogo/eagle/core/data/constants/MogoServicePaths.java @@ -150,4 +150,7 @@ public class MogoServicePaths { */ @Keep public static final String PATH_TELEMATIC_PROVIDER = "/telematic/api"; + + @Keep + public static final String PATH_MSG_BOX_MODULE = "/msg_box/api"; } diff --git a/core/mogo-core-data/src/main/java/com/mogo/eagle/core/data/msgbox/MsgBoxBean.kt b/core/mogo-core-data/src/main/java/com/mogo/eagle/core/data/msgbox/MsgBoxBean.kt new file mode 100644 index 0000000000..171d472e6b --- /dev/null +++ b/core/mogo-core-data/src/main/java/com/mogo/eagle/core/data/msgbox/MsgBoxBean.kt @@ -0,0 +1,3 @@ +package com.mogo.eagle.core.data.msgbox + +data class MsgBoxBean(val type: MsgBoxType, val bean: Any, var timestamp: Long = 0) diff --git a/core/mogo-core-data/src/main/java/com/mogo/eagle/core/data/msgbox/MsgBoxType.kt b/core/mogo-core-data/src/main/java/com/mogo/eagle/core/data/msgbox/MsgBoxType.kt new file mode 100644 index 0000000000..fa474bb89e --- /dev/null +++ b/core/mogo-core-data/src/main/java/com/mogo/eagle/core/data/msgbox/MsgBoxType.kt @@ -0,0 +1,5 @@ +package com.mogo.eagle.core.data.msgbox + +enum class MsgBoxType { + OPERATION, NOTICE, V2X, OBU, REPORT, RECORD, TRAFFIC +} \ No newline at end of file diff --git a/core/mogo-core-data/src/main/java/com/mogo/eagle/core/data/msgbox/MsgCategory.kt b/core/mogo-core-data/src/main/java/com/mogo/eagle/core/data/msgbox/MsgCategory.kt new file mode 100644 index 0000000000..095e9ed4d8 --- /dev/null +++ b/core/mogo-core-data/src/main/java/com/mogo/eagle/core/data/msgbox/MsgCategory.kt @@ -0,0 +1,5 @@ +package com.mogo.eagle.core.data.msgbox + +enum class MsgCategory { + NOTICE, SYS_INFO, RECORD_BAG +} \ No newline at end of file diff --git a/core/mogo-core-data/src/main/java/com/mogo/eagle/core/data/msgbox/OperationMsg.kt b/core/mogo-core-data/src/main/java/com/mogo/eagle/core/data/msgbox/OperationMsg.kt new file mode 100644 index 0000000000..b3aa9469ff --- /dev/null +++ b/core/mogo-core-data/src/main/java/com/mogo/eagle/core/data/msgbox/OperationMsg.kt @@ -0,0 +1,6 @@ +package com.mogo.eagle.core.data.msgbox + +/** + * 运营消息:-1表示初始值 + */ +data class OperationMsg(val timestamp : Long, val content: String, val type: Int = -1) diff --git a/core/mogo-core-function-api/src/main/java/com/mogo/eagle/core/function/api/msgbox/IMsgBoxListener.kt b/core/mogo-core-function-api/src/main/java/com/mogo/eagle/core/function/api/msgbox/IMsgBoxListener.kt new file mode 100644 index 0000000000..f09b416e68 --- /dev/null +++ b/core/mogo-core-function-api/src/main/java/com/mogo/eagle/core/function/api/msgbox/IMsgBoxListener.kt @@ -0,0 +1,13 @@ +package com.mogo.eagle.core.function.api.msgbox + +import com.mogo.eagle.core.data.msgbox.MsgBoxBean +import com.mogo.eagle.core.data.msgbox.MsgCategory + +/** + * @author chenfufeng + * @date 2022/11/21 + * 消息盒子的数据回调 + */ +interface IMsgBoxListener { + fun onDataChanged(category: MsgCategory, msgBoxList: MsgBoxBean) +} \ No newline at end of file diff --git a/core/mogo-core-function-api/src/main/java/com/mogo/eagle/core/function/api/msgbox/IMsgBoxProvider.kt b/core/mogo-core-function-api/src/main/java/com/mogo/eagle/core/function/api/msgbox/IMsgBoxProvider.kt new file mode 100644 index 0000000000..254ca20d6c --- /dev/null +++ b/core/mogo-core-function-api/src/main/java/com/mogo/eagle/core/function/api/msgbox/IMsgBoxProvider.kt @@ -0,0 +1,22 @@ +package com.mogo.eagle.core.function.api.msgbox + +import com.mogo.eagle.core.data.msgbox.MsgBoxBean +import com.mogo.eagle.core.function.api.base.IMoGoFunctionServerProvider + +interface IMsgBoxProvider: IMoGoFunctionServerProvider { + fun saveMsg(bean: MsgBoxBean) + + /** + * 通知消息:V2X、云公告、运营信息 + */ + fun getNotifyData(): List + /** + * 工控机Report信息 + */ + fun getSysInfoData(): List + + /** + * 录包信息 + */ + fun getRecordBagData(): List +} \ No newline at end of file diff --git a/core/mogo-core-function-call/src/main/java/com/mogo/eagle/core/function/call/msgbox/CallerMsgBoxListenerManager.kt b/core/mogo-core-function-call/src/main/java/com/mogo/eagle/core/function/call/msgbox/CallerMsgBoxListenerManager.kt new file mode 100644 index 0000000000..246a7d8c74 --- /dev/null +++ b/core/mogo-core-function-call/src/main/java/com/mogo/eagle/core/function/call/msgbox/CallerMsgBoxListenerManager.kt @@ -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 = + ConcurrentHashMap() + +// private val key2CategoryMap by lazy { +// ConcurrentHashMap() +// } + + /** + * 添加数据监听 + * @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) + } + } +} \ No newline at end of file diff --git a/core/mogo-core-function-call/src/main/java/com/mogo/eagle/core/function/call/msgbox/CallerMsgBoxManager.kt b/core/mogo-core-function-call/src/main/java/com/mogo/eagle/core/function/call/msgbox/CallerMsgBoxManager.kt new file mode 100644 index 0000000000..e94b38e74f --- /dev/null +++ b/core/mogo-core-function-call/src/main/java/com/mogo/eagle/core/function/call/msgbox/CallerMsgBoxManager.kt @@ -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? { + return providerApi?.getNotifyData() + } + + /** + * 工控机Report信息 + */ + fun getSysInfoData(): List? { + return providerApi?.getSysInfoData() + } + + /** + * 录包信息 + */ + fun getRecordBagData(): List? { + return providerApi?.getRecordBagData() + } +} \ No newline at end of file diff --git a/settings.gradle b/settings.gradle index cb06172693..f0b654ad1f 100644 --- a/settings.gradle +++ b/settings.gradle @@ -48,6 +48,8 @@ include ':core:function-impl:mogo-core-function-dispatch' include ':core:function-impl:mogo-core-function-bindingcar' // 车聊聊业务 include ':core:function-impl:mogo-core-function-chat' +// 消息盒子 +include ':core:function-impl:mogo-core-function-msgbox' // 服务 include ':services:mogo-service-api'