using isLoading boolean instead of stateless async result for the display name and profile picture updates
This commit is contained in:
parent
adf2c642da
commit
e3df9c4cef
|
@ -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))
|
||||
}
|
||||
}
|
||||
|
|
|
@ -34,8 +34,7 @@ data class OnboardingViewState(
|
|||
val asyncResetPassword: Async<Unit> = Uninitialized,
|
||||
val asyncResetMailConfirmed: Async<Unit> = Uninitialized,
|
||||
val asyncRegistration: Async<Unit> = Uninitialized,
|
||||
val asyncDisplayName: Async<Unit> = Uninitialized,
|
||||
val asyncProfilePicture: Async<Unit> = 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
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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.() -> 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)) }
|
||||
)
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue