Using Main to update screen seems needed otherwise I get a 1 minute delay in the loading page before the screen updates. It looks like it waits for all the Pictures to load. Not sure why.

pull/87/head
Vitor Pamplona 2023-02-05 18:39:54 -05:00
rodzic bb50099021
commit e04843fe96
3 zmienionych plików z 28 dodań i 18 usunięć

Wyświetl plik

@ -82,15 +82,18 @@ class CardFeedViewModel(val dataSource: NostrDataSource<Note>): ViewModel() {
}
private fun updateFeed(notes: List<Card>) {
val currentState = feedContent.value
val scope = CoroutineScope(Job() + Dispatchers.Main)
scope.launch {
val currentState = feedContent.value
if (notes.isEmpty()) {
_feedContent.update { CardFeedState.Empty }
} else if (currentState is CardFeedState.Loaded) {
// updates the current list
currentState.feed.value = notes
} else {
_feedContent.update { CardFeedState.Loaded(mutableStateOf(notes)) }
if (notes.isEmpty()) {
_feedContent.update { CardFeedState.Empty }
} else if (currentState is CardFeedState.Loaded) {
// updates the current list
currentState.feed.value = notes
} else {
_feedContent.update { CardFeedState.Loaded(mutableStateOf(notes)) }
}
}
}

Wyświetl plik

@ -89,10 +89,14 @@ abstract class FeedViewModel(val dataSource: NostrDataSource<Note>): ViewModel()
val oldNotesState = feedContent.value
if (oldNotesState is FeedState.Loaded) {
if (notes != oldNotesState.feed) {
updateFeed(notes)
withContext(Dispatchers.Main) {
updateFeed(notes)
}
}
} else {
updateFeed(notes)
withContext(Dispatchers.Main) {
updateFeed(notes)
}
}
}
}

Wyświetl plik

@ -60,14 +60,17 @@ open class UserFeedViewModel(val dataSource: NostrDataSource<User>): ViewModel()
}
private fun updateFeed(notes: List<User>) {
val currentState = feedContent.value
if (notes.isEmpty()) {
_feedContent.update { UserFeedState.Empty }
} else if (currentState is UserFeedState.Loaded) {
// updates the current list
currentState.feed.value = notes
} else {
_feedContent.update { UserFeedState.Loaded(mutableStateOf(notes)) }
val scope = CoroutineScope(Job() + Dispatchers.Main)
scope.launch {
val currentState = feedContent.value
if (notes.isEmpty()) {
_feedContent.update { UserFeedState.Empty }
} else if (currentState is UserFeedState.Loaded) {
// updates the current list
currentState.feed.value = notes
} else {
_feedContent.update { UserFeedState.Loaded(mutableStateOf(notes)) }
}
}
}