Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Better refreshing state indication for AccountActivity #4353

Open
wants to merge 9 commits into
base: develop
Choose a base branch
from

Conversation

Goooler
Copy link
Contributor

@Goooler Goooler commented Apr 2, 2024

@cbeyls
Copy link
Contributor

cbeyls commented Apr 2, 2024

Note: you can also remove

binding.swipeToRefreshLayout.isRefreshing = true

in AccountActivity (around line 1075). It's better to have the ViewModel as single source of truth for the refreshing state.

@Goooler
Copy link
Contributor Author

Goooler commented Apr 2, 2024

Good catch!

@connyduck
Copy link
Collaborator

Now the spinner shows up on the initial load which is very irritating imo.

@cbeyls
Copy link
Contributor

cbeyls commented Apr 4, 2024

Now the spinner shows up on the initial load which is very irritating imo.

The state could be enriched with some additional information differentiating an initial load from a refresh.

For example, instead of a boolean, use a sealed class:

sealed class LoadingState {
    data object Idle : LoadingState()

    data class Loading(val isRefresh: Boolean) : LoadingState()
}

binding.swipeToRefreshLayout.isRefreshing = it is LoadingState.Loading && it.isRefresh

@@ -76,7 +70,7 @@ class AccountViewModel @Inject constructor(

private fun obtainAccount(reload: Boolean = false) {
if (_accountData.value == null || reload) {
isDataLoading = true
_refreshState.value = RefreshState.REFRESHING
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
_refreshState.value = RefreshState.REFRESHING
if (reload) {
_refreshState.value = RefreshState.REFRESHING
}

Copy link
Contributor Author

@Goooler Goooler Apr 11, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't notice here is the key point, can we revert 3d283bd and use your logic here, it's a simple state.

  if (reload) {
      _isRefreshing.value = true
  }

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@@ -316,7 +310,7 @@ class AccountViewModel @Inject constructor(
}

private fun reload(isReload: Boolean = false) {
if (isDataLoading) {
if (_isRefreshing.value) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Two loads may still be triggered in parallel during the initial load, because _isRefreshing is not set to true in that case.

Hence I suggest to keep the loading state in a separate field, or merge loading and refreshing states together using a sealed class.

Alternatively, cancel the load in progress before starting a new one.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants