From 5ce19474ae887a351440009b413daf0cf04e5afe Mon Sep 17 00:00:00 2001 From: Vitor Pamplona Date: Thu, 25 May 2023 18:28:19 -0400 Subject: [PATCH] Moves Home and Video screen invalidations to follow the scrollTop parameter --- .../amethyst/ui/screen/loggedIn/HomeScreen.kt | 18 ++++++++++++------ .../amethyst/ui/screen/loggedIn/VideoScreen.kt | 14 +++++++++++--- 2 files changed, 23 insertions(+), 9 deletions(-) diff --git a/app/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/HomeScreen.kt b/app/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/HomeScreen.kt index da87f72ec..62959250a 100644 --- a/app/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/HomeScreen.kt +++ b/app/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/HomeScreen.kt @@ -36,6 +36,7 @@ import com.vitorpamplona.amethyst.ui.screen.FeedViewModel import com.vitorpamplona.amethyst.ui.screen.NostrHomeFeedViewModel import com.vitorpamplona.amethyst.ui.screen.NostrHomeRepliesFeedViewModel import com.vitorpamplona.amethyst.ui.screen.ScrollStateKeys +import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.launch @OptIn(ExperimentalFoundationApi::class) @@ -58,9 +59,6 @@ fun HomeScreen( LaunchedEffect(accountViewModel, account.defaultHomeFollowList) { HomeNewThreadFeedFilter.account = account HomeConversationsFeedFilter.account = account - NostrHomeDataSource.resetFilters() - homeFeedViewModel.invalidateData() - repliesFeedViewModel.invalidateData() } if (wantsToAddNip47 != null) { @@ -73,9 +71,6 @@ fun HomeScreen( if (event == Lifecycle.Event.ON_RESUME) { HomeNewThreadFeedFilter.account = account HomeConversationsFeedFilter.account = account - NostrHomeDataSource.resetFilters() - homeFeedViewModel.invalidateData() - repliesFeedViewModel.invalidateData() } } @@ -85,6 +80,17 @@ fun HomeScreen( } } + if (scrollToTop) { + val scope = rememberCoroutineScope() + LaunchedEffect(key1 = Unit) { + scope.launch(Dispatchers.IO) { + NostrHomeDataSource.resetFilters() + homeFeedViewModel.invalidateData(true) + repliesFeedViewModel.invalidateData(true) + } + } + } + val tabs by remember(homeFeedViewModel, repliesFeedViewModel) { mutableStateOf( listOf( diff --git a/app/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/VideoScreen.kt b/app/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/VideoScreen.kt index e6b9185dc..0e417fa86 100644 --- a/app/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/VideoScreen.kt +++ b/app/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/VideoScreen.kt @@ -91,6 +91,7 @@ import com.vitorpamplona.amethyst.ui.screen.LoadingFeed import com.vitorpamplona.amethyst.ui.screen.NostrVideoFeedViewModel import com.vitorpamplona.amethyst.ui.screen.ScrollStateKeys import com.vitorpamplona.amethyst.ui.screen.rememberForeverPagerState +import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.delay import kotlinx.coroutines.launch @@ -109,11 +110,19 @@ fun VideoScreen( NostrVideoDataSource.account = account VideoFeedFilter.account = account + if (scrollToTop) { + val scope = rememberCoroutineScope() + LaunchedEffect(key1 = Unit) { + scope.launch(Dispatchers.IO) { + NostrVideoDataSource.resetFilters() + videoFeedView.invalidateData() + } + } + } + LaunchedEffect(accountViewModel, accountState.value?.account?.defaultStoriesFollowList) { VideoFeedFilter.account = account NostrVideoDataSource.account = account - NostrVideoDataSource.resetFilters() - videoFeedView.invalidateData() } DisposableEffect(accountViewModel) { @@ -123,7 +132,6 @@ fun VideoScreen( VideoFeedFilter.account = account NostrVideoDataSource.account = account NostrVideoDataSource.start() - videoFeedView.invalidateData() } if (event == Lifecycle.Event.ON_PAUSE) { println("Video Stop")