From 08ea3d049e8ca723d8597a8cc129e05a427cdd03 Mon Sep 17 00:00:00 2001 From: Benoit Marty Date: Mon, 18 Nov 2019 15:03:07 +0100 Subject: [PATCH] Login screens: Simple Input form (UI) --- .../LoginGenericTextInputFormFragment.kt | 140 ++++++++++++++++++ ...fragment_login_generic_text_input_form.xml | 98 ++++++++++++ vector/src/main/res/values/strings_riotX.xml | 19 +++ 3 files changed, 257 insertions(+) create mode 100644 vector/src/main/java/im/vector/riotx/features/login/LoginGenericTextInputFormFragment.kt create mode 100644 vector/src/main/res/layout/fragment_login_generic_text_input_form.xml diff --git a/vector/src/main/java/im/vector/riotx/features/login/LoginGenericTextInputFormFragment.kt b/vector/src/main/java/im/vector/riotx/features/login/LoginGenericTextInputFormFragment.kt new file mode 100644 index 0000000000..98c30c685f --- /dev/null +++ b/vector/src/main/java/im/vector/riotx/features/login/LoginGenericTextInputFormFragment.kt @@ -0,0 +1,140 @@ +/* + * Copyright 2019 New Vector Ltd + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package im.vector.riotx.features.login + +import android.os.Bundle +import android.os.Parcelable +import android.text.InputType +import android.view.View +import androidx.core.view.isVisible +import butterknife.OnClick +import com.airbnb.mvrx.args +import com.jakewharton.rxbinding3.widget.textChanges +import im.vector.riotx.R +import kotlinx.android.parcel.Parcelize +import kotlinx.android.synthetic.main.fragment_login_generic_text_input_form.* +import javax.inject.Inject + +enum class TextInputFormFragmentMode { + SetEmailMandatory, + SetEmailOptional, + SetMsisdnMandatory, + SetMsisdnOptional, + ConfirmMsisdn +} + +@Parcelize +data class LoginGenericTextInputFormFragmentArgument( + val mode: TextInputFormFragmentMode +) : Parcelable + +/** + * In this screen, the user is asked for a text input + */ +class LoginGenericTextInputFormFragment @Inject constructor() : AbstractLoginFragment() { + + private val params: LoginGenericTextInputFormFragmentArgument by args() + + override fun getLayoutResId() = R.layout.fragment_login_generic_text_input_form + + override fun onViewCreated(view: View, savedInstanceState: Bundle?) { + super.onViewCreated(view, savedInstanceState) + + setupUi() + setupSubmitButton() + } + + private fun setupUi() { + when (params.mode) { + TextInputFormFragmentMode.SetEmailMandatory -> { + loginGenericTextInputFormTitle.text = getString(R.string.login_set_email_title) + loginGenericTextInputFormNotice.text = getString(R.string.login_set_email_notice) + loginGenericTextInputFormTil.hint = getString(R.string.login_set_email_mandatory_hint) + loginGenericTextInputFormTextInput.inputType = InputType.TYPE_CLASS_TEXT or InputType.TYPE_TEXT_VARIATION_EMAIL_ADDRESS + loginGenericTextInputFormOtherButton.isVisible = false + loginGenericTextInputFormSubmit.text = getString(R.string.login_set_email_submit) + } + TextInputFormFragmentMode.SetEmailOptional -> { + loginGenericTextInputFormTitle.text = getString(R.string.login_set_email_title) + loginGenericTextInputFormNotice.text = getString(R.string.login_set_email_notice) + loginGenericTextInputFormTil.hint = getString(R.string.login_set_email_optional_hint) + loginGenericTextInputFormTextInput.inputType = InputType.TYPE_CLASS_TEXT or InputType.TYPE_TEXT_VARIATION_EMAIL_ADDRESS + loginGenericTextInputFormOtherButton.isVisible = false + loginGenericTextInputFormSubmit.text = getString(R.string.login_set_email_submit) + } + TextInputFormFragmentMode.SetMsisdnMandatory -> { + loginGenericTextInputFormTitle.text = getString(R.string.login_set_msisdn_title) + loginGenericTextInputFormNotice.text = getString(R.string.login_set_msisdn_notice) + loginGenericTextInputFormTil.hint = getString(R.string.login_set_msisdn_mandatory_hint) + loginGenericTextInputFormTextInput.inputType = InputType.TYPE_CLASS_PHONE + loginGenericTextInputFormOtherButton.isVisible = false + loginGenericTextInputFormSubmit.text = getString(R.string.login_set_msisdn_submit) + } + TextInputFormFragmentMode.SetMsisdnOptional -> { + loginGenericTextInputFormTitle.text = getString(R.string.login_set_msisdn_title) + loginGenericTextInputFormNotice.text = getString(R.string.login_set_msisdn_notice) + loginGenericTextInputFormTil.hint = getString(R.string.login_set_msisdn_optional_hint) + loginGenericTextInputFormTextInput.inputType = InputType.TYPE_CLASS_PHONE + loginGenericTextInputFormOtherButton.isVisible = false + loginGenericTextInputFormSubmit.text = getString(R.string.login_set_msisdn_submit) + } + TextInputFormFragmentMode.ConfirmMsisdn -> { + loginGenericTextInputFormTitle.text = getString(R.string.login_msisdn_confirm_title) + loginGenericTextInputFormNotice.text = getString(R.string.login_msisdn_confirm_notice) + loginGenericTextInputFormTil.hint = getString(R.string.login_msisdn_confirm_hint) + loginGenericTextInputFormTextInput.inputType = InputType.TYPE_CLASS_NUMBER + loginGenericTextInputFormOtherButton.isVisible = true + loginGenericTextInputFormOtherButton.text = getString(R.string.login_msisdn_confirm_send_again) + loginGenericTextInputFormSubmit.text = getString(R.string.login_msisdn_confirm_submit) + } + } + } + + @OnClick(R.id.loginGenericTextInputFormOtherButton) + fun onOtherButtonClicked() { + // TODO + } + + @OnClick(R.id.loginGenericTextInputFormSubmit) + fun onSubmitClicked() { + // TODO + } + + private fun setupSubmitButton() { + when (params.mode) { + TextInputFormFragmentMode.SetEmailMandatory, + TextInputFormFragmentMode.SetMsisdnMandatory, + TextInputFormFragmentMode.ConfirmMsisdn -> { + loginGenericTextInputFormSubmit.isEnabled = false + loginGenericTextInputFormTextInput.textChanges() + .subscribe { + // TODO Better check for email format, etc? + loginGenericTextInputFormSubmit.isEnabled = it.isNotBlank() + } + .disposeOnDestroyView() + } + TextInputFormFragmentMode.SetEmailOptional, + TextInputFormFragmentMode.SetMsisdnOptional -> { + loginGenericTextInputFormSubmit.isEnabled = true + } + } + } + + override fun resetViewModel() { + // Nothing to do + } +} diff --git a/vector/src/main/res/layout/fragment_login_generic_text_input_form.xml b/vector/src/main/res/layout/fragment_login_generic_text_input_form.xml new file mode 100644 index 0000000000..4edd635515 --- /dev/null +++ b/vector/src/main/res/layout/fragment_login_generic_text_input_form.xml @@ -0,0 +1,98 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/vector/src/main/res/values/strings_riotX.xml b/vector/src/main/res/values/strings_riotX.xml index 089ac19b7e..db6d9e673f 100644 --- a/vector/src/main/res/values/strings_riotX.xml +++ b/vector/src/main/res/values/strings_riotX.xml @@ -69,4 +69,23 @@ Tap on the link to confirm your new password. Back to Sign In + Set email address + Set an email to recover your account. Later, you can optionally allow people you know to discover you by your email. + Email + Email (optional) + Next + + Set phone number + Set a phone number to optionally allow people you know to discover you. + Phone number + Phone number (optional) + Next + + Confirm phone number + + We just sent a code to %1$s. Enter it below to verify it’s you. + Enter code + Send again + Next +