From 7e3cfcdcafc20c89e14b52b98342c8f76440ad30 Mon Sep 17 00:00:00 2001 From: Vitor Pamplona Date: Mon, 27 Feb 2023 15:06:20 -0500 Subject: [PATCH] ThreadView avoids double loading. --- .../amethyst/ui/screen/FeedViewModel.kt | 4 ---- .../amethyst/ui/screen/ThreadFeedView.kt | 16 +++++++++++++--- .../amethyst/ui/screen/loggedIn/ThreadScreen.kt | 1 - 3 files changed, 13 insertions(+), 8 deletions(-) diff --git a/app/src/main/java/com/vitorpamplona/amethyst/ui/screen/FeedViewModel.kt b/app/src/main/java/com/vitorpamplona/amethyst/ui/screen/FeedViewModel.kt index 05bafe661..d7a0c9d9c 100644 --- a/app/src/main/java/com/vitorpamplona/amethyst/ui/screen/FeedViewModel.kt +++ b/app/src/main/java/com/vitorpamplona/amethyst/ui/screen/FeedViewModel.kt @@ -50,10 +50,6 @@ abstract class FeedViewModel(val localFilter: FeedFilter): ViewModel() { return localFilter.loadTop() } - fun clearFeed() { - _feedContent.update { FeedState.Loading } - } - fun refresh() { val scope = CoroutineScope(Job() + Dispatchers.Default) scope.launch { diff --git a/app/src/main/java/com/vitorpamplona/amethyst/ui/screen/ThreadFeedView.kt b/app/src/main/java/com/vitorpamplona/amethyst/ui/screen/ThreadFeedView.kt index 684f93dc8..44c7a90f0 100644 --- a/app/src/main/java/com/vitorpamplona/amethyst/ui/screen/ThreadFeedView.kt +++ b/app/src/main/java/com/vitorpamplona/amethyst/ui/screen/ThreadFeedView.kt @@ -32,6 +32,7 @@ import androidx.compose.ui.Modifier import androidx.compose.ui.draw.drawBehind import androidx.compose.ui.geometry.Offset import androidx.compose.ui.graphics.Color +import androidx.compose.ui.graphics.compositeOver import androidx.compose.ui.unit.dp import androidx.navigation.NavController import com.google.accompanist.swiperefresh.SwipeRefresh @@ -48,6 +49,7 @@ import com.vitorpamplona.amethyst.ui.note.NoteUsernameDisplay import com.vitorpamplona.amethyst.ui.note.ReactionsRow import com.vitorpamplona.amethyst.ui.note.timeAgo import com.vitorpamplona.amethyst.ui.screen.loggedIn.AccountViewModel +import kotlinx.coroutines.delay @Composable fun ThreadFeedView(noteId: String, viewModel: FeedViewModel, accountViewModel: AccountViewModel, navController: NavController) { @@ -86,10 +88,18 @@ fun ThreadFeedView(noteId: String, viewModel: FeedViewModel, accountViewModel: A } is FeedState.Loaded -> { LaunchedEffect(noteId) { + // waits to load the thread to scroll to item. + delay(100) val noteForPosition = state.feed.value.filter { it.idHex == noteId}.firstOrNull() - val position = state.feed.value.indexOf(noteForPosition) - if (position > 0) - listState.animateScrollToItem(position, 0) + var position = state.feed.value.indexOf(noteForPosition) + + if (position >= 0) { + if (position >= 1 && position < state.feed.value.size - 1) { + position -- // show the replying note + } + + listState.animateScrollToItem(position) + } } LazyColumn( diff --git a/app/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/ThreadScreen.kt b/app/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/ThreadScreen.kt index d240f32a5..184ac9c7c 100644 --- a/app/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/ThreadScreen.kt +++ b/app/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/ThreadScreen.kt @@ -30,7 +30,6 @@ fun ThreadScreen(noteId: String?, accountViewModel: AccountViewModel, navControl val feedViewModel: NostrThreadFeedViewModel = viewModel() LaunchedEffect(noteId) { - feedViewModel.clearFeed() ThreadFeedFilter.loadThread(noteId) NostrThreadDataSource.loadThread(noteId) feedViewModel.invalidateData()