completing the onboarding via dedicated event rather than observing state
- allows for greater control of the flow (such as adding new screens inbetween the creation and exit with flags)
This commit is contained in:
parent
9b12f295d1
commit
8212b7e219
|
@ -48,4 +48,6 @@ sealed class OnboardingViewEvents : VectorViewEvents {
|
|||
data class OnSendMsisdnSuccess(val msisdn: String) : OnboardingViewEvents()
|
||||
|
||||
data class OnWebLoginError(val errorCode: Int, val description: String, val failingUrl: String) : OnboardingViewEvents()
|
||||
object OnAccountCreated: OnboardingViewEvents()
|
||||
object OnAccountSignedIn: OnboardingViewEvents()
|
||||
}
|
||||
|
|
|
@ -244,7 +244,7 @@ class OnboardingViewModel @AssistedInject constructor(
|
|||
}
|
||||
null
|
||||
}
|
||||
?.let { onSessionCreated(it) }
|
||||
?.let { onSessionCreated(it, isAccountCreated = false) }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -314,7 +314,7 @@ class OnboardingViewModel @AssistedInject constructor(
|
|||
}
|
||||
?.let { data ->
|
||||
when (data) {
|
||||
is RegistrationResult.Success -> onSessionCreated(data.session)
|
||||
is RegistrationResult.Success -> onSessionCreated(data.session, isAccountCreated = true)
|
||||
is RegistrationResult.FlowResponse -> onFlowResponse(data.flowResult)
|
||||
}
|
||||
}
|
||||
|
@ -615,11 +615,11 @@ class OnboardingViewModel @AssistedInject constructor(
|
|||
}
|
||||
when (data) {
|
||||
is WellknownResult.Prompt ->
|
||||
onWellknownSuccess(action, data, homeServerConnectionConfig)
|
||||
directLoginOnWellknownSuccess(action, data, homeServerConnectionConfig)
|
||||
is WellknownResult.FailPrompt ->
|
||||
// Relax on IS discovery if homeserver is valid
|
||||
if (data.homeServerUrl != null && data.wellKnown != null) {
|
||||
onWellknownSuccess(action, WellknownResult.Prompt(data.homeServerUrl!!, null, data.wellKnown!!), homeServerConnectionConfig)
|
||||
directLoginOnWellknownSuccess(action, WellknownResult.Prompt(data.homeServerUrl!!, null, data.wellKnown!!), homeServerConnectionConfig)
|
||||
} else {
|
||||
onWellKnownError()
|
||||
}
|
||||
|
@ -639,7 +639,7 @@ class OnboardingViewModel @AssistedInject constructor(
|
|||
_viewEvents.post(OnboardingViewEvents.Failure(Exception(stringProvider.getString(R.string.autodiscover_well_known_error))))
|
||||
}
|
||||
|
||||
private suspend fun onWellknownSuccess(action: OnboardingAction.LoginOrRegister,
|
||||
private suspend fun directLoginOnWellknownSuccess(action: OnboardingAction.LoginOrRegister,
|
||||
wellKnownPrompt: WellknownResult.Prompt,
|
||||
homeServerConnectionConfig: HomeServerConnectionConfig?) {
|
||||
val alteredHomeServerConnectionConfig = homeServerConnectionConfig
|
||||
|
@ -663,7 +663,7 @@ class OnboardingViewModel @AssistedInject constructor(
|
|||
onDirectLoginError(failure)
|
||||
return
|
||||
}
|
||||
onSessionCreated(data)
|
||||
onSessionCreated(data, isAccountCreated = true)
|
||||
}
|
||||
|
||||
private fun onDirectLoginError(failure: Throwable) {
|
||||
|
@ -721,7 +721,7 @@ class OnboardingViewModel @AssistedInject constructor(
|
|||
}
|
||||
?.let {
|
||||
reAuthHelper.data = action.password
|
||||
onSessionCreated(it)
|
||||
onSessionCreated(it, isAccountCreated = false)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -751,8 +751,9 @@ class OnboardingViewModel @AssistedInject constructor(
|
|||
}
|
||||
}
|
||||
|
||||
private suspend fun onSessionCreated(session: Session) {
|
||||
awaitState().useCase?.let { useCase ->
|
||||
private suspend fun onSessionCreated(session: Session, isAccountCreated: Boolean) {
|
||||
val state = awaitState()
|
||||
state.useCase?.let { useCase ->
|
||||
session.vectorStore(applicationContext).setUseCase(useCase)
|
||||
}
|
||||
activeSessionHolder.setActiveSession(session)
|
||||
|
@ -764,6 +765,11 @@ class OnboardingViewModel @AssistedInject constructor(
|
|||
asyncLoginAction = Success(Unit)
|
||||
)
|
||||
}
|
||||
|
||||
when (isAccountCreated) {
|
||||
true -> _viewEvents.post(OnboardingViewEvents.OnAccountCreated)
|
||||
false -> _viewEvents.post(OnboardingViewEvents.OnAccountSignedIn)
|
||||
}
|
||||
}
|
||||
|
||||
private fun handleWebLoginSuccess(action: OnboardingAction.WebLoginSuccess) = withState { state ->
|
||||
|
@ -782,7 +788,7 @@ class OnboardingViewModel @AssistedInject constructor(
|
|||
}
|
||||
null
|
||||
}
|
||||
?.let { onSessionCreated(it) }
|
||||
?.let { onSessionCreated(it, isAccountCreated = false) }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -220,20 +220,12 @@ class FtueAuthVariant(
|
|||
FtueAuthUseCaseFragment::class.java,
|
||||
option = commonOption)
|
||||
}
|
||||
OnboardingViewEvents.OnAccountCreated -> onAccountCreated()
|
||||
OnboardingViewEvents.OnAccountSignedIn -> onAccountSignedIn()
|
||||
}.exhaustive
|
||||
}
|
||||
|
||||
private fun updateWithState(viewState: OnboardingViewState) {
|
||||
if (viewState.isUserLogged()) {
|
||||
val intent = HomeActivity.newIntent(
|
||||
activity,
|
||||
accountCreation = viewState.signMode == SignMode.SignUp
|
||||
)
|
||||
activity.startActivity(intent)
|
||||
activity.finish()
|
||||
return
|
||||
}
|
||||
|
||||
// Loading
|
||||
views.loginLoading.isVisible = viewState.isLoading()
|
||||
}
|
||||
|
@ -368,4 +360,18 @@ class FtueAuthVariant(
|
|||
else -> Unit // Should not happen
|
||||
}
|
||||
}
|
||||
|
||||
private fun onAccountSignedIn() {
|
||||
navigateToHome(createdAccount = false)
|
||||
}
|
||||
|
||||
private fun onAccountCreated() {
|
||||
navigateToHome(createdAccount = true)
|
||||
}
|
||||
|
||||
private fun navigateToHome(createdAccount: Boolean) {
|
||||
val intent = HomeActivity.newIntent(activity, accountCreation = createdAccount)
|
||||
activity.startActivity(intent)
|
||||
activity.finish()
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue