From dc4bd347c365c4f3fa16c139ea96e7f510a38f0a Mon Sep 17 00:00:00 2001 From: Severiano Jaramillo Date: Wed, 24 Jan 2018 18:35:08 -0600 Subject: [PATCH] Improved CreateSeedLayout using TextInputLayout --- .../activities/CreateSeedActivity.java | 67 ++-- app/src/main/res/layout/create_seed.xml | 288 ++++++++---------- 2 files changed, 157 insertions(+), 198 deletions(-) diff --git a/app/src/main/java/cy/agorise/crystalwallet/activities/CreateSeedActivity.java b/app/src/main/java/cy/agorise/crystalwallet/activities/CreateSeedActivity.java index 7c4a88b..8eca7a1 100644 --- a/app/src/main/java/cy/agorise/crystalwallet/activities/CreateSeedActivity.java +++ b/app/src/main/java/cy/agorise/crystalwallet/activities/CreateSeedActivity.java @@ -3,6 +3,8 @@ package cy.agorise.crystalwallet.activities; import android.arch.lifecycle.ViewModelProviders; import android.content.Intent; 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.AppCompatActivity; import android.text.Editable; @@ -39,23 +41,26 @@ public class CreateSeedActivity extends AppCompatActivity implements UIValidator AccountSeedViewModel accountSeedViewModel; CreateSeedValidator createSeedValidator; - @BindView(R.id.etPin) - EditText etPin; - @BindView(R.id.tvPinError) - TextView tvPinError; + @BindView(R.id.tilPin) + TextInputLayout tilPin; - @BindView(R.id.etPinConfirmation) - EditText etPinConfirmation; - @BindView(R.id.tvPinConfirmationError) - TextView tvPinConfirmationError; + @BindView(R.id.tietPin) + TextInputEditText tietPin; + + @BindView(R.id.tilPinConfirmation) + TextInputLayout tilPinConfirmation; + + @BindView(R.id.tietPinConfirmation) + TextInputEditText tietPinConfirmation; //@BindView(R.id.tvSeedWords) //TextView tvSeedWords; - @BindView (R.id.etAccountName) - EditText etAccountName; - @BindView(R.id.tvAccountNameError) - TextView tvAccountNameError; + @BindView(R.id.tilAccountName) + TextInputLayout tilAccountName; + + @BindView (R.id.tietAccountName) + TextInputEditText tietAccountName; @BindView(R.id.btnCreate) Button btnCreate; @@ -69,19 +74,23 @@ public class CreateSeedActivity extends AppCompatActivity implements UIValidator setContentView(R.layout.create_seed); ButterKnife.bind(this); + tilPin.setErrorEnabled(true); + tilPinConfirmation.setErrorEnabled(true); + tilAccountName.setErrorEnabled(true); + btnCreate.setEnabled(false); 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); } - @OnTextChanged(value = R.id.etPin, + @OnTextChanged(value = R.id.tietPin, callback = OnTextChanged.Callback.AFTER_TEXT_CHANGED) void afterPinChanged(Editable editable) { this.createSeedValidator.validate(); } - @OnTextChanged(value = R.id.etPinConfirmation, + @OnTextChanged(value = R.id.tietPinConfirmation, callback = OnTextChanged.Callback.AFTER_TEXT_CHANGED) void afterPinConfirmationChanged(Editable editable) { 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) void afterAccountNameChanged(Editable editable) { this.createSeedValidator.validate(); @@ -110,7 +119,7 @@ public class CreateSeedActivity extends AppCompatActivity implements UIValidator if (this.createSeedValidator.isValid()) { // Make request to create a bitshare account 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 @@ -168,12 +177,12 @@ public class CreateSeedActivity extends AppCompatActivity implements UIValidator activity.runOnUiThread(new Runnable() { public void run() { - if (field.getView() == etPin) { - tvPinError.setText(""); - } else if (field.getView() == etPinConfirmation){ - tvPinConfirmationError.setText(""); - } else if (field.getView() == etAccountName){ - tvAccountNameError.setText(""); + if (field.getView() == tietPin) { + tilPin.setError(""); + } else if (field.getView() == tietPinConfirmation){ + tilPinConfirmation.setError(""); + } else if (field.getView() == tietAccountName){ + tilAccountName.setError(""); } //else if (field.getView() == etSeedWords){ // tvSeedWordsError.setText(""); //} @@ -194,12 +203,12 @@ public class CreateSeedActivity extends AppCompatActivity implements UIValidator @Override public void run() { - if (field.getView() == etPin) { - tvPinError.setText(field.getMessage()); - } else if (field.getView() == etPinConfirmation){ - tvPinConfirmationError.setText(field.getMessage()); - } else if (field.getView() == etAccountName){ - tvAccountNameError.setText(field.getMessage()); + if (field.getView() == tietPin) { + tilPin.setError(field.getMessage()); + } else if (field.getView() == tietPinConfirmation){ + tilPinConfirmation.setError(field.getMessage()); + } else if (field.getView() == tietAccountName){ + tilAccountName.setError(field.getMessage()); } //else if (field.getView() == etSeedWords){ // tvSeedWordsError.setText(field.getMessage()); //} diff --git a/app/src/main/res/layout/create_seed.xml b/app/src/main/res/layout/create_seed.xml index e31aa8e..1958f75 100644 --- a/app/src/main/res/layout/create_seed.xml +++ b/app/src/main/res/layout/create_seed.xml @@ -1,108 +1,73 @@ - + tools:context=".activities.CreateSeedActivity"> - + android:layout_marginEnd="24dp" + android:layout_marginStart="24dp" + android:layout_marginTop="32dp" + app:layout_constraintBottom_toTopOf="@+id/tilPinConfirmation" + 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"> - + + - + android:layout_marginTop="8dp" + app:layout_constraintBottom_toTopOf="@+id/tilAccountName" + app:layout_constraintTop_toBottomOf="@+id/tilPin" + app:layout_constraintStart_toStartOf="@id/tilPin" + app:layout_constraintEnd_toEndOf="@id/tilPin"> - + + + - - - - - - - - - - - + android:layout_marginTop="8dp" + app:layout_constraintBottom_toTopOf="@+id/btnCancel" + app:layout_constraintTop_toBottomOf="@+id/tilPinConfirmation" + app:layout_constraintStart_toStartOf="@id/tilPinConfirmation" + app:layout_constraintEnd_toEndOf="@id/tilPinConfirmation"> + + + - + android:layout_gravity="center" + android:layout_marginStart="24dp" + android:layout_marginTop="48dp" + android:background="@color/redcolor" + 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" /> -