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
This commit is contained in:
parent
9491ebb031
commit
5343766886
|
@ -21,9 +21,13 @@ import com.keylesspalace.tusky.util.Success
|
||||||
import com.keylesspalace.tusky.util.getDomain
|
import com.keylesspalace.tusky.util.getDomain
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
import kotlinx.coroutines.Job
|
import kotlinx.coroutines.Job
|
||||||
|
import kotlinx.coroutines.channels.BufferOverflow
|
||||||
import kotlinx.coroutines.delay
|
import kotlinx.coroutines.delay
|
||||||
|
import kotlinx.coroutines.flow.MutableSharedFlow
|
||||||
import kotlinx.coroutines.flow.MutableStateFlow
|
import kotlinx.coroutines.flow.MutableStateFlow
|
||||||
|
import kotlinx.coroutines.flow.SharedFlow
|
||||||
import kotlinx.coroutines.flow.StateFlow
|
import kotlinx.coroutines.flow.StateFlow
|
||||||
|
import kotlinx.coroutines.flow.asSharedFlow
|
||||||
import kotlinx.coroutines.flow.asStateFlow
|
import kotlinx.coroutines.flow.asStateFlow
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
|
|
||||||
|
@ -42,8 +46,8 @@ class AccountViewModel @Inject constructor(
|
||||||
private val _noteSaved = MutableStateFlow(false)
|
private val _noteSaved = MutableStateFlow(false)
|
||||||
val noteSaved: StateFlow<Boolean> = _noteSaved.asStateFlow()
|
val noteSaved: StateFlow<Boolean> = _noteSaved.asStateFlow()
|
||||||
|
|
||||||
private val _isRefreshing = MutableStateFlow(false)
|
private val _isRefreshing = MutableSharedFlow<Boolean>(1, onBufferOverflow = BufferOverflow.DROP_OLDEST)
|
||||||
val isRefreshing: StateFlow<Boolean> = _isRefreshing.asStateFlow()
|
val isRefreshing: SharedFlow<Boolean> = _isRefreshing.asSharedFlow()
|
||||||
|
|
||||||
private var isDataLoading = false
|
private var isDataLoading = false
|
||||||
|
|
||||||
|
@ -84,13 +88,13 @@ class AccountViewModel @Inject constructor(
|
||||||
|
|
||||||
_accountData.value = Success(account)
|
_accountData.value = Success(account)
|
||||||
isDataLoading = false
|
isDataLoading = false
|
||||||
_isRefreshing.value = false
|
_isRefreshing.emit(false)
|
||||||
},
|
},
|
||||||
{ t ->
|
{ t ->
|
||||||
Log.w(TAG, "failed obtaining account", t)
|
Log.w(TAG, "failed obtaining account", t)
|
||||||
_accountData.value = Error(cause = t)
|
_accountData.value = Error(cause = t)
|
||||||
isDataLoading = false
|
isDataLoading = false
|
||||||
_isRefreshing.value = false
|
_isRefreshing.emit(false)
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue