Open account creation screen (with error) when crating an account on default server which only support MAS)

This commit is contained in:
Benoit Marty 2025-01-10 12:12:58 +01:00
parent d2c77a36ec
commit b9b403d075
3 changed files with 104 additions and 10 deletions

View File

@ -764,9 +764,9 @@ class OnboardingViewModel @AssistedInject constructor(
OnboardingFlow.SignUp -> {
updateSignMode(SignMode.SignUp)
if (authResult.selectedHomeserver.hasOidcCompatibilityFlow && Config.sunsetConfig is SunsetConfig.Enabled) {
// An error is displayed now
// Navigate to the screen to create an account, it will show the error
setState { copy(isLoading = false) }
_viewEvents.post(OnboardingViewEvents.Failure(MasSupportRequiredException()))
_viewEvents.post(OnboardingViewEvents.OpenCombinedRegister)
} else {
internalRegisterAction(RegisterAction.StartRegistration)
}
@ -940,7 +940,10 @@ private fun LoginMode.supportsSignModeScreen(): Boolean {
return when (this) {
LoginMode.Password,
is LoginMode.SsoAndPassword -> true
is LoginMode.Sso,
is LoginMode.Sso -> {
// In this case, an error will be displayed in the next screen
hasOidcCompatibilityFlow
}
LoginMode.Unknown,
LoginMode.Unsupported -> false
}

View File

@ -12,6 +12,7 @@ import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.TextView
import androidx.autofill.HintConstants
import androidx.core.text.isDigitsOnly
import androidx.core.view.isVisible
@ -19,6 +20,9 @@ import androidx.lifecycle.lifecycleScope
import com.airbnb.mvrx.withState
import com.google.android.material.dialog.MaterialAlertDialogBuilder
import dagger.hilt.android.AndroidEntryPoint
import im.vector.app.R
import im.vector.app.config.Config
import im.vector.app.config.SunsetConfig
import im.vector.app.core.extensions.clearErrorOnChange
import im.vector.app.core.extensions.content
import im.vector.app.core.extensions.editText
@ -31,6 +35,9 @@ import im.vector.app.core.extensions.realignPercentagesToParent
import im.vector.app.core.extensions.setOnFocusLostListener
import im.vector.app.core.extensions.setOnImeDoneListener
import im.vector.app.core.extensions.toReducedUrl
import im.vector.app.core.resources.BuildMeta
import im.vector.app.core.utils.openApplicationStore
import im.vector.app.core.utils.openUrlInChromeCustomTab
import im.vector.app.databinding.FragmentFtueCombinedRegisterBinding
import im.vector.app.features.login.LoginMode
import im.vector.app.features.login.SSORedirectRouterActivity
@ -52,12 +59,14 @@ import org.matrix.android.sdk.api.failure.isRegistrationDisabled
import org.matrix.android.sdk.api.failure.isUsernameInUse
import org.matrix.android.sdk.api.failure.isWeakPassword
import reactivecircus.flowbinding.android.widget.textChanges
import javax.inject.Inject
private const val MINIMUM_PASSWORD_LENGTH = 8
@AndroidEntryPoint
class FtueAuthCombinedRegisterFragment :
AbstractSSOFtueAuthFragment<FragmentFtueCombinedRegisterBinding>() {
@Inject lateinit var buildMeta: BuildMeta
override fun getBinding(inflater: LayoutInflater, container: ViewGroup?): FragmentFtueCombinedRegisterBinding {
return FragmentFtueCombinedRegisterBinding.inflate(inflater, container, false)
@ -181,7 +190,8 @@ class FtueAuthCombinedRegisterFragment :
}
private fun setupUi(state: OnboardingViewState) {
views.selectedServerName.text = state.selectedHomeserver.userFacingUrl.toReducedUrl()
val serverName = state.selectedHomeserver.userFacingUrl.toReducedUrl()
views.selectedServerName.text = serverName
if (state.isLoading) {
// Ensure password is hidden
@ -201,6 +211,47 @@ class FtueAuthCombinedRegisterFragment :
is LoginMode.SsoAndPassword -> renderSsoProviders(state.deviceId, state.selectedHomeserver.preferredLoginMode)
else -> hideSsoProviders()
}
(Config.sunsetConfig as? SunsetConfig.Enabled)?.let { config ->
val isMasSupportRequired = state.selectedHomeserver.hasOidcCompatibilityFlow
views.serverSelectionSpacing.isVisible = !isMasSupportRequired
views.serverSelectionDivider.isVisible = !isMasSupportRequired
views.chooseServerCardErrorMas.isVisible = isMasSupportRequired
views.chooseServerCardDownloadReplacementApp.isVisible = isMasSupportRequired
if (isMasSupportRequired) {
views.chooseServerCardErrorMas.findViewById<TextView>(R.id.view_card_error_title).text =
getString(CommonStrings.error_mas_not_supported_title, serverName)
views.chooseServerCardErrorMas.findViewById<TextView>(R.id.view_card_error_subtitle).text =
getString(
CommonStrings.error_mas_not_supported_subtitle,
config.replacementApplicationName,
serverName,
)
views.chooseServerCardDownloadReplacementApp.findViewById<TextView>(R.id.view_download_replacement_app_title).text =
getString(CommonStrings.view_download_replacement_app_title, config.replacementApplicationName)
views.chooseServerCardDownloadReplacementApp.debouncedClicks {
openApplicationStore(
activity = requireActivity(),
buildMeta = buildMeta,
appId = config.replacementApplicationId,
)
}
views.chooseServerCardDownloadReplacementApp.findViewById<View>(R.id.view_download_replacement_app_learn_more)?.debouncedClicks {
openUrlInChromeCustomTab(
context = requireContext(),
session = null,
url = config.learnMoreLink,
)
}
// Disable form
views.createAccountInput.isEnabled = false
views.createAccountPasswordInput.isEnabled = false
views.createAccountSubmit.isEnabled = false
}
}
}
private fun renderSsoProviders(deviceId: String?, loginMode: LoginMode) {

View File

@ -34,8 +34,8 @@
android:layout_height="52dp"
app:layout_constraintBottom_toTopOf="@id/createAccountHeaderIcon"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_chainStyle="packed"
app:layout_constraintVertical_bias="0" />
app:layout_constraintVertical_bias="0"
app:layout_constraintVertical_chainStyle="packed" />
<ImageView
android:id="@+id/createAccountHeaderIcon"
@ -120,11 +120,12 @@
android:id="@+id/serverSelectionSpacing"
android:layout_width="match_parent"
android:layout_height="0dp"
app:layout_constraintBottom_toTopOf="@id/createAccountInput"
app:layout_constraintBottom_toTopOf="@id/chooseServerCardErrorMas"
app:layout_constraintHeight_percent="0.05"
app:layout_constraintTop_toBottomOf="@id/selectedServerName" />
<View
android:id="@+id/serverSelectionDivider"
android:layout_width="0dp"
android:layout_height="1dp"
android:background="?vctr_content_quaternary"
@ -133,6 +134,45 @@
app:layout_constraintStart_toStartOf="@id/createAccountGutterStart"
app:layout_constraintTop_toTopOf="@id/serverSelectionSpacing" />
<FrameLayout
android:id="@+id/chooseServerCardErrorMas"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:visibility="gone"
app:layout_constraintBottom_toTopOf="@id/chooseServerCardDownloadReplacementApp"
app:layout_constraintEnd_toEndOf="@id/createAccountGutterEnd"
app:layout_constraintStart_toStartOf="@id/createAccountGutterStart"
app:layout_constraintTop_toBottomOf="@+id/serverSelectionSpacing"
tools:visibility="visible">
<include
layout="@layout/view_error_registration_with_mas"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</FrameLayout>
<FrameLayout
android:id="@+id/chooseServerCardDownloadReplacementApp"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:layout_marginBottom="16dp"
android:visibility="gone"
app:layout_constraintBottom_toTopOf="@+id/createAccountInput"
app:layout_constraintEnd_toEndOf="@id/createAccountGutterEnd"
app:layout_constraintStart_toStartOf="@id/createAccountGutterStart"
app:layout_constraintTop_toBottomOf="@+id/chooseServerCardErrorMas"
tools:visibility="visible">
<include
layout="@layout/view_download_replacement_app"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</FrameLayout>
<com.google.android.material.textfield.TextInputLayout
android:id="@+id/createAccountInput"
style="@style/Widget.Vector.TextInputLayout.Username"
@ -142,16 +182,16 @@
app:layout_constraintBottom_toTopOf="@id/createAccountEntryFooter"
app:layout_constraintEnd_toEndOf="@id/createAccountGutterEnd"
app:layout_constraintStart_toStartOf="@id/createAccountGutterStart"
app:layout_constraintTop_toBottomOf="@id/serverSelectionSpacing">
app:layout_constraintTop_toBottomOf="@id/chooseServerCardDownloadReplacementApp">
<com.google.android.material.textfield.TextInputEditText
android:id="@+id/createAccountEditText"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:imeOptions="actionNext"
android:nextFocusForward="@id/createAccountPasswordInput"
android:inputType="textNoSuggestions"
android:maxLines="1" />
android:maxLines="1"
android:nextFocusForward="@id/createAccountPasswordInput" />
</com.google.android.material.textfield.TextInputLayout>