From c2857664d3ca8eb70ec9431727b6e2df642a73b9 Mon Sep 17 00:00:00 2001 From: KotlinGeekDev Date: Thu, 30 Jan 2025 14:50:05 +0100 Subject: [PATCH] Just use simple List. Remove explicit dispatcher calls in unneeded places. --- .../screen/loggedIn/lists/CustomListsScreen.kt | 5 ++--- .../loggedIn/lists/FollowSetFeedViewModel.kt | 18 +++++++----------- .../ui/screen/loggedIn/lists/FollowSetState.kt | 5 +---- 3 files changed, 10 insertions(+), 18 deletions(-) diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/lists/CustomListsScreen.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/lists/CustomListsScreen.kt index 1897f7fd0..6a66780d7 100644 --- a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/lists/CustomListsScreen.kt +++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/lists/CustomListsScreen.kt @@ -67,7 +67,6 @@ import com.vitorpamplona.amethyst.ui.stringRes import com.vitorpamplona.amethyst.ui.theme.FeedPadding import com.vitorpamplona.amethyst.ui.theme.StdVertSpacer import com.vitorpamplona.amethyst.ui.theme.ThemeComparisonColumn -import kotlinx.collections.immutable.ImmutableList @Composable fun ListsScreen( @@ -134,7 +133,7 @@ fun CustomListsScreen( followSetsViewModel.invalidateData() } is FollowSetState.Loaded -> { - val followSetFeed by (setsState as FollowSetState.Loaded).feed + val followSetFeed = (setsState as FollowSetState.Loaded).feed FollowListLoaded( loadedFeedState = followSetFeed, ) @@ -148,7 +147,7 @@ fun CustomListsScreen( @Composable fun FollowListLoaded( modifier: Modifier = Modifier, - loadedFeedState: ImmutableList, + loadedFeedState: List, ) { val listState = rememberLazyListState() Log.d("FollowSetComposable", "FollowListLoaded: Follow Set size: ${loadedFeedState.size}") diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/lists/FollowSetFeedViewModel.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/lists/FollowSetFeedViewModel.kt index 67e6d81f3..7b5c28fb6 100644 --- a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/lists/FollowSetFeedViewModel.kt +++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/lists/FollowSetFeedViewModel.kt @@ -50,7 +50,7 @@ open class FollowSetFeedViewModel( val feedContent = _feedContent.asStateFlow() private fun refresh() { - viewModelScope.launch(Dispatchers.Default) { refreshSuspended() } + viewModelScope.launch { refreshSuspended() } } override val isRefreshing: MutableState = mutableStateOf(false) @@ -66,7 +66,7 @@ open class FollowSetFeedViewModel( val oldNotesState = _feedContent.value if (oldNotesState is FollowSetState.Loaded) { // Using size as a proxy for has changed. - if (!equalImmutableLists(notes, oldNotesState.feed.value.toImmutableList())) { + if (!equalImmutableLists(notes, oldNotesState.feed.toImmutableList())) { updateFeed(notes) } } else { @@ -78,20 +78,16 @@ open class FollowSetFeedViewModel( } private fun updateFeed(notes: ImmutableList) { - viewModelScope.launch(Dispatchers.Main) { - val currentState = _feedContent.value + viewModelScope.launch { if (notes.isEmpty()) { _feedContent.update { FollowSetState.Empty } - } else if (currentState is FollowSetState.Loaded) { - // updates the current list - currentState.feed.value = notes } else { - _feedContent.update { FollowSetState.Loaded(mutableStateOf(notes)) } + _feedContent.update { FollowSetState.Loaded(notes) } } } } - private val bundler = BundledUpdate(250, Dispatchers.IO) + private val bundler = BundledUpdate(250) override fun invalidateData(ignoreIfDoing: Boolean) { bundler.invalidate(ignoreIfDoing) { @@ -104,9 +100,9 @@ open class FollowSetFeedViewModel( var collectorJob: Job? = null init { - Log.d("Init", "${this.javaClass.simpleName}") + Log.d("Init", this.javaClass.simpleName) collectorJob = - viewModelScope.launch(Dispatchers.IO) { + viewModelScope.launch(Dispatchers.Default) { checkNotInMainThread() LocalCache.live.newEventBundles.collect { newNotes -> diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/lists/FollowSetState.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/lists/FollowSetState.kt index c2a71aa72..ad646211f 100644 --- a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/lists/FollowSetState.kt +++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/lists/FollowSetState.kt @@ -20,14 +20,11 @@ */ package com.vitorpamplona.amethyst.ui.screen.loggedIn.lists -import androidx.compose.runtime.MutableState -import kotlinx.collections.immutable.ImmutableList - sealed class FollowSetState { data object Loading : FollowSetState() class Loaded( - val feed: MutableState>, + val feed: List, ) : FollowSetState() object Empty : FollowSetState()