reordering methods to match usage
- also ports the Sso listener to a functional interface
This commit is contained in:
parent
bc4566da4d
commit
12ae35f5ac
@ -30,7 +30,7 @@ import org.matrix.android.sdk.api.auth.data.SsoIdentityProvider
|
|||||||
class SocialLoginButtonsView @JvmOverloads constructor(context: Context, attrs: AttributeSet? = null, defStyle: Int = 0) :
|
class SocialLoginButtonsView @JvmOverloads constructor(context: Context, attrs: AttributeSet? = null, defStyle: Int = 0) :
|
||||||
LinearLayout(context, attrs, defStyle) {
|
LinearLayout(context, attrs, defStyle) {
|
||||||
|
|
||||||
interface InteractionListener {
|
fun interface InteractionListener {
|
||||||
fun onProviderSelected(id: String?)
|
fun onProviderSelected(id: String?)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -46,6 +46,7 @@ import im.vector.app.features.onboarding.OnboardingViewState
|
|||||||
import kotlinx.coroutines.flow.combine
|
import kotlinx.coroutines.flow.combine
|
||||||
import kotlinx.coroutines.flow.launchIn
|
import kotlinx.coroutines.flow.launchIn
|
||||||
import kotlinx.coroutines.flow.onEach
|
import kotlinx.coroutines.flow.onEach
|
||||||
|
import org.matrix.android.sdk.api.auth.data.SsoIdentityProvider
|
||||||
import org.matrix.android.sdk.api.failure.isInvalidPassword
|
import org.matrix.android.sdk.api.failure.isInvalidPassword
|
||||||
import org.matrix.android.sdk.api.failure.isInvalidUsername
|
import org.matrix.android.sdk.api.failure.isInvalidUsername
|
||||||
import org.matrix.android.sdk.api.failure.isLoginEmailUnknown
|
import org.matrix.android.sdk.api.failure.isLoginEmailUnknown
|
||||||
@ -76,20 +77,25 @@ class FtueAuthCombinedSignUpFragment @Inject constructor() : AbstractSSOFtueAuth
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun setupAutoFill() {
|
private fun setupSubmitButton() {
|
||||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
views.createAccountSubmit.setOnClickListener { submit() }
|
||||||
views.createAccountInput.setAutofillHints(HintConstants.AUTOFILL_HINT_NEW_USERNAME)
|
observeInputFields()
|
||||||
views.createAccountPasswordInput.setAutofillHints(HintConstants.AUTOFILL_HINT_NEW_PASSWORD)
|
.onEach {
|
||||||
}
|
views.createAccountPasswordInput.error = null
|
||||||
|
views.createAccountInput.error = null
|
||||||
|
views.createAccountSubmit.isEnabled = it
|
||||||
|
}
|
||||||
|
.launchIn(viewLifecycleOwner.lifecycleScope)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun setupSocialLoginButtons() {
|
private fun observeInputFields() = combine(
|
||||||
views.ssoButtons.mode = SocialLoginButtonsView.Mode.MODE_SIGN_UP
|
views.createAccountInput.hasContentFlow { it.trim() },
|
||||||
}
|
views.createAccountPasswordInput.hasContentFlow(),
|
||||||
|
transform = { isLoginNotEmpty, isPasswordNotEmpty -> isLoginNotEmpty && isPasswordNotEmpty }
|
||||||
|
)
|
||||||
|
|
||||||
private fun submit() {
|
private fun submit() {
|
||||||
withState(viewModel) { state ->
|
withState(viewModel) { state ->
|
||||||
|
|
||||||
cleanupUi()
|
cleanupUi()
|
||||||
|
|
||||||
val login = views.createAccountInput.content()
|
val login = views.createAccountInput.content()
|
||||||
@ -122,43 +128,6 @@ class FtueAuthCombinedSignUpFragment @Inject constructor() : AbstractSSOFtueAuth
|
|||||||
views.createAccountPasswordInput.error = null
|
views.createAccountPasswordInput.error = null
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun setupUi(state: OnboardingViewState) {
|
|
||||||
if (state.loginMode is LoginMode.SsoAndPassword) {
|
|
||||||
views.ssoGroup.isVisible = state.loginMode.ssoIdentityProviders?.isNotEmpty() == true
|
|
||||||
views.ssoButtons.ssoIdentityProviders = state.loginMode.ssoIdentityProviders?.sorted()
|
|
||||||
views.ssoButtons.listener = object : SocialLoginButtonsView.InteractionListener {
|
|
||||||
override fun onProviderSelected(id: String?) {
|
|
||||||
viewModel.getSsoUrl(
|
|
||||||
redirectUrl = SSORedirectRouterActivity.VECTOR_REDIRECT_URL,
|
|
||||||
deviceId = state.deviceId,
|
|
||||||
providerId = id
|
|
||||||
)
|
|
||||||
?.let { openInCustomTab(it) }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
views.ssoGroup.isVisible = false
|
|
||||||
views.ssoButtons.ssoIdentityProviders = null
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun setupSubmitButton() {
|
|
||||||
views.createAccountSubmit.setOnClickListener { submit() }
|
|
||||||
observeInputFields()
|
|
||||||
.onEach {
|
|
||||||
views.createAccountPasswordInput.error = null
|
|
||||||
views.createAccountInput.error = null
|
|
||||||
views.createAccountSubmit.isEnabled = it
|
|
||||||
}
|
|
||||||
.launchIn(viewLifecycleOwner.lifecycleScope)
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun observeInputFields() = combine(
|
|
||||||
views.createAccountInput.hasContentFlow { it.trim() },
|
|
||||||
views.createAccountPasswordInput.hasContentFlow(),
|
|
||||||
transform = { isLoginNotEmpty, isPasswordNotEmpty -> isLoginNotEmpty && isPasswordNotEmpty }
|
|
||||||
)
|
|
||||||
|
|
||||||
override fun resetViewModel() {
|
override fun resetViewModel() {
|
||||||
viewModel.handle(OnboardingAction.ResetAuthenticationAttempt)
|
viewModel.handle(OnboardingAction.ResetAuthenticationAttempt)
|
||||||
}
|
}
|
||||||
@ -195,13 +164,44 @@ class FtueAuthCombinedSignUpFragment @Inject constructor() : AbstractSSOFtueAuth
|
|||||||
override fun updateWithState(state: OnboardingViewState) {
|
override fun updateWithState(state: OnboardingViewState) {
|
||||||
setupUi(state)
|
setupUi(state)
|
||||||
setupAutoFill()
|
setupAutoFill()
|
||||||
setupSocialLoginButtons()
|
|
||||||
|
|
||||||
if (state.isLoading) {
|
if (state.isLoading) {
|
||||||
// Ensure password is hidden
|
// Ensure password is hidden
|
||||||
views.createAccountPasswordInput.editText().hidePassword()
|
views.createAccountPasswordInput.editText().hidePassword()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun setupUi(state: OnboardingViewState) {
|
||||||
|
when (state.loginMode) {
|
||||||
|
is LoginMode.SsoAndPassword -> renderSsoProviders(state.deviceId, state.loginMode.ssoIdentityProviders)
|
||||||
|
else -> hideSsoProviders()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun renderSsoProviders(deviceId: String?, ssoProviders: List<SsoIdentityProvider>?) {
|
||||||
|
views.ssoButtons.mode = SocialLoginButtonsView.Mode.MODE_SIGN_UP
|
||||||
|
views.ssoButtons.ssoIdentityProviders = ssoProviders?.sorted()
|
||||||
|
views.ssoButtons.listener = SocialLoginButtonsView.InteractionListener { id ->
|
||||||
|
views.ssoGroup.isVisible = ssoProviders?.isNotEmpty() == true
|
||||||
|
viewModel.getSsoUrl(
|
||||||
|
redirectUrl = SSORedirectRouterActivity.VECTOR_REDIRECT_URL,
|
||||||
|
deviceId = deviceId,
|
||||||
|
providerId = id
|
||||||
|
)?.let { openInCustomTab(it) }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun hideSsoProviders() {
|
||||||
|
views.ssoGroup.isVisible = false
|
||||||
|
views.ssoButtons.ssoIdentityProviders = null
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun setupAutoFill() {
|
||||||
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
||||||
|
views.createAccountInput.setAutofillHints(HintConstants.AUTOFILL_HINT_NEW_USERNAME)
|
||||||
|
views.createAccountPasswordInput.setAutofillHints(HintConstants.AUTOFILL_HINT_NEW_PASSWORD)
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun OnboardingViewState.isNumericOnlyUserIdForbidden() = serverType == ServerType.MatrixOrg
|
private fun OnboardingViewState.isNumericOnlyUserIdForbidden() = serverType == ServerType.MatrixOrg
|
||||||
|
Loading…
x
Reference in New Issue
Block a user