Moves UserFeed to MutableLists
This commit is contained in:
@@ -2,10 +2,11 @@ package com.vitorpamplona.amethyst.ui.screen
|
|||||||
|
|
||||||
import androidx.compose.runtime.MutableState
|
import androidx.compose.runtime.MutableState
|
||||||
import com.vitorpamplona.amethyst.model.User
|
import com.vitorpamplona.amethyst.model.User
|
||||||
|
import kotlinx.collections.immutable.ImmutableList
|
||||||
|
|
||||||
sealed class UserFeedState {
|
sealed class UserFeedState {
|
||||||
object Loading : UserFeedState()
|
object Loading : UserFeedState()
|
||||||
class Loaded(val feed: MutableState<List<User>>) : UserFeedState()
|
class Loaded(val feed: MutableState<ImmutableList<User>>) : UserFeedState()
|
||||||
object Empty : UserFeedState()
|
object Empty : UserFeedState()
|
||||||
class FeedError(val errorMessage: String) : UserFeedState()
|
class FeedError(val errorMessage: String) : UserFeedState()
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,6 +12,8 @@ import com.vitorpamplona.amethyst.ui.dal.FeedFilter
|
|||||||
import com.vitorpamplona.amethyst.ui.dal.HiddenAccountsFeedFilter
|
import com.vitorpamplona.amethyst.ui.dal.HiddenAccountsFeedFilter
|
||||||
import com.vitorpamplona.amethyst.ui.dal.UserProfileFollowersFeedFilter
|
import com.vitorpamplona.amethyst.ui.dal.UserProfileFollowersFeedFilter
|
||||||
import com.vitorpamplona.amethyst.ui.dal.UserProfileFollowsFeedFilter
|
import com.vitorpamplona.amethyst.ui.dal.UserProfileFollowsFeedFilter
|
||||||
|
import kotlinx.collections.immutable.ImmutableList
|
||||||
|
import kotlinx.collections.immutable.toImmutableList
|
||||||
import kotlinx.coroutines.CoroutineScope
|
import kotlinx.coroutines.CoroutineScope
|
||||||
import kotlinx.coroutines.Dispatchers
|
import kotlinx.coroutines.Dispatchers
|
||||||
import kotlinx.coroutines.Job
|
import kotlinx.coroutines.Job
|
||||||
@@ -56,12 +58,12 @@ open class UserFeedViewModel(val dataSource: FeedFilter<User>) : ViewModel() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun refreshSuspended() {
|
private fun refreshSuspended() {
|
||||||
val notes = dataSource.loadTop()
|
val notes = dataSource.loadTop().toImmutableList()
|
||||||
|
|
||||||
val oldNotesState = _feedContent.value
|
val oldNotesState = _feedContent.value
|
||||||
if (oldNotesState is UserFeedState.Loaded) {
|
if (oldNotesState is UserFeedState.Loaded) {
|
||||||
// Using size as a proxy for has changed.
|
// Using size as a proxy for has changed.
|
||||||
if (notes != oldNotesState.feed.value) {
|
if (!equalImmutableLists(notes, oldNotesState.feed.value)) {
|
||||||
updateFeed(notes)
|
updateFeed(notes)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@@ -69,7 +71,7 @@ open class UserFeedViewModel(val dataSource: FeedFilter<User>) : ViewModel() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun updateFeed(notes: List<User>) {
|
private fun updateFeed(notes: ImmutableList<User>) {
|
||||||
val scope = CoroutineScope(Job() + Dispatchers.Main)
|
val scope = CoroutineScope(Job() + Dispatchers.Main)
|
||||||
scope.launch {
|
scope.launch {
|
||||||
val currentState = _feedContent.value
|
val currentState = _feedContent.value
|
||||||
|
|||||||
Reference in New Issue
Block a user