From bbef06de596a163aa26cf37d6cf2f963313880d0 Mon Sep 17 00:00:00 2001 From: Vitor Pamplona Date: Fri, 2 Jun 2023 21:52:22 -0400 Subject: [PATCH] Moves UserFeed to MutableLists --- .../com/vitorpamplona/amethyst/ui/screen/UserFeedState.kt | 3 ++- .../vitorpamplona/amethyst/ui/screen/UserFeedViewModel.kt | 8 +++++--- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/app/src/main/java/com/vitorpamplona/amethyst/ui/screen/UserFeedState.kt b/app/src/main/java/com/vitorpamplona/amethyst/ui/screen/UserFeedState.kt index 6a86f37e3..18ecf6a9b 100644 --- a/app/src/main/java/com/vitorpamplona/amethyst/ui/screen/UserFeedState.kt +++ b/app/src/main/java/com/vitorpamplona/amethyst/ui/screen/UserFeedState.kt @@ -2,10 +2,11 @@ package com.vitorpamplona.amethyst.ui.screen import androidx.compose.runtime.MutableState import com.vitorpamplona.amethyst.model.User +import kotlinx.collections.immutable.ImmutableList sealed class UserFeedState { object Loading : UserFeedState() - class Loaded(val feed: MutableState>) : UserFeedState() + class Loaded(val feed: MutableState>) : UserFeedState() object Empty : UserFeedState() class FeedError(val errorMessage: String) : UserFeedState() } diff --git a/app/src/main/java/com/vitorpamplona/amethyst/ui/screen/UserFeedViewModel.kt b/app/src/main/java/com/vitorpamplona/amethyst/ui/screen/UserFeedViewModel.kt index 889d0e8d2..8783471af 100644 --- a/app/src/main/java/com/vitorpamplona/amethyst/ui/screen/UserFeedViewModel.kt +++ b/app/src/main/java/com/vitorpamplona/amethyst/ui/screen/UserFeedViewModel.kt @@ -12,6 +12,8 @@ import com.vitorpamplona.amethyst.ui.dal.FeedFilter import com.vitorpamplona.amethyst.ui.dal.HiddenAccountsFeedFilter import com.vitorpamplona.amethyst.ui.dal.UserProfileFollowersFeedFilter import com.vitorpamplona.amethyst.ui.dal.UserProfileFollowsFeedFilter +import kotlinx.collections.immutable.ImmutableList +import kotlinx.collections.immutable.toImmutableList import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.Job @@ -56,12 +58,12 @@ open class UserFeedViewModel(val dataSource: FeedFilter) : ViewModel() { } private fun refreshSuspended() { - val notes = dataSource.loadTop() + val notes = dataSource.loadTop().toImmutableList() val oldNotesState = _feedContent.value if (oldNotesState is UserFeedState.Loaded) { // Using size as a proxy for has changed. - if (notes != oldNotesState.feed.value) { + if (!equalImmutableLists(notes, oldNotesState.feed.value)) { updateFeed(notes) } } else { @@ -69,7 +71,7 @@ open class UserFeedViewModel(val dataSource: FeedFilter) : ViewModel() { } } - private fun updateFeed(notes: List) { + private fun updateFeed(notes: ImmutableList) { val scope = CoroutineScope(Job() + Dispatchers.Main) scope.launch { val currentState = _feedContent.value