Merge 6e48b6ad79
into 9087b4186f
This commit is contained in:
commit
9dcc6deb47
|
@ -479,8 +479,8 @@ class AccountActivity : BottomSheetActivity(), ActionButtonActivity, MenuProvide
|
|||
private fun setupRefreshLayout() {
|
||||
binding.swipeToRefreshLayout.setOnRefreshListener { onRefresh() }
|
||||
lifecycleScope.launch {
|
||||
viewModel.isRefreshing.collect { isRefreshing ->
|
||||
binding.swipeToRefreshLayout.isRefreshing = isRefreshing == true
|
||||
viewModel.isRefreshing.collect {
|
||||
binding.swipeToRefreshLayout.isRefreshing = it
|
||||
}
|
||||
}
|
||||
binding.swipeToRefreshLayout.setColorSchemeResources(R.color.tusky_blue)
|
||||
|
@ -1063,7 +1063,6 @@ class AccountActivity : BottomSheetActivity(), ActionButtonActivity, MenuProvide
|
|||
return true
|
||||
}
|
||||
R.id.action_refresh -> {
|
||||
binding.swipeToRefreshLayout.isRefreshing = true
|
||||
onRefresh()
|
||||
return true
|
||||
}
|
||||
|
|
|
@ -21,13 +21,9 @@ 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
|
||||
|
||||
|
@ -46,10 +42,8 @@ class AccountViewModel @Inject constructor(
|
|||
private val _noteSaved = MutableStateFlow(false)
|
||||
val noteSaved: StateFlow<Boolean> = _noteSaved.asStateFlow()
|
||||
|
||||
private val _isRefreshing = MutableSharedFlow<Boolean>(1, onBufferOverflow = BufferOverflow.DROP_OLDEST)
|
||||
val isRefreshing: SharedFlow<Boolean> = _isRefreshing.asSharedFlow()
|
||||
|
||||
private var isDataLoading = false
|
||||
private val _isRefreshing = MutableStateFlow(false)
|
||||
val isRefreshing: StateFlow<Boolean> = _isRefreshing.asStateFlow()
|
||||
|
||||
lateinit var accountId: String
|
||||
var isSelf = false
|
||||
|
@ -76,7 +70,9 @@ class AccountViewModel @Inject constructor(
|
|||
|
||||
private fun obtainAccount(reload: Boolean = false) {
|
||||
if (_accountData.value == null || reload) {
|
||||
isDataLoading = true
|
||||
if (reload) {
|
||||
_isRefreshing.value = true
|
||||
}
|
||||
_accountData.value = Loading()
|
||||
|
||||
viewModelScope.launch {
|
||||
|
@ -87,14 +83,12 @@ class AccountViewModel @Inject constructor(
|
|||
isFromOwnDomain = domain == activeAccount.domain
|
||||
|
||||
_accountData.value = Success(account)
|
||||
isDataLoading = false
|
||||
_isRefreshing.emit(false)
|
||||
_isRefreshing.value = false
|
||||
},
|
||||
{ t ->
|
||||
Log.w(TAG, "failed obtaining account", t)
|
||||
_accountData.value = Error(cause = t)
|
||||
isDataLoading = false
|
||||
_isRefreshing.emit(false)
|
||||
_isRefreshing.value = false
|
||||
}
|
||||
)
|
||||
}
|
||||
|
@ -316,7 +310,7 @@ class AccountViewModel @Inject constructor(
|
|||
}
|
||||
|
||||
private fun reload(isReload: Boolean = false) {
|
||||
if (isDataLoading) {
|
||||
if (_isRefreshing.value) {
|
||||
return
|
||||
}
|
||||
accountId.let {
|
||||
|
|
Loading…
Reference in New Issue