fix: 红点用preNotificationStats精确对比+有通知时不更新lastStats
之前diffStats失败的根因:有通知时fetchStatistics也更新lastStats, 导致基准被污染。 修复: - checkDots=true 时用 preNotificationStats(通知前快照)对比, 不更新 lastStats - checkDots=false(正常刷新)时才更新 lastStats - 这样 preNotificationStats 始终是通知前的干净基准 Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -143,13 +143,9 @@ class HomeFragment : BaseFragment<FragmentHomeBinding>() {
|
|||||||
renderDots()
|
renderDots()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
// 有未读通知 → 所有未 ack 的卡片显示红点
|
// 有未读通知 → 用 preNotificationStats 精确对比
|
||||||
val ack = notificationManager.acknowledgedCards
|
// onResume 时 view 可能重建,需要重新请求 API
|
||||||
activeDotCards.clear()
|
fetchStatistics(checkDots = true)
|
||||||
if (2 !in ack) activeDotCards.add(2)
|
|
||||||
if (3 !in ack) activeDotCards.add(3)
|
|
||||||
if (4 !in ack) activeDotCards.add(4)
|
|
||||||
renderDots()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onDestroyView() {
|
override fun onDestroyView() {
|
||||||
@@ -362,22 +358,33 @@ class HomeFragment : BaseFragment<FragmentHomeBinding>() {
|
|||||||
if (result is ApiResult.Success && result.data != null) {
|
if (result is ApiResult.Success && result.data != null) {
|
||||||
val data = result.data
|
val data = result.data
|
||||||
|
|
||||||
// 有 pending 通知 → 所有未 ack 的卡片显示红点(不用 diffStats,避免竞态)
|
|
||||||
if (checkDots && notificationManager.pendingCount > 0) {
|
if (checkDots && notificationManager.pendingCount > 0) {
|
||||||
|
// 用 preNotificationStats(通知前快照)做精确对比
|
||||||
|
val baseline = notificationManager.preNotificationStats
|
||||||
|
if (baseline != null) {
|
||||||
|
val changed = notificationManager.diffStats(baseline, data)
|
||||||
val ack = notificationManager.acknowledgedCards
|
val ack = notificationManager.acknowledgedCards
|
||||||
if (2 !in ack) activeDotCards.add(2)
|
for (status in changed) {
|
||||||
if (3 !in ack) activeDotCards.add(3)
|
if (status !in ack) activeDotCards.add(status)
|
||||||
if (4 !in ack) activeDotCards.add(4)
|
}
|
||||||
|
} else {
|
||||||
|
// 无快照(极端情况)→ 所有有值的加红点
|
||||||
|
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)
|
||||||
|
}
|
||||||
renderDots()
|
renderDots()
|
||||||
|
// 有通知时不更新 lastStats,保留旧基准给后续 diff
|
||||||
|
} else {
|
||||||
|
// 无通知的正常刷新 → 更新 lastStats 基准
|
||||||
|
notificationManager.lastStats = data
|
||||||
}
|
}
|
||||||
|
|
||||||
// 更新数字
|
// 更新数字
|
||||||
tvPoolNum.text = data.waitForTask.toString()
|
tvPoolNum.text = data.waitForTask.toString()
|
||||||
tvPunchNum.text = data.treatTask.toString()
|
tvPunchNum.text = data.treatTask.toString()
|
||||||
tvCompleteNum.text = data.incompleteTask.toString()
|
tvCompleteNum.text = data.incompleteTask.toString()
|
||||||
|
|
||||||
// 保存为下次对比基准
|
|
||||||
notificationManager.lastStats = data
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user