diff --git a/vector/src/main/java/im/vector/riotx/features/login/LoginActivity.kt b/vector/src/main/java/im/vector/riotx/features/login/LoginActivity.kt index 86be00702c..1eebf532e7 100644 --- a/vector/src/main/java/im/vector/riotx/features/login/LoginActivity.kt +++ b/vector/src/main/java/im/vector/riotx/features/login/LoginActivity.kt @@ -235,6 +235,7 @@ open class LoginActivity : VectorBaseActivity(), ToolbarConfigurable { ServerType.Other -> addFragmentToBackstack(R.id.loginFragmentContainer, LoginServerUrlFormFragment::class.java, option = commonOption) + ServerType.Unknown -> Unit /* Should not happen */ } } diff --git a/vector/src/main/java/im/vector/riotx/features/login/LoginFragment.kt b/vector/src/main/java/im/vector/riotx/features/login/LoginFragment.kt index 28c2299faa..ef8281fa89 100644 --- a/vector/src/main/java/im/vector/riotx/features/login/LoginFragment.kt +++ b/vector/src/main/java/im/vector/riotx/features/login/LoginFragment.kt @@ -166,6 +166,7 @@ class LoginFragment @Inject constructor() : AbstractLoginFragment() { loginTitle.text = getString(resId, state.homeServerUrl.toReducedUrl()) loginNotice.text = getString(R.string.login_server_other_text) } + ServerType.Unknown -> Unit /* Should not happen */ } loginPasswordNotice.isVisible = false } diff --git a/vector/src/main/java/im/vector/riotx/features/login/LoginServerSelectionFragment.kt b/vector/src/main/java/im/vector/riotx/features/login/LoginServerSelectionFragment.kt index 79c5c7d024..3a1bba7f11 100644 --- a/vector/src/main/java/im/vector/riotx/features/login/LoginServerSelectionFragment.kt +++ b/vector/src/main/java/im/vector/riotx/features/login/LoginServerSelectionFragment.kt @@ -19,7 +19,6 @@ package im.vector.riotx.features.login import android.os.Bundle import android.view.View import butterknife.OnClick -import com.airbnb.mvrx.withState import im.vector.riotx.R import im.vector.riotx.core.utils.openUrlInChromeCustomTab import kotlinx.android.synthetic.main.fragment_login_server_selection.* @@ -40,11 +39,7 @@ class LoginServerSelectionFragment @Inject constructor() : AbstractLoginFragment } private fun updateSelectedChoice(state: LoginViewState) { - state.serverType.let { - loginServerChoiceMatrixOrg.isChecked = it == ServerType.MatrixOrg - loginServerChoiceModular.isChecked = it == ServerType.Modular - loginServerChoiceOther.isChecked = it == ServerType.Other - } + loginServerChoiceMatrixOrg.isChecked = state.serverType == ServerType.MatrixOrg } private fun initTextViews() { @@ -61,42 +56,17 @@ class LoginServerSelectionFragment @Inject constructor() : AbstractLoginFragment @OnClick(R.id.loginServerChoiceMatrixOrg) fun selectMatrixOrg() { - if (loginServerChoiceMatrixOrg.isChecked) { - // Consider this is a submit - submit() - } else { - loginViewModel.handle(LoginAction.UpdateServerType(ServerType.MatrixOrg)) - } + loginViewModel.handle(LoginAction.UpdateServerType(ServerType.MatrixOrg)) } @OnClick(R.id.loginServerChoiceModular) fun selectModular() { - if (loginServerChoiceModular.isChecked) { - // Consider this is a submit - submit() - } else { - loginViewModel.handle(LoginAction.UpdateServerType(ServerType.Modular)) - } + loginViewModel.handle(LoginAction.UpdateServerType(ServerType.Modular)) } @OnClick(R.id.loginServerChoiceOther) fun selectOther() { - if (loginServerChoiceOther.isChecked) { - // Consider this is a submit - submit() - } else { - loginViewModel.handle(LoginAction.UpdateServerType(ServerType.Other)) - } - } - - @OnClick(R.id.loginServerSubmit) - fun submit() = withState(loginViewModel) { state -> - if (state.serverType == ServerType.MatrixOrg) { - // Request login flow here - loginViewModel.handle(LoginAction.UpdateHomeServer(getString(R.string.matrix_org_server_url))) - } else { - loginViewModel.handle(LoginAction.PostViewEvent(LoginViewEvents.OnServerSelectionDone)) - } + loginViewModel.handle(LoginAction.UpdateServerType(ServerType.Other)) } @OnClick(R.id.loginServerIKnowMyIdSubmit) diff --git a/vector/src/main/java/im/vector/riotx/features/login/LoginSignUpSignInSelectionFragment.kt b/vector/src/main/java/im/vector/riotx/features/login/LoginSignUpSignInSelectionFragment.kt index 427ad99b41..6ac5993f30 100644 --- a/vector/src/main/java/im/vector/riotx/features/login/LoginSignUpSignInSelectionFragment.kt +++ b/vector/src/main/java/im/vector/riotx/features/login/LoginSignUpSignInSelectionFragment.kt @@ -49,6 +49,7 @@ open class LoginSignUpSignInSelectionFragment @Inject constructor() : AbstractLo loginSignupSigninTitle.text = getString(R.string.login_server_other_title) loginSignupSigninText.text = getString(R.string.login_connect_to, state.homeServerUrl.toReducedUrl()) } + ServerType.Unknown -> Unit /* Should not happen */ } } diff --git a/vector/src/main/java/im/vector/riotx/features/login/LoginViewModel.kt b/vector/src/main/java/im/vector/riotx/features/login/LoginViewModel.kt index fc970297d1..47736ec047 100644 --- a/vector/src/main/java/im/vector/riotx/features/login/LoginViewModel.kt +++ b/vector/src/main/java/im/vector/riotx/features/login/LoginViewModel.kt @@ -321,7 +321,7 @@ class LoginViewModel @AssistedInject constructor( LoginAction.ResetHomeServerType -> { setState { copy( - serverType = ServerType.MatrixOrg + serverType = ServerType.Unknown ) } } @@ -390,6 +390,15 @@ class LoginViewModel @AssistedInject constructor( serverType = action.serverType ) } + + when (action.serverType) { + ServerType.Unknown -> Unit /* Should not happen */ + ServerType.MatrixOrg -> + // Request login flow here + handle(LoginAction.UpdateHomeServer(stringProvider.getString(R.string.matrix_org_server_url))) + ServerType.Modular, + ServerType.Other -> _viewEvents.post(LoginViewEvents.OnServerSelectionDone) + }.exhaustive } private fun handleInitWith(action: LoginAction.InitWith) { @@ -682,7 +691,9 @@ class LoginViewModel @AssistedInject constructor( _viewEvents.post(LoginViewEvents.Failure(failure)) setState { copy( - asyncHomeServerLoginFlowRequest = Uninitialized + asyncHomeServerLoginFlowRequest = Uninitialized, + // If we were trying to retrieve matrix.org login flow, also reset the serverType + serverType = if (serverType == ServerType.MatrixOrg) ServerType.Unknown else serverType ) } } diff --git a/vector/src/main/java/im/vector/riotx/features/login/LoginViewState.kt b/vector/src/main/java/im/vector/riotx/features/login/LoginViewState.kt index 944d1f7d82..655966ce25 100644 --- a/vector/src/main/java/im/vector/riotx/features/login/LoginViewState.kt +++ b/vector/src/main/java/im/vector/riotx/features/login/LoginViewState.kt @@ -35,7 +35,7 @@ data class LoginViewState( // User choices @PersistState - val serverType: ServerType = ServerType.MatrixOrg, + val serverType: ServerType = ServerType.Unknown, @PersistState val signMode: SignMode = SignMode.Unknown, @PersistState diff --git a/vector/src/main/java/im/vector/riotx/features/login/ServerType.kt b/vector/src/main/java/im/vector/riotx/features/login/ServerType.kt index 4c7007c137..50dfee19f0 100644 --- a/vector/src/main/java/im/vector/riotx/features/login/ServerType.kt +++ b/vector/src/main/java/im/vector/riotx/features/login/ServerType.kt @@ -17,6 +17,7 @@ package im.vector.riotx.features.login enum class ServerType { + Unknown, MatrixOrg, Modular, Other diff --git a/vector/src/main/res/drawable/bg_login_server_selector.xml b/vector/src/main/res/drawable/bg_login_server_selector.xml index 57be1e5d54..3fcc4e006a 100644 --- a/vector/src/main/res/drawable/bg_login_server_selector.xml +++ b/vector/src/main/res/drawable/bg_login_server_selector.xml @@ -2,6 +2,7 @@ + diff --git a/vector/src/main/res/layout/fragment_login_server_selection.xml b/vector/src/main/res/layout/fragment_login_server_selection.xml index 16465486a2..de7bf65cbb 100644 --- a/vector/src/main/res/layout/fragment_login_server_selection.xml +++ b/vector/src/main/res/layout/fragment_login_server_selection.xml @@ -43,6 +43,7 @@ app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toBottomOf="@+id/loginServerTitle" /> + - - + - - - - + + app:layout_constraintTop_toBottomOf="@+id/loginServerChoiceOther" />