chore: 代码清理(debug日志+孤立文件+未用字段+测试修复)

1. 去掉 fetchStatistics/renderDots 中的 debug Timber.d
2. 删除孤立文件: bg_new_task_hint.xml, bg_btn_primary.xml, bg_btn_secondary.xml
3. 删除未用字段: onPendingCountChanged
4. 单元测试修复:
   - 添加 Dispatchers.setMain/resetMain (JVM无Main线程)
   - 新增: 数字id解析、acknowledgeCard减pendingCount、ack清除、preNotificationStats
   - 总计 22 条测试

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
dongliang
2026-04-29 21:03:12 +09:30
parent 602f0ccce6
commit 08aae2065e
6 changed files with 123 additions and 118 deletions

View File

@@ -71,9 +71,6 @@ class NotificationManager @Inject constructor(
/** 协程作用域 */
private val scope = CoroutineScope(Dispatchers.Main + SupervisorJob())
/** 去抖合并后的回调(通知 UI 更新横幅数字) */
var onPendingCountChanged: ((Int) -> Unit)? = null
/**
* 处理 MQTT type=1 新任务消息
* 去抖策略1s 窗口内的消息暂存,窗口结束后合并处理(不丢弃)

View File

@@ -366,14 +366,11 @@ class HomeFragment : BaseFragment<FragmentHomeBinding>() {
if (checkDots && notificationManager.pendingCount > 0) {
val baseline = notificationManager.preNotificationStats
Timber.d("首页: checkDots baseline=$baseline, newData=$data, pendingCount=${notificationManager.pendingCount}")
if (baseline != null) {
val changed = notificationManager.diffStats(baseline, data)
val ack = notificationManager.acknowledgedCards
Timber.d("首页: diffStats changed=$changed, ack=$ack, activeDots=$activeDotCards")
for (status in changed) {
if (status !in ack) activeDotCards.add(status)
// 记录每个分类的增量(供 acknowledgeCard 扣减 pendingCount 用)
val increment = when (status) {
2 -> data.waitForTask - baseline.waitForTask
3 -> data.treatTask - baseline.treatTask
@@ -383,17 +380,15 @@ class HomeFragment : BaseFragment<FragmentHomeBinding>() {
notificationManager.recordCardIncrement(status, increment)
}
} else {
Timber.d("首页: baseline为null兜底显示所有有值的红点")
// 无快照(极端情况)→ 所有有值的红点
val ack = notificationManager.acknowledgedCards
if (data.waitForTask > 0 && 2 !in ack) activeDotCards.add(2)
if (data.treatTask > 0 && 3 !in ack) activeDotCards.add(3)
if (data.incompleteTask > 0 && 4 !in ack) activeDotCards.add(4)
}
Timber.d("首页: renderDots activeDotCards=$activeDotCards")
renderDots()
} else {
notificationManager.lastStats = data
Timber.d("首页: lastStats 更新为 $data (无通知刷新)")
}
// 更新数字
@@ -582,7 +577,6 @@ class HomeFragment : BaseFragment<FragmentHomeBinding>() {
dotPool.visibility = if (2 in activeDotCards) View.VISIBLE else View.GONE
dotPunch.visibility = if (3 in activeDotCards) View.VISIBLE else View.GONE
dotComplete.visibility = if (4 in activeDotCards) View.VISIBLE else View.GONE
Timber.d("首页: renderDots 完成 pool=${dotPool.visibility==View.VISIBLE} punch=${dotPunch.visibility==View.VISIBLE} complete=${dotComplete.visibility==View.VISIBLE}")
}
/** 标记某个分类已查看:从 activeDotCards 移除 + 通知管理器记录 */

View File

@@ -1,16 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- 主按钮背景(深蓝色圆角) -->
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="true">
<shape android:shape="rectangle">
<solid android:color="#FF1565C0" />
<corners android:radius="12dp" />
</shape>
</item>
<item>
<shape android:shape="rectangle">
<solid android:color="#FF1E88E5" />
<corners android:radius="12dp" />
</shape>
</item>
</selector>

View File

@@ -1,16 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- 次按钮背景(深灰色圆角) -->
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="true">
<shape android:shape="rectangle">
<solid android:color="#FF424242" />
<corners android:radius="12dp" />
</shape>
</item>
<item>
<shape android:shape="rectangle">
<solid android:color="#FF333333" />
<corners android:radius="12dp" />
</shape>
</item>
</selector>

View File

@@ -1,7 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- 新任务提示条背景(蓝色半透明圆角) -->
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<solid android:color="#1A3B9EFF" />
<corners android:radius="12dp" />
</shape>