From b271c1775cc221e53ed91399458b63a69e127558 Mon Sep 17 00:00:00 2001 From: Vitor Pamplona Date: Mon, 19 Jun 2023 20:30:13 -0400 Subject: [PATCH] BugFix for not updating Notifications quickly. --- .../amethyst/ui/screen/CardFeedViewModel.kt | 14 ++++++++++++++ .../amethyst/ui/screen/loggedIn/MainScreen.kt | 3 +-- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/com/vitorpamplona/amethyst/ui/screen/CardFeedViewModel.kt b/app/src/main/java/com/vitorpamplona/amethyst/ui/screen/CardFeedViewModel.kt index b98221e57..3d9cf01fc 100644 --- a/app/src/main/java/com/vitorpamplona/amethyst/ui/screen/CardFeedViewModel.kt +++ b/app/src/main/java/com/vitorpamplona/amethyst/ui/screen/CardFeedViewModel.kt @@ -283,6 +283,20 @@ open class CardFeedViewModel(val localFilter: FeedFilter) : ViewModel() { } } + @OptIn(ExperimentalTime::class) + fun invalidateDataAndSendToTop() { + clear() + bundler.invalidate(false) { + // adds the time to perform the refresh into this delay + // holding off new updates in case of heavy refresh routines. + val (value, elapsed) = measureTimedValue { + refreshSuspended() + sendToTop() + } + Log.d("Time", "${this.javaClass.simpleName} Card update $elapsed") + } + } + @OptIn(ExperimentalTime::class) fun checkKeysInvalidateDataAndSendToTop() { if (lastFeedKey != localFilter.feedKey()) { diff --git a/app/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/MainScreen.kt b/app/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/MainScreen.kt index 0c3ca2db5..1b9747c3f 100644 --- a/app/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/MainScreen.kt +++ b/app/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/MainScreen.kt @@ -141,8 +141,7 @@ fun MainScreen(accountViewModel: AccountViewModel, accountStateViewModel: Accoun videoFeedViewModel.sendToTop() } Route.Notification.base -> { - notifFeedViewModel.clear() - notifFeedViewModel.sendToTop() + notifFeedViewModel.invalidateDataAndSendToTop() } }