Login screens: Simple Input form (UI)

This commit is contained in:
Benoit Marty 2019-11-18 15:03:07 +01:00
parent f24889230c
commit 08ea3d049e
3 changed files with 257 additions and 0 deletions

View File

@ -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
}
}

View File

@ -0,0 +1,98 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/login_fragment"
android:layout_width="match_parent"
android:layout_height="match_parent">
<androidx.core.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<LinearLayout
style="@style/LoginContainer"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<ImageView
android:id="@+id/logoImageView"
style="@style/LoginTopIcon"
android:layout_gravity="center_horizontal" />
<TextView
android:id="@+id/loginGenericTextInputFormTitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="130dp"
android:textAppearance="@style/TextAppearance.Vector.Login.Title"
tools:text="@string/login_set_email_title" />
<TextView
android:id="@+id/loginGenericTextInputFormNotice"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/layout_vertical_margin"
android:gravity="start"
android:textAppearance="@style/TextAppearance.Vector.Login.Text.Small"
tools:text="@string/login_set_email_notice" />
<com.google.android.material.textfield.TextInputLayout
android:id="@+id/loginGenericTextInputFormTil"
style="@style/VectorTextInputLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="26dp"
app:errorEnabled="true"
tools:hint="@string/login_set_email_optional_hint">
<com.google.android.material.textfield.TextInputEditText
android:id="@+id/loginGenericTextInputFormTextInput"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:imeOptions="actionDone"
android:maxLines="1"
tools:inputType="textEmailAddress" />
</com.google.android.material.textfield.TextInputLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:orientation="horizontal">
<com.google.android.material.button.MaterialButton
android:id="@+id/loginGenericTextInputFormOtherButton"
style="@style/Style.Vector.Login.Button.Text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="start"
android:visibility="gone"
tools:text="@string/login_msisdn_confirm_send_again"
tools:visibility="visible" />
<com.google.android.material.button.MaterialButton
android:id="@+id/loginGenericTextInputFormSubmit"
style="@style/Style.Vector.Login.Button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_gravity="end"
android:enabled="false"
tools:ignore="RelativeOverlap"
tools:text="@string/login_set_email_submit" />
</RelativeLayout>
</LinearLayout>
</androidx.core.widget.NestedScrollView>
</androidx.constraintlayout.widget.ConstraintLayout>

View File

@ -69,4 +69,23 @@
<string name="login_reset_password_success_notice_2">Tap on the link to confirm your new password.</string>
<string name="login_reset_password_success_submit">Back to Sign In</string>
<string name="login_set_email_title">Set email address</string>
<string name="login_set_email_notice">Set an email to recover your account. Later, you can optionally allow people you know to discover you by your email.</string>
<string name="login_set_email_mandatory_hint">Email</string>
<string name="login_set_email_optional_hint">Email (optional)</string>
<string name="login_set_email_submit">Next</string>
<string name="login_set_msisdn_title">Set phone number</string>
<string name="login_set_msisdn_notice">Set a phone number to optionally allow people you know to discover you.</string>
<string name="login_set_msisdn_mandatory_hint">Phone number</string>
<string name="login_set_msisdn_optional_hint">Phone number (optional)</string>
<string name="login_set_msisdn_submit">Next</string>
<string name="login_msisdn_confirm_title">Confirm phone number</string>
<!-- Template will be replaced by a phone number -->
<string name="login_msisdn_confirm_notice">We just sent a code to %1$s. Enter it below to verify its you.</string>
<string name="login_msisdn_confirm_hint">Enter code</string>
<string name="login_msisdn_confirm_send_again">Send again</string>
<string name="login_msisdn_confirm_submit">Next</string>
</resources>