Skip to content

Commit

Permalink
fix swipe-refresh spinner showing forever when refreshing AccountActi…
Browse files Browse the repository at this point in the history
…vity (#4345)

The flow must emit every update even if the values are the same, so use
SharedFlow instead of StateFlow.

Regression from #4337 cc @Goooler
  • Loading branch information
connyduck authored Mar 30, 2024
1 parent 9491ebb commit 5343766
Showing 1 changed file with 8 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -42,8 +46,8 @@ class AccountViewModel @Inject constructor(
private val _noteSaved = MutableStateFlow(false)
val noteSaved: StateFlow<Boolean> = _noteSaved.asStateFlow()

private val _isRefreshing = MutableStateFlow(false)
val isRefreshing: StateFlow<Boolean> = _isRefreshing.asStateFlow()
private val _isRefreshing = MutableSharedFlow<Boolean>(1, onBufferOverflow = BufferOverflow.DROP_OLDEST)
val isRefreshing: SharedFlow<Boolean> = _isRefreshing.asSharedFlow()

private var isDataLoading = false

Expand Down Expand Up @@ -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)
}
)
}
Expand Down

0 comments on commit 5343766

Please sign in to comment.