fix: 去抖合并后更新横幅数字
问题:多条消息同时到达,第一条横幅显示1,后续被去抖暂存。 1s后合并处理emit NewTaskArrived(count=3),但MainActivity 只监听MqttMessageReceived更新横幅,不监听NewTaskArrived。 修复:MainActivity同时监听NewTaskArrived,去抖合并后更新横幅。 时序:消息1→横幅"1条" → 消息2,3暂存 → 1s后合并→横幅更新"3条" Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -80,12 +80,23 @@ class MainActivity : AppCompatActivity() {
|
||||
private fun observeMqttMessages() {
|
||||
activityScope.launch {
|
||||
eventBus.events.collect { event ->
|
||||
if (event is AppEvent.MqttMessageReceived && event.type == 1) {
|
||||
notificationManager.onNewTaskMessage(event.rawJson)
|
||||
val count = notificationManager.pendingCount
|
||||
if (count > 0) {
|
||||
notificationBanner.show(count)
|
||||
when (event) {
|
||||
is AppEvent.MqttMessageReceived -> {
|
||||
if (event.type == 1) {
|
||||
notificationManager.onNewTaskMessage(event.rawJson)
|
||||
val count = notificationManager.pendingCount
|
||||
if (count > 0) {
|
||||
notificationBanner.show(count)
|
||||
}
|
||||
}
|
||||
}
|
||||
// 去抖合并完成后 → 更新横幅数字
|
||||
is AppEvent.NewTaskArrived -> {
|
||||
if (event.count > 0) {
|
||||
notificationBanner.show(event.count)
|
||||
}
|
||||
}
|
||||
else -> {}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user