mirror of
https://github.com/element-hq/element-android
synced 2024-11-24 10:25:35 +03:00
splitting the homeserver edit from the selection so that we can handle the cases differently
This commit is contained in:
parent
1e520121ce
commit
e9f50038a4
6 changed files with 30 additions and 15 deletions
|
@ -30,6 +30,7 @@ sealed interface OnboardingAction : VectorViewModelAction {
|
|||
|
||||
data class UpdateServerType(val serverType: ServerType) : OnboardingAction
|
||||
data class SelectHomeServer(val homeServerUrl: String) : OnboardingAction
|
||||
data class EditHomeServer(val homeServerUrl: String) : OnboardingAction
|
||||
data class UpdateUseCase(val useCase: FtueUseCase) : OnboardingAction
|
||||
object ResetUseCase : OnboardingAction
|
||||
data class UpdateSignMode(val signMode: SignMode) : OnboardingAction
|
||||
|
|
|
@ -40,6 +40,7 @@ sealed class OnboardingViewEvents : VectorViewEvents {
|
|||
object EditServerSelection : OnboardingViewEvents()
|
||||
data class OnServerSelectionDone(val serverType: ServerType) : OnboardingViewEvents()
|
||||
object OnLoginFlowRetrieved : OnboardingViewEvents()
|
||||
object OnHomeserverEdited : OnboardingViewEvents()
|
||||
data class OnSignModeSelected(val signMode: SignMode) : OnboardingViewEvents()
|
||||
object OnForgetPasswordClicked : OnboardingViewEvents()
|
||||
object OnResetPasswordSendThreePidDone : OnboardingViewEvents()
|
||||
|
|
|
@ -140,7 +140,8 @@ class OnboardingViewModel @AssistedInject constructor(
|
|||
is OnboardingAction.UpdateServerType -> handleUpdateServerType(action)
|
||||
is OnboardingAction.UpdateSignMode -> handleUpdateSignMode(action)
|
||||
is OnboardingAction.InitWith -> handleInitWith(action)
|
||||
is OnboardingAction.SelectHomeServer -> handleSelectHomeserver(action).also { lastAction = action }
|
||||
is OnboardingAction.SelectHomeServer -> handleHomeserverChange(action.homeServerUrl).also { lastAction = action }
|
||||
is OnboardingAction.EditHomeServer -> handleHomeserverChange(action.homeServerUrl).also { lastAction = action }
|
||||
is OnboardingAction.LoginOrRegister -> handleLoginOrRegister(action).also { lastAction = action }
|
||||
is OnboardingAction.Register -> handleRegisterWith(action).also { lastAction = action }
|
||||
is OnboardingAction.LoginWithToken -> handleLoginWithToken(action)
|
||||
|
@ -576,8 +577,8 @@ class OnboardingViewModel @AssistedInject constructor(
|
|||
}
|
||||
}
|
||||
|
||||
private fun handleSelectHomeserver(action: OnboardingAction.SelectHomeServer) {
|
||||
val homeServerConnectionConfig = homeServerConnectionConfigFactory.create(action.homeServerUrl)
|
||||
private fun handleHomeserverChange(homeserverUrl: String) {
|
||||
val homeServerConnectionConfig = homeServerConnectionConfigFactory.create(homeserverUrl)
|
||||
if (homeServerConnectionConfig == null) {
|
||||
// This is invalid
|
||||
_viewEvents.post(OnboardingViewEvents.Failure(Throwable("Unable to create a HomeServerConnectionConfig")))
|
||||
|
@ -630,17 +631,23 @@ class OnboardingViewModel @AssistedInject constructor(
|
|||
|
||||
private fun onAuthenticationStartedSuccess() {
|
||||
withState {
|
||||
if (it.selectedHomeserver.preferredLoginMode.supportsSignModeScreen()) {
|
||||
when (it.onboardingFlow) {
|
||||
OnboardingFlow.SignIn -> handleUpdateSignMode(OnboardingAction.UpdateSignMode(SignMode.SignIn))
|
||||
OnboardingFlow.SignUp -> handleUpdateSignMode(OnboardingAction.UpdateSignMode(SignMode.SignUp))
|
||||
OnboardingFlow.SignInSignUp,
|
||||
null -> {
|
||||
when (lastAction) {
|
||||
is OnboardingAction.EditHomeServer -> _viewEvents.post(OnboardingViewEvents.OnHomeserverEdited)
|
||||
is OnboardingAction.SelectHomeServer -> {
|
||||
if (it.selectedHomeserver.preferredLoginMode.supportsSignModeScreen()) {
|
||||
when (it.onboardingFlow) {
|
||||
OnboardingFlow.SignIn -> handleUpdateSignMode(OnboardingAction.UpdateSignMode(SignMode.SignIn))
|
||||
OnboardingFlow.SignUp -> handleUpdateSignMode(OnboardingAction.UpdateSignMode(SignMode.SignUp))
|
||||
OnboardingFlow.SignInSignUp,
|
||||
null -> {
|
||||
_viewEvents.post(OnboardingViewEvents.OnLoginFlowRetrieved)
|
||||
}
|
||||
}
|
||||
} else {
|
||||
_viewEvents.post(OnboardingViewEvents.OnLoginFlowRetrieved)
|
||||
}
|
||||
}
|
||||
} else {
|
||||
_viewEvents.post(OnboardingViewEvents.OnLoginFlowRetrieved)
|
||||
else -> _viewEvents.post(OnboardingViewEvents.OnLoginFlowRetrieved)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -43,7 +43,7 @@ class StartAuthenticationFlowUseCase @Inject constructor(
|
|||
private fun createSelectedHomeserverState(authFlow: LoginFlowResult, config: HomeServerConnectionConfig, preferredLoginMode: LoginMode): SelectedHomeserverState {
|
||||
val matrixOrgUrl = stringProvider.getString(R.string.matrix_org_server_url).ensureTrailingSlash()
|
||||
return SelectedHomeserverState(
|
||||
description = when (authFlow.homeServerUrl) {
|
||||
description = when (config.homeServerUri.toString()) {
|
||||
matrixOrgUrl -> stringProvider.getString(R.string.ftue_auth_create_account_matrix_dot_org_server_description)
|
||||
else -> null
|
||||
},
|
||||
|
|
|
@ -20,10 +20,13 @@ import android.os.Bundle
|
|||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import androidx.core.view.isEmpty
|
||||
import im.vector.app.core.extensions.content
|
||||
import im.vector.app.core.extensions.editText
|
||||
import im.vector.app.core.extensions.realignPercentagesToParent
|
||||
import im.vector.app.core.extensions.toReducedUrl
|
||||
import im.vector.app.core.utils.ensureProtocol
|
||||
import im.vector.app.core.utils.ensureTrailingSlash
|
||||
import im.vector.app.databinding.FragmentFtueServerSelectionCombinedBinding
|
||||
import im.vector.app.features.onboarding.OnboardingAction
|
||||
import im.vector.app.features.onboarding.OnboardingViewEvents
|
||||
|
@ -45,7 +48,7 @@ class FtueAuthCombinedServerSelectionFragment @Inject constructor() : AbstractFt
|
|||
}
|
||||
|
||||
views.chooseServerSubmit.debouncedClicks {
|
||||
viewModel.handle(OnboardingAction.SelectHomeServer(views.chooseServerInput.content()))
|
||||
viewModel.handle(OnboardingAction.EditHomeServer(views.chooseServerInput.content().ensureProtocol().ensureTrailingSlash()))
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -54,8 +57,10 @@ class FtueAuthCombinedServerSelectionFragment @Inject constructor() : AbstractFt
|
|||
}
|
||||
|
||||
override fun updateWithState(state: OnboardingViewState) {
|
||||
val userUrlInput = state.selectedHomeserver.sourceUrl?.toReducedUrlKeepingSchemaIfInsecure()
|
||||
views.chooseServerInput.editText().setText(userUrlInput)
|
||||
if (views.chooseServerInput.isEmpty()) {
|
||||
val userUrlInput = state.selectedHomeserver.sourceUrl?.toReducedUrlKeepingSchemaIfInsecure()
|
||||
views.chooseServerInput.editText().setText(userUrlInput)
|
||||
}
|
||||
}
|
||||
|
||||
private fun String.toReducedUrlKeepingSchemaIfInsecure() = toReducedUrl(keepSchema = this.startsWith("http://"))
|
||||
|
|
|
@ -240,6 +240,7 @@ class FtueAuthVariant(
|
|||
option = commonOption
|
||||
)
|
||||
}
|
||||
OnboardingViewEvents.OnHomeserverEdited -> activity.popBackstack()
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue