diff --git a/vector/src/main/java/im/vector/app/features/onboarding/OnboardingViewModel.kt b/vector/src/main/java/im/vector/app/features/onboarding/OnboardingViewModel.kt index e7302cb1e2..6ebbffa6e3 100644 --- a/vector/src/main/java/im/vector/app/features/onboarding/OnboardingViewModel.kt +++ b/vector/src/main/java/im/vector/app/features/onboarding/OnboardingViewModel.kt @@ -828,20 +828,20 @@ class OnboardingViewModel @AssistedInject constructor( } private fun updateDisplayName(displayName: String) { - setState { copy(asyncDisplayName = Loading()) } + setState { copy(isLoading = true) } viewModelScope.launch { val activeSession = activeSessionHolder.getActiveSession() try { activeSession.setDisplayName(activeSession.myUserId, displayName) setState { copy( - asyncDisplayName = Success(Unit), + isLoading = false, personalizationState = personalizationState.copy(displayName = displayName) ) } handleDisplayNameStepComplete() } catch (error: Throwable) { - setState { copy(asyncDisplayName = Fail(error)) } + setState { copy(isLoading = false) } _viewEvents.post(OnboardingViewEvents.Failure(error)) } } @@ -883,7 +883,7 @@ class OnboardingViewModel @AssistedInject constructor( when (val pictureUri = state.personalizationState.selectedPictureUri) { null -> _viewEvents.post(OnboardingViewEvents.Failure(NullPointerException("picture uri is missing from state"))) else -> { - setState { copy(asyncProfilePicture = Loading()) } + setState { copy(isLoading = true) } viewModelScope.launch { val activeSession = activeSessionHolder.getActiveSession() try { @@ -894,12 +894,12 @@ class OnboardingViewModel @AssistedInject constructor( ) setState { copy( - asyncProfilePicture = Success(Unit), + isLoading = false, ) } onProfilePictureSaved() } catch (error: Throwable) { - setState { copy(asyncProfilePicture = Fail(error)) } + setState { copy(isLoading = false) } _viewEvents.post(OnboardingViewEvents.Failure(error)) } } diff --git a/vector/src/main/java/im/vector/app/features/onboarding/OnboardingViewState.kt b/vector/src/main/java/im/vector/app/features/onboarding/OnboardingViewState.kt index 8747de6da8..cdb68cfdac 100644 --- a/vector/src/main/java/im/vector/app/features/onboarding/OnboardingViewState.kt +++ b/vector/src/main/java/im/vector/app/features/onboarding/OnboardingViewState.kt @@ -34,8 +34,7 @@ data class OnboardingViewState( val asyncResetPassword: Async = Uninitialized, val asyncResetMailConfirmed: Async = Uninitialized, val asyncRegistration: Async = Uninitialized, - val asyncDisplayName: Async = Uninitialized, - val asyncProfilePicture: Async = Uninitialized, + val isLoading: Boolean = false, @PersistState val onboardingFlow: OnboardingFlow? = null, @@ -73,14 +72,12 @@ data class OnboardingViewState( val personalizationState: PersonalizationState = PersonalizationState() ) : MavericksState { - fun isLoading(): Boolean { + fun legacyIsLoading(): Boolean { return asyncLoginAction is Loading || asyncHomeServerLoginFlowRequest is Loading || asyncResetPassword is Loading || asyncResetMailConfirmed is Loading || - asyncRegistration is Loading || - asyncDisplayName is Loading || - asyncProfilePicture is Loading + asyncRegistration is Loading } } diff --git a/vector/src/main/java/im/vector/app/features/onboarding/ftueauth/FtueAuthVariant.kt b/vector/src/main/java/im/vector/app/features/onboarding/ftueauth/FtueAuthVariant.kt index 13b5f61010..b8319c9f3a 100644 --- a/vector/src/main/java/im/vector/app/features/onboarding/ftueauth/FtueAuthVariant.kt +++ b/vector/src/main/java/im/vector/app/features/onboarding/ftueauth/FtueAuthVariant.kt @@ -121,7 +121,7 @@ class FtueAuthVariant( private fun updateWithState(viewState: OnboardingViewState) { isForceLoginFallbackEnabled = viewState.isForceLoginFallbackEnabled - views.loginLoading.isVisible = viewState.isLoading() + views.loginLoading.isVisible = viewState.isLoading || viewState.legacyIsLoading() } override fun setIsLoading(isLoading: Boolean) = Unit diff --git a/vector/src/test/java/im/vector/app/features/onboarding/OnboardingViewModelTest.kt b/vector/src/test/java/im/vector/app/features/onboarding/OnboardingViewModelTest.kt index 4fd079611d..20e6ceb55d 100644 --- a/vector/src/test/java/im/vector/app/features/onboarding/OnboardingViewModelTest.kt +++ b/vector/src/test/java/im/vector/app/features/onboarding/OnboardingViewModelTest.kt @@ -17,7 +17,6 @@ package im.vector.app.features.onboarding import android.net.Uri -import com.airbnb.mvrx.Fail import com.airbnb.mvrx.Loading import com.airbnb.mvrx.Success import com.airbnb.mvrx.Uninitialized @@ -260,8 +259,8 @@ class OnboardingViewModelTest { test .assertStatesChanges( initialState, - { copy(asyncDisplayName = Loading()) }, - { copy(asyncDisplayName = Fail(AN_ERROR)) }, + { copy(isLoading = true) }, + { copy(isLoading = false) }, ) .assertEvents(OnboardingViewEvents.Failure(AN_ERROR)) .finish() @@ -307,7 +306,7 @@ class OnboardingViewModelTest { viewModel.handle(OnboardingAction.SaveSelectedProfilePicture) test - .assertStates(expectedProfilePictureFailureStates(initialStateWithPicture, AN_ERROR)) + .assertStates(expectedProfilePictureFailureStates(initialStateWithPicture)) .assertEvents(OnboardingViewEvents.Failure(AN_ERROR)) .finish() } @@ -362,20 +361,20 @@ class OnboardingViewModelTest { private fun expectedProfilePictureSuccessStates(state: OnboardingViewState) = listOf( state, - state.copy(asyncProfilePicture = Loading()), - state.copy(asyncProfilePicture = Success(Unit)) + state.copy(isLoading = true), + state.copy(isLoading = false) ) - private fun expectedProfilePictureFailureStates(state: OnboardingViewState, cause: Exception) = listOf( + private fun expectedProfilePictureFailureStates(state: OnboardingViewState) = listOf( state, - state.copy(asyncProfilePicture = Loading()), - state.copy(asyncProfilePicture = Fail(cause)) + state.copy(isLoading = true), + state.copy(isLoading = false) ) private fun expectedSuccessfulDisplayNameUpdateStates(): List OnboardingViewState> { return listOf( - { copy(asyncDisplayName = Loading()) }, - { copy(asyncDisplayName = Success(Unit), personalizationState = personalizationState.copy(displayName = A_DISPLAY_NAME)) } + { copy(isLoading = true) }, + { copy(isLoading = false, personalizationState = personalizationState.copy(displayName = A_DISPLAY_NAME)) } ) }