fix: lastStats为null时红点兜底显示
问题:首次加载时fetchStatistics()异步未返回,lastStats为null。 此时收到通知→diffStats(null,data)→emptySet()→无红点。 修复:lastStats为null时,有pending通知则对所有有值的分类 显示红点(兜底策略,宁多勿漏)。 Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -370,16 +370,26 @@ class HomeFragment : BaseFragment<FragmentHomeBinding>() {
|
||||
// 对比红点:累积到 activeDotCards,不覆盖已有的
|
||||
if (checkDots) {
|
||||
val oldStats = notificationManager.lastStats
|
||||
val changedCards = notificationManager.diffStats(oldStats, data)
|
||||
for (status in changedCards) {
|
||||
activeDotCards.add(status) // 累积,不会移除已有的
|
||||
val increment = when (status) {
|
||||
2 -> data.waitForTask - (oldStats?.waitForTask ?: 0)
|
||||
3 -> data.treatTask - (oldStats?.treatTask ?: 0)
|
||||
4 -> data.incompleteTask - (oldStats?.incompleteTask ?: 0)
|
||||
else -> 0
|
||||
if (oldStats != null) {
|
||||
// 有旧数据 → 精确对比
|
||||
val changedCards = notificationManager.diffStats(oldStats, data)
|
||||
for (status in changedCards) {
|
||||
activeDotCards.add(status)
|
||||
val increment = when (status) {
|
||||
2 -> data.waitForTask - oldStats.waitForTask
|
||||
3 -> data.treatTask - oldStats.treatTask
|
||||
4 -> data.incompleteTask - oldStats.incompleteTask
|
||||
else -> 0
|
||||
}
|
||||
notificationManager.recordCardIncrement(status, increment)
|
||||
}
|
||||
} else {
|
||||
// 无旧数据(首次加载 lastStats 还为 null)→ 有 pending 通知就显示所有有值的
|
||||
if (notificationManager.pendingCount > 0) {
|
||||
if (data.waitForTask > 0) activeDotCards.add(2)
|
||||
if (data.treatTask > 0) activeDotCards.add(3)
|
||||
if (data.incompleteTask > 0) activeDotCards.add(4)
|
||||
}
|
||||
notificationManager.recordCardIncrement(status, increment)
|
||||
}
|
||||
renderDots()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user