splitting the homeserver edit from the selection so that we can handle the cases differently

This commit is contained in:
Adam Brown 2022-04-01 16:53:54 +01:00
parent 1e520121ce
commit e9f50038a4
6 changed files with 30 additions and 15 deletions

View file

@ -30,6 +30,7 @@ sealed interface OnboardingAction : VectorViewModelAction {
data class UpdateServerType(val serverType: ServerType) : OnboardingAction data class UpdateServerType(val serverType: ServerType) : OnboardingAction
data class SelectHomeServer(val homeServerUrl: String) : OnboardingAction data class SelectHomeServer(val homeServerUrl: String) : OnboardingAction
data class EditHomeServer(val homeServerUrl: String) : OnboardingAction
data class UpdateUseCase(val useCase: FtueUseCase) : OnboardingAction data class UpdateUseCase(val useCase: FtueUseCase) : OnboardingAction
object ResetUseCase : OnboardingAction object ResetUseCase : OnboardingAction
data class UpdateSignMode(val signMode: SignMode) : OnboardingAction data class UpdateSignMode(val signMode: SignMode) : OnboardingAction

View file

@ -40,6 +40,7 @@ sealed class OnboardingViewEvents : VectorViewEvents {
object EditServerSelection : OnboardingViewEvents() object EditServerSelection : OnboardingViewEvents()
data class OnServerSelectionDone(val serverType: ServerType) : OnboardingViewEvents() data class OnServerSelectionDone(val serverType: ServerType) : OnboardingViewEvents()
object OnLoginFlowRetrieved : OnboardingViewEvents() object OnLoginFlowRetrieved : OnboardingViewEvents()
object OnHomeserverEdited : OnboardingViewEvents()
data class OnSignModeSelected(val signMode: SignMode) : OnboardingViewEvents() data class OnSignModeSelected(val signMode: SignMode) : OnboardingViewEvents()
object OnForgetPasswordClicked : OnboardingViewEvents() object OnForgetPasswordClicked : OnboardingViewEvents()
object OnResetPasswordSendThreePidDone : OnboardingViewEvents() object OnResetPasswordSendThreePidDone : OnboardingViewEvents()

View file

@ -140,7 +140,8 @@ class OnboardingViewModel @AssistedInject constructor(
is OnboardingAction.UpdateServerType -> handleUpdateServerType(action) is OnboardingAction.UpdateServerType -> handleUpdateServerType(action)
is OnboardingAction.UpdateSignMode -> handleUpdateSignMode(action) is OnboardingAction.UpdateSignMode -> handleUpdateSignMode(action)
is OnboardingAction.InitWith -> handleInitWith(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.LoginOrRegister -> handleLoginOrRegister(action).also { lastAction = action }
is OnboardingAction.Register -> handleRegisterWith(action).also { lastAction = action } is OnboardingAction.Register -> handleRegisterWith(action).also { lastAction = action }
is OnboardingAction.LoginWithToken -> handleLoginWithToken(action) is OnboardingAction.LoginWithToken -> handleLoginWithToken(action)
@ -576,8 +577,8 @@ class OnboardingViewModel @AssistedInject constructor(
} }
} }
private fun handleSelectHomeserver(action: OnboardingAction.SelectHomeServer) { private fun handleHomeserverChange(homeserverUrl: String) {
val homeServerConnectionConfig = homeServerConnectionConfigFactory.create(action.homeServerUrl) val homeServerConnectionConfig = homeServerConnectionConfigFactory.create(homeserverUrl)
if (homeServerConnectionConfig == null) { if (homeServerConnectionConfig == null) {
// This is invalid // This is invalid
_viewEvents.post(OnboardingViewEvents.Failure(Throwable("Unable to create a HomeServerConnectionConfig"))) _viewEvents.post(OnboardingViewEvents.Failure(Throwable("Unable to create a HomeServerConnectionConfig")))
@ -630,6 +631,9 @@ class OnboardingViewModel @AssistedInject constructor(
private fun onAuthenticationStartedSuccess() { private fun onAuthenticationStartedSuccess() {
withState { withState {
when (lastAction) {
is OnboardingAction.EditHomeServer -> _viewEvents.post(OnboardingViewEvents.OnHomeserverEdited)
is OnboardingAction.SelectHomeServer -> {
if (it.selectedHomeserver.preferredLoginMode.supportsSignModeScreen()) { if (it.selectedHomeserver.preferredLoginMode.supportsSignModeScreen()) {
when (it.onboardingFlow) { when (it.onboardingFlow) {
OnboardingFlow.SignIn -> handleUpdateSignMode(OnboardingAction.UpdateSignMode(SignMode.SignIn)) OnboardingFlow.SignIn -> handleUpdateSignMode(OnboardingAction.UpdateSignMode(SignMode.SignIn))
@ -643,6 +647,9 @@ class OnboardingViewModel @AssistedInject constructor(
_viewEvents.post(OnboardingViewEvents.OnLoginFlowRetrieved) _viewEvents.post(OnboardingViewEvents.OnLoginFlowRetrieved)
} }
} }
else -> _viewEvents.post(OnboardingViewEvents.OnLoginFlowRetrieved)
}
}
} }
fun getInitialHomeServerUrl(): String? { fun getInitialHomeServerUrl(): String? {

View file

@ -43,7 +43,7 @@ class StartAuthenticationFlowUseCase @Inject constructor(
private fun createSelectedHomeserverState(authFlow: LoginFlowResult, config: HomeServerConnectionConfig, preferredLoginMode: LoginMode): SelectedHomeserverState { private fun createSelectedHomeserverState(authFlow: LoginFlowResult, config: HomeServerConnectionConfig, preferredLoginMode: LoginMode): SelectedHomeserverState {
val matrixOrgUrl = stringProvider.getString(R.string.matrix_org_server_url).ensureTrailingSlash() val matrixOrgUrl = stringProvider.getString(R.string.matrix_org_server_url).ensureTrailingSlash()
return SelectedHomeserverState( 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) matrixOrgUrl -> stringProvider.getString(R.string.ftue_auth_create_account_matrix_dot_org_server_description)
else -> null else -> null
}, },

View file

@ -20,10 +20,13 @@ import android.os.Bundle
import android.view.LayoutInflater import android.view.LayoutInflater
import android.view.View import android.view.View
import android.view.ViewGroup import android.view.ViewGroup
import androidx.core.view.isEmpty
import im.vector.app.core.extensions.content import im.vector.app.core.extensions.content
import im.vector.app.core.extensions.editText import im.vector.app.core.extensions.editText
import im.vector.app.core.extensions.realignPercentagesToParent import im.vector.app.core.extensions.realignPercentagesToParent
import im.vector.app.core.extensions.toReducedUrl 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.databinding.FragmentFtueServerSelectionCombinedBinding
import im.vector.app.features.onboarding.OnboardingAction import im.vector.app.features.onboarding.OnboardingAction
import im.vector.app.features.onboarding.OnboardingViewEvents import im.vector.app.features.onboarding.OnboardingViewEvents
@ -45,7 +48,7 @@ class FtueAuthCombinedServerSelectionFragment @Inject constructor() : AbstractFt
} }
views.chooseServerSubmit.debouncedClicks { views.chooseServerSubmit.debouncedClicks {
viewModel.handle(OnboardingAction.SelectHomeServer(views.chooseServerInput.content())) viewModel.handle(OnboardingAction.EditHomeServer(views.chooseServerInput.content().ensureProtocol().ensureTrailingSlash()))
} }
} }
@ -54,9 +57,11 @@ class FtueAuthCombinedServerSelectionFragment @Inject constructor() : AbstractFt
} }
override fun updateWithState(state: OnboardingViewState) { override fun updateWithState(state: OnboardingViewState) {
if (views.chooseServerInput.isEmpty()) {
val userUrlInput = state.selectedHomeserver.sourceUrl?.toReducedUrlKeepingSchemaIfInsecure() val userUrlInput = state.selectedHomeserver.sourceUrl?.toReducedUrlKeepingSchemaIfInsecure()
views.chooseServerInput.editText().setText(userUrlInput) views.chooseServerInput.editText().setText(userUrlInput)
} }
}
private fun String.toReducedUrlKeepingSchemaIfInsecure() = toReducedUrl(keepSchema = this.startsWith("http://")) private fun String.toReducedUrlKeepingSchemaIfInsecure() = toReducedUrl(keepSchema = this.startsWith("http://"))
} }

View file

@ -240,6 +240,7 @@ class FtueAuthVariant(
option = commonOption option = commonOption
) )
} }
OnboardingViewEvents.OnHomeserverEdited -> activity.popBackstack()
} }
} }