mirror of
https://github.com/vitorpamplona/amethyst.git
synced 2025-09-26 11:46:20 +02:00
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.
This commit is contained in:
@@ -82,15 +82,18 @@ class CardFeedViewModel(val dataSource: NostrDataSource<Note>): ViewModel() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun updateFeed(notes: List<Card>) {
|
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()) {
|
if (notes.isEmpty()) {
|
||||||
_feedContent.update { CardFeedState.Empty }
|
_feedContent.update { CardFeedState.Empty }
|
||||||
} else if (currentState is CardFeedState.Loaded) {
|
} else if (currentState is CardFeedState.Loaded) {
|
||||||
// updates the current list
|
// updates the current list
|
||||||
currentState.feed.value = notes
|
currentState.feed.value = notes
|
||||||
} else {
|
} else {
|
||||||
_feedContent.update { CardFeedState.Loaded(mutableStateOf(notes)) }
|
_feedContent.update { CardFeedState.Loaded(mutableStateOf(notes)) }
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -89,10 +89,14 @@ abstract class FeedViewModel(val dataSource: NostrDataSource<Note>): ViewModel()
|
|||||||
val oldNotesState = feedContent.value
|
val oldNotesState = feedContent.value
|
||||||
if (oldNotesState is FeedState.Loaded) {
|
if (oldNotesState is FeedState.Loaded) {
|
||||||
if (notes != oldNotesState.feed) {
|
if (notes != oldNotesState.feed) {
|
||||||
updateFeed(notes)
|
withContext(Dispatchers.Main) {
|
||||||
|
updateFeed(notes)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
updateFeed(notes)
|
withContext(Dispatchers.Main) {
|
||||||
|
updateFeed(notes)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -60,14 +60,17 @@ open class UserFeedViewModel(val dataSource: NostrDataSource<User>): ViewModel()
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun updateFeed(notes: List<User>) {
|
private fun updateFeed(notes: List<User>) {
|
||||||
val currentState = feedContent.value
|
val scope = CoroutineScope(Job() + Dispatchers.Main)
|
||||||
if (notes.isEmpty()) {
|
scope.launch {
|
||||||
_feedContent.update { UserFeedState.Empty }
|
val currentState = feedContent.value
|
||||||
} else if (currentState is UserFeedState.Loaded) {
|
if (notes.isEmpty()) {
|
||||||
// updates the current list
|
_feedContent.update { UserFeedState.Empty }
|
||||||
currentState.feed.value = notes
|
} else if (currentState is UserFeedState.Loaded) {
|
||||||
} else {
|
// updates the current list
|
||||||
_feedContent.update { UserFeedState.Loaded(mutableStateOf(notes)) }
|
currentState.feed.value = notes
|
||||||
|
} else {
|
||||||
|
_feedContent.update { UserFeedState.Loaded(mutableStateOf(notes)) }
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user