Simplify the server selection screen: remove the "Continue" button

This commit is contained in:
Benoit Marty 2020-07-06 10:49:03 +02:00
parent b853397c0a
commit 2a68c8d08b
9 changed files with 29 additions and 55 deletions

View File

@ -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 */
}
}

View File

@ -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
}

View File

@ -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)

View File

@ -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 */
}
}

View File

@ -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
)
}
}

View File

@ -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

View File

@ -17,6 +17,7 @@
package im.vector.riotx.features.login
enum class ServerType {
Unknown,
MatrixOrg,
Modular,
Other

View File

@ -2,6 +2,7 @@
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@drawable/bg_login_server_checked" android:state_checked="true" />
<item android:drawable="@drawable/bg_login_server_checked" android:state_pressed="true" />
<item android:drawable="@drawable/bg_login_server" />

View File

@ -43,6 +43,7 @@
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/loginServerTitle" />
<!-- Use a CheckableConstraintLayout to keep the pressed state when retrieving login flow -->
<im.vector.riotx.core.platform.CheckableConstraintLayout
android:id="@+id/loginServerChoiceMatrixOrg"
android:layout_width="match_parent"
@ -84,7 +85,7 @@
</im.vector.riotx.core.platform.CheckableConstraintLayout>
<im.vector.riotx.core.platform.CheckableConstraintLayout
<androidx.constraintlayout.widget.ConstraintLayout
android:id="@+id/loginServerChoiceModular"
android:layout_width="match_parent"
android:layout_height="wrap_content"
@ -135,9 +136,9 @@
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="@+id/loginServerChoiceModularText" />
</im.vector.riotx.core.platform.CheckableConstraintLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
<im.vector.riotx.core.platform.CheckableConstraintLayout
<androidx.constraintlayout.widget.ConstraintLayout
android:id="@+id/loginServerChoiceOther"
android:layout_width="match_parent"
android:layout_height="wrap_content"
@ -178,20 +179,7 @@
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/loginServerChoiceOtherTitle" />
</im.vector.riotx.core.platform.CheckableConstraintLayout>
<com.google.android.material.button.MaterialButton
android:id="@+id/loginServerSubmit"
style="@style/Style.Vector.Login.Button"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="24dp"
android:text="@string/login_continue"
android:transitionName="loginSubmitTransition"
app:layout_constraintBottom_toTopOf="@+id/loginServerIKnowMyIdSubmit"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/loginServerChoiceOther" />
</androidx.constraintlayout.widget.ConstraintLayout>
<com.google.android.material.button.MaterialButton
android:id="@+id/loginServerIKnowMyIdSubmit"
@ -204,7 +192,7 @@
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/loginServerSubmit" />
app:layout_constraintTop_toBottomOf="@+id/loginServerChoiceOther" />
</androidx.constraintlayout.widget.ConstraintLayout>