From 9fef3e9e3e6f1ec366b2a6c0579170b95f17e62f Mon Sep 17 00:00:00 2001 From: Vitor Pamplona Date: Mon, 30 Oct 2023 12:27:59 -0400 Subject: [PATCH] Only updates notification dots once at every 3 seconds. --- .../amethyst/ui/screen/loggedIn/AccountViewModel.kt | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/AccountViewModel.kt b/app/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/AccountViewModel.kt index 8fe2f8239..29a153e39 100644 --- a/app/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/AccountViewModel.kt +++ b/app/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/AccountViewModel.kt @@ -32,6 +32,7 @@ import com.vitorpamplona.amethyst.service.OnlineChecker import com.vitorpamplona.amethyst.service.ZapPaymentHandler import com.vitorpamplona.amethyst.service.checkNotInMainThread import com.vitorpamplona.amethyst.ui.actions.Dao +import com.vitorpamplona.amethyst.ui.components.BundledInsert import com.vitorpamplona.amethyst.ui.components.MarkdownParser import com.vitorpamplona.amethyst.ui.components.UrlPreviewState import com.vitorpamplona.amethyst.ui.navigation.Route @@ -862,6 +863,13 @@ class AccountViewModel(val account: Account, val settings: SettingsState) : View private var collectorJob: Job? = null val notificationDots = HasNotificationDot(bottomNavigationItems, account) + private val bundlerInsert = BundledInsert>(3000, Dispatchers.IO) + + fun invalidateInsertData(newItems: Set) { + bundlerInsert.invalidateList(newItems) { + updateNotificationDots(it.flatten().toSet()) + } + } suspend fun updateNotificationDots(newNotes: Set = emptySet()) { val (value, elapsed) = measureTimedValue { @@ -875,8 +883,7 @@ class AccountViewModel(val account: Account, val settings: SettingsState) : View collectorJob = viewModelScope.launch(Dispatchers.IO) { LocalCache.live.newEventBundles.collect { newNotes -> Log.d("Rendering Metrics", "Notification Dots Calculation refresh ${this@AccountViewModel}") - - updateNotificationDots(newNotes) + invalidateInsertData(newNotes) } } }