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:
@@ -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 窗口内的消息暂存,窗口结束后合并处理(不丢弃)
|
||||
|
||||
@@ -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 移除 + 通知管理器记录 */
|
||||
|
||||
Reference in New Issue
Block a user