mirror of
https://github.com/vitorpamplona/amethyst.git
synced 2025-09-25 19:56:47 +02:00
Adds an isRefreshing status for all feeds.
This commit is contained in:
@@ -21,7 +21,11 @@
|
||||
package com.vitorpamplona.amethyst.ui.feeds
|
||||
|
||||
import android.util.Log
|
||||
import androidx.compose.runtime.MutableState
|
||||
import androidx.compose.runtime.Stable
|
||||
import androidx.compose.runtime.getValue
|
||||
import androidx.compose.runtime.mutableStateOf
|
||||
import androidx.compose.runtime.setValue
|
||||
import androidx.lifecycle.viewModelScope
|
||||
import com.vitorpamplona.amethyst.model.Note
|
||||
import com.vitorpamplona.amethyst.service.checkNotInMainThread
|
||||
@@ -54,6 +58,8 @@ class FeedContentState(
|
||||
|
||||
private var lastFeedKey: String? = null
|
||||
|
||||
override val isRefreshing: MutableState<Boolean> = mutableStateOf(false)
|
||||
|
||||
fun sendToTop() {
|
||||
if (scrolltoTopPending) return
|
||||
|
||||
@@ -72,6 +78,8 @@ class FeedContentState(
|
||||
fun refreshSuspended() {
|
||||
checkNotInMainThread()
|
||||
|
||||
isRefreshing.value = true
|
||||
try {
|
||||
lastFeedKey = localFilter.feedKey()
|
||||
val notes = localFilter.loadTop().distinctBy { it.idHex }.toImmutableList()
|
||||
|
||||
@@ -83,6 +91,9 @@ class FeedContentState(
|
||||
} else {
|
||||
updateFeed(notes)
|
||||
}
|
||||
} finally {
|
||||
isRefreshing.value = false
|
||||
}
|
||||
}
|
||||
|
||||
private fun updateFeed(notes: ImmutableList<Note>) {
|
||||
|
@@ -20,6 +20,10 @@
|
||||
*/
|
||||
package com.vitorpamplona.amethyst.ui.feeds
|
||||
|
||||
import androidx.compose.runtime.MutableState
|
||||
|
||||
interface InvalidatableContent {
|
||||
fun invalidateData(ignoreIfDoing: Boolean = false)
|
||||
|
||||
val isRefreshing: MutableState<Boolean>
|
||||
}
|
||||
|
@@ -260,6 +260,8 @@ abstract class FeedViewModel(
|
||||
InvalidatableContent {
|
||||
val feedState = FeedContentState(localFilter, viewModelScope)
|
||||
|
||||
override val isRefreshing = feedState.isRefreshing
|
||||
|
||||
fun sendToTop() = feedState.sendToTop()
|
||||
|
||||
suspend fun sentToTop() = feedState.sentToTop()
|
||||
|
@@ -21,6 +21,7 @@
|
||||
package com.vitorpamplona.amethyst.ui.screen
|
||||
|
||||
import android.util.Log
|
||||
import androidx.compose.runtime.MutableState
|
||||
import androidx.compose.runtime.Stable
|
||||
import androidx.compose.runtime.mutableStateOf
|
||||
import androidx.lifecycle.ViewModel
|
||||
@@ -107,9 +108,14 @@ open class UserFeedViewModel(
|
||||
viewModelScope.launch(Dispatchers.Default) { refreshSuspended() }
|
||||
}
|
||||
|
||||
override val isRefreshing: MutableState<Boolean> = mutableStateOf(false)
|
||||
|
||||
private fun refreshSuspended() {
|
||||
checkNotInMainThread()
|
||||
|
||||
try {
|
||||
isRefreshing.value = true
|
||||
|
||||
val notes = dataSource.loadTop().toImmutableList()
|
||||
|
||||
val oldNotesState = _feedContent.value
|
||||
@@ -121,6 +127,9 @@ open class UserFeedViewModel(
|
||||
} else {
|
||||
updateFeed(notes)
|
||||
}
|
||||
} finally {
|
||||
isRefreshing.value = false
|
||||
}
|
||||
}
|
||||
|
||||
private fun updateFeed(notes: ImmutableList<User>) {
|
||||
|
@@ -22,7 +22,9 @@ package com.vitorpamplona.amethyst.ui.screen.loggedIn.notifications
|
||||
|
||||
import android.util.Log
|
||||
import androidx.compose.runtime.Immutable
|
||||
import androidx.compose.runtime.MutableState
|
||||
import androidx.compose.runtime.Stable
|
||||
import androidx.compose.runtime.mutableStateOf
|
||||
import com.vitorpamplona.amethyst.model.Account
|
||||
import com.vitorpamplona.amethyst.model.LocalCache
|
||||
import com.vitorpamplona.amethyst.model.Note
|
||||
@@ -72,6 +74,8 @@ class CardFeedContentState(
|
||||
|
||||
private var lastFeedKey: String? = null
|
||||
|
||||
override val isRefreshing: MutableState<Boolean> = mutableStateOf(false)
|
||||
|
||||
fun sendToTop() {
|
||||
if (scrolltoTopPending) return
|
||||
|
||||
@@ -94,6 +98,9 @@ class CardFeedContentState(
|
||||
private fun refreshSuspended() {
|
||||
checkNotInMainThread()
|
||||
|
||||
try {
|
||||
isRefreshing.value = true
|
||||
|
||||
val notes = localFilter.feed()
|
||||
lastFeedKey = localFilter.feedKey()
|
||||
|
||||
@@ -130,6 +137,9 @@ class CardFeedContentState(
|
||||
|
||||
updateFeed(cards)
|
||||
}
|
||||
} finally {
|
||||
isRefreshing.value = false
|
||||
}
|
||||
}
|
||||
|
||||
private fun convertToCard(notes: Collection<Note>): List<Card> {
|
||||
|
@@ -21,7 +21,9 @@
|
||||
package com.vitorpamplona.amethyst.ui.screen.loggedIn.profile
|
||||
|
||||
import android.util.Log
|
||||
import androidx.compose.runtime.MutableState
|
||||
import androidx.compose.runtime.Stable
|
||||
import androidx.compose.runtime.mutableStateOf
|
||||
import androidx.lifecycle.ViewModel
|
||||
import androidx.lifecycle.viewModelScope
|
||||
import com.vitorpamplona.amethyst.model.RelayInfo
|
||||
@@ -50,11 +52,16 @@ class RelayFeedViewModel :
|
||||
|
||||
var currentUser: User? = null
|
||||
|
||||
override val isRefreshing: MutableState<Boolean> = mutableStateOf(false)
|
||||
|
||||
fun refresh() {
|
||||
viewModelScope.launch(Dispatchers.Default) { refreshSuspended() }
|
||||
}
|
||||
|
||||
fun refreshSuspended() {
|
||||
try {
|
||||
isRefreshing.value = true
|
||||
|
||||
val beingUsed = currentUser?.relaysBeingUsed?.values ?: emptyList()
|
||||
val beingUsedSet = currentUser?.relaysBeingUsed?.keys ?: emptySet()
|
||||
|
||||
@@ -72,6 +79,9 @@ class RelayFeedViewModel :
|
||||
val newList = (beingUsed + newRelaysFromRecord).sortedWith(order)
|
||||
|
||||
_feedContent.update { newList }
|
||||
} finally {
|
||||
isRefreshing.value = false
|
||||
}
|
||||
}
|
||||
|
||||
val listener: (UserState) -> Unit = { invalidateData() }
|
||||
|
@@ -21,6 +21,7 @@
|
||||
package com.vitorpamplona.amethyst.ui.screen.loggedIn.settings
|
||||
|
||||
import android.util.Log
|
||||
import androidx.compose.runtime.MutableState
|
||||
import androidx.compose.runtime.Stable
|
||||
import androidx.compose.runtime.mutableStateOf
|
||||
import androidx.lifecycle.ViewModel
|
||||
@@ -63,6 +64,8 @@ open class StringFeedViewModel(
|
||||
private val _feedContent = MutableStateFlow<StringFeedState>(StringFeedState.Loading)
|
||||
val feedContent = _feedContent.asStateFlow()
|
||||
|
||||
override val isRefreshing: MutableState<Boolean> = mutableStateOf(false)
|
||||
|
||||
private fun refresh() {
|
||||
viewModelScope.launch(Dispatchers.Default) { refreshSuspended() }
|
||||
}
|
||||
@@ -70,6 +73,9 @@ open class StringFeedViewModel(
|
||||
private fun refreshSuspended() {
|
||||
checkNotInMainThread()
|
||||
|
||||
try {
|
||||
isRefreshing.value = true
|
||||
|
||||
val notes = dataSource.loadTop().toImmutableList()
|
||||
|
||||
val oldNotesState = _feedContent.value
|
||||
@@ -81,6 +87,9 @@ open class StringFeedViewModel(
|
||||
} else {
|
||||
updateFeed(notes)
|
||||
}
|
||||
} finally {
|
||||
isRefreshing.value = false
|
||||
}
|
||||
}
|
||||
|
||||
private fun updateFeed(notes: ImmutableList<String>) {
|
||||
|
Reference in New Issue
Block a user