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 OnSendMsisdnSuccess(val msisdn: String) : OnboardingViewEvents()
|
||||||
|
|
||||||
data class OnWebLoginError(val errorCode: Int, val description: String, val failingUrl: 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
|
null
|
||||||
}
|
}
|
||||||
?.let { onSessionCreated(it) }
|
?.let { onSessionCreated(it, isAccountCreated = false) }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -314,7 +314,7 @@ class OnboardingViewModel @AssistedInject constructor(
|
||||||
}
|
}
|
||||||
?.let { data ->
|
?.let { data ->
|
||||||
when (data) {
|
when (data) {
|
||||||
is RegistrationResult.Success -> onSessionCreated(data.session)
|
is RegistrationResult.Success -> onSessionCreated(data.session, isAccountCreated = true)
|
||||||
is RegistrationResult.FlowResponse -> onFlowResponse(data.flowResult)
|
is RegistrationResult.FlowResponse -> onFlowResponse(data.flowResult)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -615,11 +615,11 @@ class OnboardingViewModel @AssistedInject constructor(
|
||||||
}
|
}
|
||||||
when (data) {
|
when (data) {
|
||||||
is WellknownResult.Prompt ->
|
is WellknownResult.Prompt ->
|
||||||
onWellknownSuccess(action, data, homeServerConnectionConfig)
|
directLoginOnWellknownSuccess(action, data, homeServerConnectionConfig)
|
||||||
is WellknownResult.FailPrompt ->
|
is WellknownResult.FailPrompt ->
|
||||||
// Relax on IS discovery if homeserver is valid
|
// Relax on IS discovery if homeserver is valid
|
||||||
if (data.homeServerUrl != null && data.wellKnown != null) {
|
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 {
|
} else {
|
||||||
onWellKnownError()
|
onWellKnownError()
|
||||||
}
|
}
|
||||||
|
@ -639,7 +639,7 @@ class OnboardingViewModel @AssistedInject constructor(
|
||||||
_viewEvents.post(OnboardingViewEvents.Failure(Exception(stringProvider.getString(R.string.autodiscover_well_known_error))))
|
_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,
|
wellKnownPrompt: WellknownResult.Prompt,
|
||||||
homeServerConnectionConfig: HomeServerConnectionConfig?) {
|
homeServerConnectionConfig: HomeServerConnectionConfig?) {
|
||||||
val alteredHomeServerConnectionConfig = homeServerConnectionConfig
|
val alteredHomeServerConnectionConfig = homeServerConnectionConfig
|
||||||
|
@ -663,7 +663,7 @@ class OnboardingViewModel @AssistedInject constructor(
|
||||||
onDirectLoginError(failure)
|
onDirectLoginError(failure)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
onSessionCreated(data)
|
onSessionCreated(data, isAccountCreated = true)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun onDirectLoginError(failure: Throwable) {
|
private fun onDirectLoginError(failure: Throwable) {
|
||||||
|
@ -721,7 +721,7 @@ class OnboardingViewModel @AssistedInject constructor(
|
||||||
}
|
}
|
||||||
?.let {
|
?.let {
|
||||||
reAuthHelper.data = action.password
|
reAuthHelper.data = action.password
|
||||||
onSessionCreated(it)
|
onSessionCreated(it, isAccountCreated = false)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -751,8 +751,9 @@ class OnboardingViewModel @AssistedInject constructor(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private suspend fun onSessionCreated(session: Session) {
|
private suspend fun onSessionCreated(session: Session, isAccountCreated: Boolean) {
|
||||||
awaitState().useCase?.let { useCase ->
|
val state = awaitState()
|
||||||
|
state.useCase?.let { useCase ->
|
||||||
session.vectorStore(applicationContext).setUseCase(useCase)
|
session.vectorStore(applicationContext).setUseCase(useCase)
|
||||||
}
|
}
|
||||||
activeSessionHolder.setActiveSession(session)
|
activeSessionHolder.setActiveSession(session)
|
||||||
|
@ -764,6 +765,11 @@ class OnboardingViewModel @AssistedInject constructor(
|
||||||
asyncLoginAction = Success(Unit)
|
asyncLoginAction = Success(Unit)
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
when (isAccountCreated) {
|
||||||
|
true -> _viewEvents.post(OnboardingViewEvents.OnAccountCreated)
|
||||||
|
false -> _viewEvents.post(OnboardingViewEvents.OnAccountSignedIn)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun handleWebLoginSuccess(action: OnboardingAction.WebLoginSuccess) = withState { state ->
|
private fun handleWebLoginSuccess(action: OnboardingAction.WebLoginSuccess) = withState { state ->
|
||||||
|
@ -782,7 +788,7 @@ class OnboardingViewModel @AssistedInject constructor(
|
||||||
}
|
}
|
||||||
null
|
null
|
||||||
}
|
}
|
||||||
?.let { onSessionCreated(it) }
|
?.let { onSessionCreated(it, isAccountCreated = false) }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -220,20 +220,12 @@ class FtueAuthVariant(
|
||||||
FtueAuthUseCaseFragment::class.java,
|
FtueAuthUseCaseFragment::class.java,
|
||||||
option = commonOption)
|
option = commonOption)
|
||||||
}
|
}
|
||||||
|
OnboardingViewEvents.OnAccountCreated -> onAccountCreated()
|
||||||
|
OnboardingViewEvents.OnAccountSignedIn -> onAccountSignedIn()
|
||||||
}.exhaustive
|
}.exhaustive
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun updateWithState(viewState: OnboardingViewState) {
|
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
|
// Loading
|
||||||
views.loginLoading.isVisible = viewState.isLoading()
|
views.loginLoading.isVisible = viewState.isLoading()
|
||||||
}
|
}
|
||||||
|
@ -368,4 +360,18 @@ class FtueAuthVariant(
|
||||||
else -> Unit // Should not happen
|
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