Skip to content

Commit

Permalink
hiding username/password fields when the homeserver doesn't support t…
Browse files Browse the repository at this point in the history
…hem and showing SSO options when available
  • Loading branch information
ouchadam committed May 16, 2022
1 parent 474ea13 commit 9a28949
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -112,13 +112,24 @@ class FtueAuthCombinedLoginFragment @Inject constructor(

private fun setupUi(state: OnboardingViewState) {
when (state.selectedHomeserver.preferredLoginMode) {
is LoginMode.SsoAndPassword -> renderSsoProviders(state.deviceId, state.selectedHomeserver.preferredLoginMode.ssoIdentityProviders)
else -> hideSsoProviders()
is LoginMode.SsoAndPassword -> {
showUsernamePassword()
renderSsoProviders(state.deviceId, state.selectedHomeserver.preferredLoginMode.ssoIdentityProviders)
}
is LoginMode.Sso -> {
hideUsernamePassword()
renderSsoProviders(state.deviceId, state.selectedHomeserver.preferredLoginMode.ssoIdentityProviders)
}
else -> {
showUsernamePassword()
hideSsoProviders()
}
}
}

private fun renderSsoProviders(deviceId: String?, ssoProviders: List<SsoIdentityProvider>?) {
views.ssoGroup.isVisible = ssoProviders?.isNotEmpty() == true
views.ssoButtonsHeader.isVisible = views.ssoGroup.isVisible && views.loginEntryGroup.isVisible
views.ssoButtons.render(ssoProviders, SocialLoginButtonsView.Mode.MODE_CONTINUE) { id ->
viewModel.getSsoUrl(
redirectUrl = SSORedirectRouterActivity.VECTOR_REDIRECT_URL,
Expand All @@ -133,6 +144,14 @@ class FtueAuthCombinedLoginFragment @Inject constructor(
views.ssoButtons.ssoIdentityProviders = null
}

private fun hideUsernamePassword() {
views.loginEntryGroup.isVisible = false
}

private fun showUsernamePassword() {
views.loginEntryGroup.isVisible = true
}

private fun setupAutoFill() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
views.loginInput.setAutofillHints(HintConstants.AUTOFILL_HINT_NEW_USERNAME)
Expand Down
7 changes: 7 additions & 0 deletions vector/src/main/res/layout/fragment_ftue_combined_login.xml
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,13 @@
app:layout_constraintStart_toStartOf="@id/loginGutterStart"
app:layout_constraintTop_toTopOf="@id/serverSelectionSpacing" />

<androidx.constraintlayout.widget.Group
android:id="@+id/loginEntryGroup"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:visibility="visible"
app:constraint_referenced_ids="loginInput,loginPasswordInput,entrySpacing,actionSpacing,loginSubmit" />

<com.google.android.material.textfield.TextInputLayout
android:id="@+id/loginInput"
style="@style/Widget.Vector.TextInputLayout.Username"
Expand Down

0 comments on commit 9a28949

Please sign in to comment.