From 5343766886fec9bd1812c28d4383c1c7955b961a Mon Sep 17 00:00:00 2001 From: Konrad Pozniak Date: Sat, 30 Mar 2024 11:31:29 +0100 Subject: [PATCH] fix swipe-refresh spinner showing forever when refreshing AccountActivity (#4345) The flow must emit every update even if the values are the same, so use SharedFlow instead of StateFlow. Regression from https://github.com/tuskyapp/Tusky/pull/4337 cc @Goooler --- .../tusky/components/account/AccountViewModel.kt | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/app/src/main/java/com/keylesspalace/tusky/components/account/AccountViewModel.kt b/app/src/main/java/com/keylesspalace/tusky/components/account/AccountViewModel.kt index c21e679d..91d6dd0e 100644 --- a/app/src/main/java/com/keylesspalace/tusky/components/account/AccountViewModel.kt +++ b/app/src/main/java/com/keylesspalace/tusky/components/account/AccountViewModel.kt @@ -21,9 +21,13 @@ import com.keylesspalace.tusky.util.Success import com.keylesspalace.tusky.util.getDomain import javax.inject.Inject import kotlinx.coroutines.Job +import kotlinx.coroutines.channels.BufferOverflow import kotlinx.coroutines.delay +import kotlinx.coroutines.flow.MutableSharedFlow import kotlinx.coroutines.flow.MutableStateFlow +import kotlinx.coroutines.flow.SharedFlow import kotlinx.coroutines.flow.StateFlow +import kotlinx.coroutines.flow.asSharedFlow import kotlinx.coroutines.flow.asStateFlow import kotlinx.coroutines.launch @@ -42,8 +46,8 @@ class AccountViewModel @Inject constructor( private val _noteSaved = MutableStateFlow(false) val noteSaved: StateFlow = _noteSaved.asStateFlow() - private val _isRefreshing = MutableStateFlow(false) - val isRefreshing: StateFlow = _isRefreshing.asStateFlow() + private val _isRefreshing = MutableSharedFlow(1, onBufferOverflow = BufferOverflow.DROP_OLDEST) + val isRefreshing: SharedFlow = _isRefreshing.asSharedFlow() private var isDataLoading = false @@ -84,13 +88,13 @@ class AccountViewModel @Inject constructor( _accountData.value = Success(account) isDataLoading = false - _isRefreshing.value = false + _isRefreshing.emit(false) }, { t -> Log.w(TAG, "failed obtaining account", t) _accountData.value = Error(cause = t) isDataLoading = false - _isRefreshing.value = false + _isRefreshing.emit(false) } ) }