Improved CreateSeedLayout using TextInputLayout

This commit is contained in:
Severiano Jaramillo 2018-01-24 18:35:08 -06:00
parent aabdab2951
commit dc4bd347c3
2 changed files with 157 additions and 198 deletions

View file

@ -3,6 +3,8 @@ package cy.agorise.crystalwallet.activities;
import android.arch.lifecycle.ViewModelProviders; import android.arch.lifecycle.ViewModelProviders;
import android.content.Intent; import android.content.Intent;
import android.os.Bundle; import android.os.Bundle;
import android.support.design.widget.TextInputEditText;
import android.support.design.widget.TextInputLayout;
import android.support.v7.app.AlertDialog; import android.support.v7.app.AlertDialog;
import android.support.v7.app.AppCompatActivity; import android.support.v7.app.AppCompatActivity;
import android.text.Editable; import android.text.Editable;
@ -39,23 +41,26 @@ public class CreateSeedActivity extends AppCompatActivity implements UIValidator
AccountSeedViewModel accountSeedViewModel; AccountSeedViewModel accountSeedViewModel;
CreateSeedValidator createSeedValidator; CreateSeedValidator createSeedValidator;
@BindView(R.id.etPin) @BindView(R.id.tilPin)
EditText etPin; TextInputLayout tilPin;
@BindView(R.id.tvPinError)
TextView tvPinError;
@BindView(R.id.etPinConfirmation) @BindView(R.id.tietPin)
EditText etPinConfirmation; TextInputEditText tietPin;
@BindView(R.id.tvPinConfirmationError)
TextView tvPinConfirmationError; @BindView(R.id.tilPinConfirmation)
TextInputLayout tilPinConfirmation;
@BindView(R.id.tietPinConfirmation)
TextInputEditText tietPinConfirmation;
//@BindView(R.id.tvSeedWords) //@BindView(R.id.tvSeedWords)
//TextView tvSeedWords; //TextView tvSeedWords;
@BindView (R.id.etAccountName) @BindView(R.id.tilAccountName)
EditText etAccountName; TextInputLayout tilAccountName;
@BindView(R.id.tvAccountNameError)
TextView tvAccountNameError; @BindView (R.id.tietAccountName)
TextInputEditText tietAccountName;
@BindView(R.id.btnCreate) @BindView(R.id.btnCreate)
Button btnCreate; Button btnCreate;
@ -69,19 +74,23 @@ public class CreateSeedActivity extends AppCompatActivity implements UIValidator
setContentView(R.layout.create_seed); setContentView(R.layout.create_seed);
ButterKnife.bind(this); ButterKnife.bind(this);
tilPin.setErrorEnabled(true);
tilPinConfirmation.setErrorEnabled(true);
tilAccountName.setErrorEnabled(true);
btnCreate.setEnabled(false); btnCreate.setEnabled(false);
accountSeedViewModel = ViewModelProviders.of(this).get(AccountSeedViewModel.class); accountSeedViewModel = ViewModelProviders.of(this).get(AccountSeedViewModel.class);
createSeedValidator = new CreateSeedValidator(this.getApplicationContext(),etPin,etPinConfirmation,etAccountName); createSeedValidator = new CreateSeedValidator(this.getApplicationContext(),tietPin,tietPinConfirmation,tietAccountName);
createSeedValidator.setListener(this); createSeedValidator.setListener(this);
} }
@OnTextChanged(value = R.id.etPin, @OnTextChanged(value = R.id.tietPin,
callback = OnTextChanged.Callback.AFTER_TEXT_CHANGED) callback = OnTextChanged.Callback.AFTER_TEXT_CHANGED)
void afterPinChanged(Editable editable) { void afterPinChanged(Editable editable) {
this.createSeedValidator.validate(); this.createSeedValidator.validate();
} }
@OnTextChanged(value = R.id.etPinConfirmation, @OnTextChanged(value = R.id.tietPinConfirmation,
callback = OnTextChanged.Callback.AFTER_TEXT_CHANGED) callback = OnTextChanged.Callback.AFTER_TEXT_CHANGED)
void afterPinConfirmationChanged(Editable editable) { void afterPinConfirmationChanged(Editable editable) {
this.createSeedValidator.validate(); this.createSeedValidator.validate();
@ -94,7 +103,7 @@ public class CreateSeedActivity extends AppCompatActivity implements UIValidator
} }
*/ */
@OnTextChanged(value = R.id.etAccountName, @OnTextChanged(value = R.id.tietAccountName,
callback = OnTextChanged.Callback.AFTER_TEXT_CHANGED) callback = OnTextChanged.Callback.AFTER_TEXT_CHANGED)
void afterAccountNameChanged(Editable editable) { void afterAccountNameChanged(Editable editable) {
this.createSeedValidator.validate(); this.createSeedValidator.validate();
@ -110,7 +119,7 @@ public class CreateSeedActivity extends AppCompatActivity implements UIValidator
if (this.createSeedValidator.isValid()) { if (this.createSeedValidator.isValid()) {
// Make request to create a bitshare account // Make request to create a bitshare account
final ValidateCreateBitsharesAccountRequest request = final ValidateCreateBitsharesAccountRequest request =
new ValidateCreateBitsharesAccountRequest(etAccountName.getText().toString(), getApplicationContext()); new ValidateCreateBitsharesAccountRequest(tietAccountName.getText().toString(), getApplicationContext());
//Makes dialog to tell the user that the account is been created //Makes dialog to tell the user that the account is been created
@ -168,12 +177,12 @@ public class CreateSeedActivity extends AppCompatActivity implements UIValidator
activity.runOnUiThread(new Runnable() { activity.runOnUiThread(new Runnable() {
public void run() { public void run() {
if (field.getView() == etPin) { if (field.getView() == tietPin) {
tvPinError.setText(""); tilPin.setError("");
} else if (field.getView() == etPinConfirmation){ } else if (field.getView() == tietPinConfirmation){
tvPinConfirmationError.setText(""); tilPinConfirmation.setError("");
} else if (field.getView() == etAccountName){ } else if (field.getView() == tietAccountName){
tvAccountNameError.setText(""); tilAccountName.setError("");
} //else if (field.getView() == etSeedWords){ } //else if (field.getView() == etSeedWords){
// tvSeedWordsError.setText(""); // tvSeedWordsError.setText("");
//} //}
@ -194,12 +203,12 @@ public class CreateSeedActivity extends AppCompatActivity implements UIValidator
@Override @Override
public void run() { public void run() {
if (field.getView() == etPin) { if (field.getView() == tietPin) {
tvPinError.setText(field.getMessage()); tilPin.setError(field.getMessage());
} else if (field.getView() == etPinConfirmation){ } else if (field.getView() == tietPinConfirmation){
tvPinConfirmationError.setText(field.getMessage()); tilPinConfirmation.setError(field.getMessage());
} else if (field.getView() == etAccountName){ } else if (field.getView() == tietAccountName){
tvAccountNameError.setText(field.getMessage()); tilAccountName.setError(field.getMessage());
} //else if (field.getView() == etSeedWords){ } //else if (field.getView() == etSeedWords){
// tvSeedWordsError.setText(field.getMessage()); // tvSeedWordsError.setText(field.getMessage());
//} //}

View file

@ -1,108 +1,73 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" <android.support.constraint.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" xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
android:orientation="vertical" tools:context=".activities.CreateSeedActivity">
android:paddingBottom="0dp"
android:paddingLeft="0dp"
android:paddingRight="0dp"
android:paddingTop="@dimen/activity_vertical_margin">
<TextView <android.support.design.widget.TextInputLayout
android:id="@+id/tvPin" android:id="@+id/tilPin"
android:layout_width="match_parent" android:layout_width="0dp"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginLeft="@dimen/activity_horizontal_margin" android:layout_marginEnd="24dp"
android:layout_marginRight="@dimen/activity_horizontal_margin" android:layout_marginStart="24dp"
android:layout_marginTop="10dp" android:layout_marginTop="32dp"
android:text="@string/txt_6_digits_pin" app:layout_constraintBottom_toTopOf="@+id/tilPinConfirmation"
android:textStyle="bold" /> app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintVertical_bias="0.1"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_chainStyle="packed">
<EditText <android.support.design.widget.TextInputEditText
android:id="@+id/etPin" android:id="@+id/tietPin"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="40dp" android:layout_height="wrap_content"
android:layout_marginLeft="@dimen/activity_horizontal_margin" android:hint="@string/txt_6_digits_pin"
android:layout_marginRight="@dimen/activity_horizontal_margin" android:inputType="number"
android:background="@drawable/edittext_bg" android:singleLine="true" />
android:inputType="number" </android.support.design.widget.TextInputLayout>
android:maxLines="1"
android:textColor="@color/black" />
<TextView <android.support.design.widget.TextInputLayout
android:id="@+id/tvPinError" android:id="@+id/tilPinConfirmation"
android:layout_width="match_parent" android:layout_width="0dp"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginLeft="@dimen/activity_horizontal_margin" android:layout_marginTop="8dp"
android:layout_marginRight="@dimen/activity_horizontal_margin" app:layout_constraintBottom_toTopOf="@+id/tilAccountName"
android:layout_marginTop="10dp" app:layout_constraintTop_toBottomOf="@+id/tilPin"
android:textColor="@color/red" app:layout_constraintStart_toStartOf="@id/tilPin"
android:textStyle="bold" /> app:layout_constraintEnd_toEndOf="@id/tilPin">
<TextView <android.support.design.widget.TextInputEditText
android:id="@+id/tvPinConfirmation" android:id="@+id/tietPinConfirmation"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/txt_6_digits_pin_confirm"
android:inputType="number"
android:singleLine="true" />
</android.support.design.widget.TextInputLayout>
<android.support.design.widget.TextInputLayout
android:id="@+id/tilAccountName"
android:layout_width="0dp"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginLeft="@dimen/activity_horizontal_margin" android:layout_marginTop="8dp"
android:layout_marginRight="@dimen/activity_horizontal_margin" app:layout_constraintBottom_toTopOf="@+id/btnCancel"
android:layout_marginTop="10dp" app:layout_constraintTop_toBottomOf="@+id/tilPinConfirmation"
android:text="@string/txt_6_digits_pin_confirm" app:layout_constraintStart_toStartOf="@id/tilPinConfirmation"
android:textStyle="bold" /> app:layout_constraintEnd_toEndOf="@id/tilPinConfirmation">
<EditText
android:id="@+id/etPinConfirmation"
android:layout_width="match_parent"
android:layout_height="40dp"
android:layout_marginLeft="@dimen/activity_horizontal_margin"
android:layout_marginRight="@dimen/activity_horizontal_margin"
android:background="@drawable/edittext_bg"
android:inputType="number"
android:maxLines="1"
android:singleLine="true"
android:textColor="@color/black" />
<TextView
android:id="@+id/tvPinConfirmationError"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="@dimen/activity_horizontal_margin"
android:layout_marginRight="@dimen/activity_horizontal_margin"
android:layout_marginTop="10dp"
android:textColor="@color/red"
android:textStyle="bold" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="@dimen/activity_horizontal_margin"
android:layout_marginRight="@dimen/activity_horizontal_margin"
android:layout_marginTop="10dp"
android:text="@string/txt_account_name"
android:textStyle="bold" />
<EditText
android:id="@+id/etAccountName"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="@dimen/activity_horizontal_margin"
android:layout_marginRight="@dimen/activity_horizontal_margin"
android:background="@drawable/edittext_bg"
android:gravity="top"
android:inputType="textMultiLine"
android:textColor="@color/black" />
<TextView
android:id="@+id/tvAccountNameError"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="@dimen/activity_horizontal_margin"
android:layout_marginRight="@dimen/activity_horizontal_margin"
android:layout_marginTop="10dp"
android:textColor="@color/red"
android:textStyle="bold" />
<android.support.design.widget.TextInputEditText
android:id="@+id/tietAccountName"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/txt_account_name"
android:inputType="textMultiLine"
android:singleLine="true" />
</android.support.design.widget.TextInputLayout>
<!--
<TextView <TextView
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
@ -111,90 +76,75 @@
android:layout_marginTop="10dp" android:layout_marginTop="10dp"
android:text="@string/txt_brain_key_info" android:text="@string/txt_brain_key_info"
android:textSize="15dp" android:textSize="15dp"
android:visibility="gone" /> android:visibility="gone" /> -->
<LinearLayout <Button
android:layout_width="match_parent" android:id="@+id/btnCancel"
android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginLeft="@dimen/activity_horizontal_margin" android:layout_gravity="center"
android:layout_marginRight="@dimen/activity_horizontal_margin" android:layout_marginStart="24dp"
android:layout_marginTop="10dp" android:layout_marginTop="48dp"
android:gravity="center" android:background="@color/redcolor"
android:orientation="horizontal"> android:text="@string/cancel"
android:textColor="@color/white"
android:textStyle="bold"
app:layout_constraintBottom_toTopOf="@+id/linearLayout"
app:layout_constraintStart_toStartOf="@id/tilAccountName"
app:layout_constraintTop_toBottomOf="@+id/tilAccountName" />
<Button <Button
android:id="@+id/btnCancel" android:id="@+id/btnCreate"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_gravity="center" android:layout_gravity="center"
android:layout_margin="10dp" android:layout_marginEnd="24dp"
android:background="@color/pink" android:background="@color/colorPrimary"
android:text="@string/cancel" android:padding="10dp"
android:textColor="@color/white" /> android:text="@string/create_wallet"
android:textColor="@color/white"
<Button android:textStyle="bold"
android:id="@+id/btnCreate" app:layout_constraintEnd_toEndOf="@id/tilAccountName"
android:layout_width="wrap_content" app:layout_constraintTop_toTopOf="@id/btnCancel" />
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_margin="10dp"
android:background="@color/green"
android:padding="10dp"
android:text="@string/create_wallet"
android:textColor="@color/white" />
</LinearLayout>
<LinearLayout <LinearLayout
android:id="@+id/linearLayout"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="35dp"
android:background="@color/white" android:background="@color/bottomBarColor"
android:gravity="bottom" android:orientation="horizontal"
android:orientation="vertical"> app:layout_constraintBottom_toBottomOf="parent">
<LinearLayout <TextView
android:layout_width="match_parent" android:id="@+id/tvAppVersion_brain_key_activity"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:gravity="center"
android:text="@string/v_1_0_beta" />
<TextView
android:id="@+id/tvBlockNumberHead_brain_key_activity"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="2"
android:gravity="center"
android:text="@string/block_number" />
<ImageView
android:id="@+id/ivSocketConnected_brain_key_activity"
android:layout_width="0dp"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:background="@color/black"></LinearLayout> android:layout_gravity="center"
android:layout_weight="0.5" />
<LinearLayout <ImageView
android:layout_width="match_parent" android:layout_width="0dp"
android:layout_height="35dp" android:layout_height="wrap_content"
android:background="@color/bottomBarColor" android:layout_gravity="center"
android:gravity="bottom" android:layout_weight="0.5"
android:orientation="horizontal"> android:src="@drawable/icon_setting"
android:visibility="invisible" />
<TextView
android:id="@+id/tvAppVersion_brain_key_activity"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:gravity="center"
android:text="@string/v_1_0_beta" />
<TextView
android:id="@+id/tvBlockNumberHead_brain_key_activity"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="2"
android:gravity="center"
android:text="@string/block_number" />
<ImageView
android:id="@+id/ivSocketConnected_brain_key_activity"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_weight="0.5" />
<ImageView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_weight="0.5"
android:src="@drawable/icon_setting"
android:visibility="invisible" />
</LinearLayout>
</LinearLayout> </LinearLayout>
</LinearLayout> </android.support.constraint.ConstraintLayout>