[2.13.0-arch-opt] code opt

This commit is contained in:
zhongchao
2023-03-03 15:02:29 +08:00
parent d30cbb2bda
commit 835a547ad8
10 changed files with 141 additions and 178 deletions

View File

@@ -1,26 +1,35 @@
package com.mogo.eagle.core.function.msgbox
import android.annotation.SuppressLint
import android.content.Context
import android.os.Looper
import com.mogo.eagle.core.data.deva.report.ReportEntity
import com.mogo.eagle.core.data.enums.DataSourceType
import com.mogo.eagle.core.data.msgbox.*
import com.mogo.eagle.core.data.deva.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.mogo.logger.CallerLogger
import com.mogo.eagle.core.utilcode.mogo.logger.CallerLogger.e
import com.mogo.eagle.core.utilcode.util.GsonUtils
import com.mogo.eagle.core.utilcode.util.ProcessUtils
import com.mogo.eagle.core.utilcode.util.SPUtils
import com.mogo.eagle.core.utilcode.util.Utils
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.delay
import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext
import java.io.File
import java.text.SimpleDateFormat
import java.util.*
object DataManager {
// private val msgBoxMap: EnumMap<MsgBoxType, MutableList<MsgBoxBean>> = EnumMap(MsgBoxType::class.java)
const val TAG = "DataManager"
// 消失时间5000ms
const val DISMISS_TIME = 5000L
@@ -148,6 +157,10 @@ object DataManager {
* 从本地数据库中查询数据
*/
fun queryAllMessages(context: Context) {
if (!ProcessUtils.isMainProcess(context)) {
return
}
clearMessageBoxTable(context)
scope.launch {
initCache()
try {
@@ -158,6 +171,38 @@ object DataManager {
}
}
@SuppressLint("SimpleDateFormat")
private fun clearMessageBoxTable(context: Context) {
Thread {
val lastLaunchTimeStr = SPUtils.getInstance().getString("last_launch", "")
val format = SimpleDateFormat("yyyy-MM-dd")
val currDate = Date(System.currentTimeMillis())
val currTimeStr = format.format(currDate)
try {
if (lastLaunchTimeStr != null && lastLaunchTimeStr.isNotEmpty()) {
val isSameDay = currTimeStr == lastLaunchTimeStr
// 超过一天需要清除消息盒子中的数据并把时间戳存入SP
if (!isSameDay) {
val file: File = context.getDatabasePath(MsgBoxDb.INTERNAL_DB_NAME)
if (file != null && file.exists()) {
context.deleteDatabase(MsgBoxDb.INTERNAL_DB_NAME)
}
SPUtils.getInstance().put("last_launch", currTimeStr)
}
} else {
// 首次使用App或中途仅删除sp文件
val file: File = context.getDatabasePath(MsgBoxDb.INTERNAL_DB_NAME)
if (file != null && file.exists()) {
context.deleteDatabase(MsgBoxDb.INTERNAL_DB_NAME)
}
SPUtils.getInstance().put("last_launch", currTimeStr)
}
} catch (e: Exception) {
e(TAG, e.message)
}
}.start()
}
private fun initCache() {
if (cacheNotifyList.isNotEmpty()) {
cacheNotifyList.clear()
@@ -170,86 +215,87 @@ object DataManager {
}
}
private suspend fun getCacheMessages(context: Context): List<MsgBoxBean> = withContext(Dispatchers.IO) {
delay(2000)
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)
private suspend fun getCacheMessages(context: Context): List<MsgBoxBean> =
withContext(Dispatchers.IO) {
delay(2000)
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.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.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.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.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)
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())
else -> {
return@map MsgBoxBean(MsgBoxType.V2X, V2XMsg())
}
}
}
}
}
}
/**
* 存储到本地数据库
@@ -298,7 +344,8 @@ object DataManager {
fun delMsgBoxBean(context: Context, msgBoxBean: MsgBoxBean) {
scope.launch {
withContext(Dispatchers.Default) {
val msgBoxInfo = MsgBoxInfo(msgBoxBean.bean2Json, msgBoxBean.type.ordinal, msgBoxBean.timestamp)
val msgBoxInfo =
MsgBoxInfo(msgBoxBean.bean2Json, msgBoxBean.type.ordinal, msgBoxBean.timestamp)
MsgBoxDb.getDb(context)
.monitorDao()
.deleteMsg(msgBoxInfo)

View File

@@ -173,9 +173,6 @@ class DevaToolsProvider : IDevaToolsProvider {
override fun updateUpgradeProgress() {
upgradeManager.updateUpgradeProgress(mContext!!)
}
override fun updateObuUpgradeStatus() {
upgradeManager.updateObuUpgradeStatus(mContext!!)
}

View File

@@ -1,36 +0,0 @@
package com.mogo.eagle.core.function.hmi.ui.setting
import android.content.Context
import android.util.AttributeSet
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
/**
* @author XuXinChao
* @description fix java.lang.IndexOutOfBoundsException检测到不一致。视图持有者适配器positionViewHolder无效
* @since: 2022/6/7
*/
class WrapContentLinearLayoutManager : LinearLayoutManager {
constructor(context: Context?) : super(context) {}
constructor(context: Context?, orientation: Int, reverseLayout: Boolean) : super(
context,
orientation,
reverseLayout
) {}
constructor(
context: Context?,
attrs: AttributeSet?,
defStyleAttr: Int,
defStyleRes: Int
) : super(context, attrs, defStyleAttr, defStyleRes) {}
override fun onLayoutChildren(recycler: RecyclerView.Recycler?, state: RecyclerView.State?) {
try {
super.onLayoutChildren(recycler, state)
} catch (e: IndexOutOfBoundsException) {
e.printStackTrace()
}
}
}

View File

@@ -40,6 +40,7 @@ class PncActionsView @JvmOverloads constructor(
@Volatile
private var mTrafficLightResult: TrafficLightResult? = null
@Volatile
private var mAutoPilotStatusInfo: AutopilotStatusInfo? = null
private val bgResources: Int

View File

@@ -11,6 +11,7 @@ import android.view.View
import com.mogo.eagle.core.function.api.setting.IMoGoSkinModeChangeListener
import com.mogo.eagle.core.function.call.setting.CallerSkinModeListenerManager
import com.mogo.eagle.core.function.hmi.R
import com.mogo.eagle.core.utilcode.util.ThreadUtils
import kotlin.math.abs
@@ -139,17 +140,19 @@ class BatteryView : View , IMoGoSkinModeChangeListener {
}
override fun onSkinModeChange(skinMode: Int) {
when (skinMode) {
0 -> {
batteryColor = resources.getColor(R.color.color_27FFFFFF)
powerColor = Color.WHITE
}
1 -> {
batteryColor = resources.getColor(R.color.color_1E111111)
powerColor = resources.getColor(R.color.color_2C2E30)
ThreadUtils.runOnUiThread {
when (skinMode) {
0 -> {
batteryColor = resources.getColor(R.color.color_27FFFFFF)
powerColor = Color.WHITE
}
1 -> {
batteryColor = resources.getColor(R.color.color_1E111111)
powerColor = resources.getColor(R.color.color_2C2E30)
}
}
invalidate()
}
invalidate()
}
override fun onAttachedToWindow() {

View File

@@ -29,7 +29,9 @@ class CheckSystemView @JvmOverloads constructor(
const val TAG = "CheckSystemView"
}
@Volatile
private var connectStatus = false //是否连接工控机
@Volatile
private var autopilotStatus: Int? = null //自动驾驶状态 0代表不可自动驾驶,1代表可自动驾驶,2代表自动驾驶中
private var dockerRebootDialog: DockerRebootDialog? = null

View File

@@ -14,6 +14,7 @@ import com.mogo.eagle.core.function.call.hmi.CallerHmiViewControlListenerManager
import com.mogo.eagle.core.function.call.setting.CallerSkinModeListenerManager
import com.mogo.eagle.core.function.hmi.R
import com.mogo.eagle.core.utilcode.util.BarUtils
import com.mogo.eagle.core.utilcode.util.ThreadUtils
import kotlinx.android.synthetic.main.view_status_bar.view.*
import java.util.concurrent.CopyOnWriteArrayList
@@ -55,9 +56,11 @@ class StatusBarView @JvmOverloads constructor(
}
override fun onSkinModeChange(skinMode: Int) {
when (skinMode) {
0 -> setStatusBarDarkOrLight(false)
1 -> setStatusBarDarkOrLight(true)
ThreadUtils.runOnUiThread {
when (skinMode) {
0 -> setStatusBarDarkOrLight(false)
1 -> setStatusBarDarkOrLight(true)
}
}
}

View File

@@ -2,7 +2,6 @@ package com.mogo.eagle.core.function.main;
import static com.mogo.eagle.core.utilcode.mogo.logger.scene.SceneConstant.M_HMI;
import android.annotation.SuppressLint;
import android.content.Context;
import android.os.Process;
@@ -18,20 +17,15 @@ import com.mogo.eagle.core.data.constants.MogoServicePaths;
import com.mogo.eagle.core.function.api.chat.biz.ChatConsts;
import com.mogo.eagle.core.function.call.devatools.CallerDevaToolsManager;
import com.mogo.eagle.core.function.call.msgbox.CallerMsgBoxManager;
import com.mogo.eagle.core.function.msgbox.db.MsgBoxDb;
import com.mogo.eagle.core.utilcode.mogo.AppIdentityModeUtils;
import com.mogo.eagle.core.utilcode.mogo.AppLaunchTimeUtils;
import com.mogo.eagle.core.utilcode.mogo.logger.CallerLogger;
import com.mogo.eagle.core.utilcode.util.ProcessUtils;
import com.mogo.eagle.core.utilcode.util.SPUtils;
import java.io.File;
import java.lang.reflect.Field;
import java.text.SimpleDateFormat;
import java.util.Date;
/**
* 默认初始化一些基础服务配置 todo 分离 msgBox去自己的模块中 --- 扶风
* 默认初始化一些基础服务配置
*/
public abstract class MainMoGoApplication extends AbsMogoApplication {
@@ -50,12 +44,8 @@ public abstract class MainMoGoApplication extends AbsMogoApplication {
initLogConfig();
initTipToast();
initModules();
if (ProcessUtils.isMainProcess(this)) {
clearMessageBoxTable();
CallerMsgBoxManager.INSTANCE.queryAllMessages(this);
}
CallerMsgBoxManager.INSTANCE.queryAllMessages(this);
CallerDevaToolsManager.INSTANCE.updateUpgradeProgress();
CallerDevaToolsManager.INSTANCE.updateObuUpgradeStatus();
}
@Override
@@ -64,38 +54,6 @@ public abstract class MainMoGoApplication extends AbsMogoApplication {
return true;
}
@SuppressLint("SimpleDateFormat")
private void clearMessageBoxTable() {
new Thread(() -> {
String lastLaunchTimeStr = SPUtils.getInstance().getString("last_launch", "");
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
Date currDate = new Date(System.currentTimeMillis());
String currTimeStr = format.format(currDate);
try {
if (lastLaunchTimeStr != null && !lastLaunchTimeStr.isEmpty()) {
boolean isSameDay = currTimeStr.equals(lastLaunchTimeStr);
// 超过一天需要清除消息盒子中的数据并把时间戳存入SP
if (!isSameDay) {
File file = this.getDatabasePath(MsgBoxDb.INTERNAL_DB_NAME);
if (file != null && file.exists()) {
this.deleteDatabase(MsgBoxDb.INTERNAL_DB_NAME);
}
SPUtils.getInstance().put("last_launch", currTimeStr);
}
} else {
// 首次使用App或中途仅删除sp文件
File file = this.getDatabasePath(MsgBoxDb.INTERNAL_DB_NAME);
if (file != null && file.exists()) {
this.deleteDatabase(MsgBoxDb.INTERNAL_DB_NAME);
}
SPUtils.getInstance().put("last_launch", currTimeStr);
}
} catch (Exception e) {
CallerLogger.INSTANCE.e(TAG, e.getMessage());
}
}).start();
}
/**
* 初始化异常采集配置
*/
@@ -126,11 +84,11 @@ public abstract class MainMoGoApplication extends AbsMogoApplication {
MogoModulePaths.addModuleFunctionServer(new MogoModule(MogoServicePaths.PATH_V2X_OBU_MOGO, "IMoGoObuProvider"));
// BIZ
MogoModulePaths.addModuleFunctionServer(new MogoModule(MogoServicePaths.PATH_FUNC_BIZ, "IMoGoNoticeProvider"));
// todo 后置 车聊聊IM
// 后置 车聊聊IM
MogoModulePaths.addModuleFunctionServer(new MogoModule(ChatConsts.CHAT_PROVIDER_PATH, ChatConsts.CHAT_MODULE_NAME));
// 司机身份专属
if (AppIdentityModeUtils.isDriver(FunctionBuildConfig.appIdentityMode)) {
// todo 后置 地图数据收集模块
// 后置 地图数据收集模块
MogoModulePaths.addModuleFunctionServer(new MogoModule(MogoServicePaths.PATH_MAP_DATA_COLLECT_PROVIDER, "MoGoMapDataCollector"));
}
CallerLogger.INSTANCE.i(M_HMI + TAG, "App launch timer cost " + (System.currentTimeMillis() - start) + "ms");
@@ -141,7 +99,7 @@ public abstract class MainMoGoApplication extends AbsMogoApplication {
super.attachBaseContext(base);
/*如果是主进程**/
// if (ProcessUtils.isMainProcess(this)) {
AppLaunchTimeUtils.beginTimeCalculate(AppLaunchTimeUtils.COLD_START);
AppLaunchTimeUtils.beginTimeCalculate(AppLaunchTimeUtils.COLD_START);
// }
BoostMultiDex.install(base);
AbsMogoApplication.sApp = this;

View File

@@ -125,11 +125,6 @@ interface IDevaToolsProvider : IProvider {
*/
fun updateUpgradeProgress()
/**
* obu下载进度
*/
fun updateObuUpgradeStatus()
/**
* 展示状态栏
*/

View File

@@ -169,13 +169,6 @@ object CallerDevaToolsManager {
devaToolsProviderApi?.updateUpgradeProgress()
}
/**
* obu下载状态
*/
fun updateObuUpgradeStatus() {
devaToolsProviderApi?.updateObuUpgradeStatus()
}
/**
* 展示状态栏
*/