重构 HomeActivity:修复多项稳定性与架构问题
架构优化: - 新增 HomeViewModel,将 companion object 中的共享状态(shelfItems、 weightMap、selectedShelfIndex、temperatureC、humidity)迁移至 ViewModel, 消除 Activity 重建时的状态残留与全局状态污染问题 协程修复: - repeatOnLifecycle(CREATED) 改为 STARTED,确保 Flow 收集与 UI 可见性 生命周期对齐,进入后台时自动停止订阅 - 串口数据接收改用 Channel<String> + 单一消费协程,替代多 launch 并发模式, 彻底消除 StringBuilder(serialReader)的并发竞争问题 稳定性修复: - 修复 tipDialog 从未赋值导致 Dialog 功能失效及 onDestroy 窗口泄漏问题 - 修复 weightHex.toInt() 十进制解析错误,改为 toIntOrNull(16) 并添加兜底 - 修复 updateOverdueState 按索引访问接口数据导致的越界风险, 改为按 deviceNo 精确匹配,同时修正交叉排列导致的状态串位问题 - 废弃 API getSerializableExtra 替换为版本分支兼容写法(minSdk 25+) 依赖升级: - androidx.core-ktx 1.10.1 → 1.12.0 Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -2,7 +2,7 @@
|
||||
#agp = "8.11.1"
|
||||
agp = "8.4.0"
|
||||
kotlin = "2.0.21"
|
||||
coreKtx = "1.10.1"
|
||||
coreKtx = "1.12.0"
|
||||
junit = "4.13.2"
|
||||
junitVersion = "1.1.5"
|
||||
espressoCore = "3.5.1"
|
||||
|
||||
Reference in New Issue
Block a user