Login screens: Perform dummy action when user does not want to enter an email -> account created!

This commit is contained in:
Benoit Marty 2019-11-19 14:51:51 +01:00
parent 3f80076fb1
commit 9aa270c7ad
5 changed files with 72 additions and 4 deletions

View file

@ -29,5 +29,7 @@ interface RegistrationWizard {
fun acceptTerms(callback: MatrixCallback<RegistrationResult>): Cancelable
fun dummy(callback: MatrixCallback<RegistrationResult>): Cancelable
// TODO Add other method here
}

View file

@ -90,6 +90,21 @@ internal class DefaultRegistrationWizard(private val homeServerConnectionConfig:
), callback)
}
override fun dummy(callback: MatrixCallback<RegistrationResult>): Cancelable {
val safeSession = currentSession ?: run {
callback.onFailure(IllegalStateException("developer error, call createAccount() method first"))
return NoOpCancellable
}
return performRegistrationRequest(
RegistrationParams(
auth = AuthParams(
type = LoginFlowTypes.DUMMY,
session = safeSession
)
), callback)
}
private fun performRegistrationRequest(registrationParams: RegistrationParams, callback: MatrixCallback<RegistrationResult>): Cancelable {
val job = GlobalScope.launch(coroutineDispatchers.main) {
val result = runCatching {

View file

@ -37,6 +37,7 @@ sealed class LoginAction : VectorViewModelAction {
data class ConfirmMsisdn(val code: String) : RegisterAction()
data class CaptchaDone(val captchaResponse: String) : RegisterAction()
object AcceptTerms : RegisterAction()
object RegisterDummy : RegisterAction()
// Reset actions
open class ResetAction : LoginAction()

View file

@ -94,7 +94,24 @@ class LoginGenericTextInputFormFragment @Inject constructor() : AbstractLoginFra
@OnClick(R.id.loginGenericTextInputFormSubmit)
fun onSubmitClicked() {
// TODO
val text = loginGenericTextInputFormTextInput.text.toString()
if (text.isEmpty()) {
// Perform dummy action
loginViewModel.handle(LoginAction.RegisterDummy)
} else {
when (params.mode) {
TextInputFormFragmentMode.SetEmail -> {
// TODO
}
TextInputFormFragmentMode.SetMsisdn -> {
// TODO
}
TextInputFormFragmentMode.ConfirmMsisdn -> {
// TODO
}
}
}
}
private fun setupSubmitButton() {

View file

@ -101,9 +101,10 @@ class LoginViewModel @AssistedInject constructor(@Assisted initialState: LoginVi
private fun handleRegisterAction(action: LoginAction.RegisterAction) {
when (action) {
is LoginAction.RegisterWith -> handleRegisterWith(action)
is LoginAction.CaptchaDone -> handleCaptchaDone(action)
is LoginAction.AcceptTerms -> handleAcceptTerms()
is LoginAction.RegisterWith -> handleRegisterWith(action)
is LoginAction.CaptchaDone -> handleCaptchaDone(action)
is LoginAction.AcceptTerms -> handleAcceptTerms()
is LoginAction.RegisterDummy -> handleRegisterDummy()
// TODO Add other actions here
}
}
@ -140,6 +141,38 @@ class LoginViewModel @AssistedInject constructor(@Assisted initialState: LoginVi
})
}
private fun handleRegisterDummy() {
setState {
copy(
asyncRegistration = Loading()
)
}
currentTask = registrationWizard?.dummy(object : MatrixCallback<RegistrationResult> {
override fun onSuccess(data: RegistrationResult) {
setState {
copy(
asyncRegistration = Success(data)
)
}
when (data) {
is RegistrationResult.Success -> onSessionCreated(data.session)
is RegistrationResult.FlowResponse -> onFlowResponse(data.flowResult)
}
}
override fun onFailure(failure: Throwable) {
// TODO Handled JobCancellationException
setState {
copy(
asyncRegistration = Fail(failure)
)
}
}
})
}
private fun handleRegisterWith(action: LoginAction.RegisterWith) {
setState {
copy(