Revert "Use refreshing state"

This reverts commit 3d283bd5
This commit is contained in:
Goooler 2024-04-11 08:16:14 +08:00
parent 26d19e2229
commit 6e48b6ad79
2 changed files with 8 additions and 22 deletions

View File

@ -488,16 +488,8 @@ class AccountActivity : BottomSheetActivity(), ActionButtonActivity, MenuProvide
private fun setupRefreshLayout() { private fun setupRefreshLayout() {
binding.swipeToRefreshLayout.setOnRefreshListener { onRefresh() } binding.swipeToRefreshLayout.setOnRefreshListener { onRefresh() }
lifecycleScope.launch { lifecycleScope.launch {
viewModel.refreshState.collect { viewModel.isRefreshing.collect {
when (it) { binding.swipeToRefreshLayout.isRefreshing = it
AccountViewModel.RefreshState.INITIAL -> Unit
AccountViewModel.RefreshState.REFRESHING -> {
binding.swipeToRefreshLayout.isRefreshing = true
}
AccountViewModel.RefreshState.IDLE -> {
binding.swipeToRefreshLayout.isRefreshing = false
}
}
} }
} }
binding.swipeToRefreshLayout.setColorSchemeResources(R.color.tusky_blue) binding.swipeToRefreshLayout.setColorSchemeResources(R.color.tusky_blue)

View File

@ -42,8 +42,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 _refreshState = MutableStateFlow(RefreshState.INITIAL) private val _isRefreshing = MutableStateFlow(false)
val refreshState: StateFlow<RefreshState> = _refreshState.asStateFlow() val isRefreshing: StateFlow<Boolean> = _isRefreshing.asStateFlow()
lateinit var accountId: String lateinit var accountId: String
var isSelf = false var isSelf = false
@ -71,7 +71,7 @@ class AccountViewModel @Inject constructor(
private fun obtainAccount(reload: Boolean = false) { private fun obtainAccount(reload: Boolean = false) {
if (_accountData.value == null || reload) { if (_accountData.value == null || reload) {
if (reload) { if (reload) {
_refreshState.value = RefreshState.REFRESHING _isRefreshing.value = true
} }
_accountData.value = Loading() _accountData.value = Loading()
@ -83,12 +83,12 @@ class AccountViewModel @Inject constructor(
isFromOwnDomain = domain == activeAccount.domain isFromOwnDomain = domain == activeAccount.domain
_accountData.value = Success(account) _accountData.value = Success(account)
_refreshState.value = RefreshState.IDLE _isRefreshing.value = 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)
_refreshState.value = RefreshState.IDLE _isRefreshing.value = false
} }
) )
} }
@ -310,7 +310,7 @@ class AccountViewModel @Inject constructor(
} }
private fun reload(isReload: Boolean = false) { private fun reload(isReload: Boolean = false) {
if (_refreshState.value == RefreshState.REFRESHING) { if (_isRefreshing.value) {
return return
} }
accountId.let { accountId.let {
@ -338,12 +338,6 @@ class AccountViewModel @Inject constructor(
UNSUBSCRIBE UNSUBSCRIBE
} }
enum class RefreshState {
INITIAL,
REFRESHING,
IDLE
}
companion object { companion object {
const val TAG = "AccountViewModel" const val TAG = "AccountViewModel"
} }