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,不覆盖已有的
|
// 对比红点:累积到 activeDotCards,不覆盖已有的
|
||||||
if (checkDots) {
|
if (checkDots) {
|
||||||
val oldStats = notificationManager.lastStats
|
val oldStats = notificationManager.lastStats
|
||||||
val changedCards = notificationManager.diffStats(oldStats, data)
|
if (oldStats != null) {
|
||||||
for (status in changedCards) {
|
// 有旧数据 → 精确对比
|
||||||
activeDotCards.add(status) // 累积,不会移除已有的
|
val changedCards = notificationManager.diffStats(oldStats, data)
|
||||||
val increment = when (status) {
|
for (status in changedCards) {
|
||||||
2 -> data.waitForTask - (oldStats?.waitForTask ?: 0)
|
activeDotCards.add(status)
|
||||||
3 -> data.treatTask - (oldStats?.treatTask ?: 0)
|
val increment = when (status) {
|
||||||
4 -> data.incompleteTask - (oldStats?.incompleteTask ?: 0)
|
2 -> data.waitForTask - oldStats.waitForTask
|
||||||
else -> 0
|
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()
|
renderDots()
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user