- Adding TextView under EditText to display errors

This commit is contained in:
Javier Varona 2017-10-04 22:46:55 -04:00
parent e9e8c11eb3
commit 2cf1104a30
7 changed files with 204 additions and 99 deletions

View file

@ -33,6 +33,8 @@ dependencies {
exclude group: 'com.android.support', module: 'support-annotations'
})
compile 'com.android.support:appcompat-v7:26.1.0'
compile 'com.android.support:support-v4:26.1.0'
compile 'com.android.support:design:26.1.0'
compile 'com.android.support.constraint:constraint-layout:1.0.2'
testCompile 'junit:junit:4.12'
testCompile 'org.mockito:mockito-core:1.10.19'

View file

@ -9,7 +9,7 @@
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
android:theme="@style/Theme.AppCompat">
<activity android:name=".activities.IntroActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

View file

@ -24,6 +24,7 @@ import cy.agorise.crystalwallet.viewmodels.AccountSeedViewModel;
import cy.agorise.crystalwallet.viewmodels.TransactionListViewModel;
import cy.agorise.crystalwallet.viewmodels.validators.ImportSeedValidator;
import cy.agorise.crystalwallet.viewmodels.validators.ImportSeedValidatorListener;
import cy.agorise.crystalwallet.viewmodels.validators.ValidationField;
import cy.agorise.crystalwallet.views.TransactionListView;
public class ImportSeedActivity extends AppCompatActivity implements ImportSeedValidatorListener {
@ -31,17 +32,23 @@ public class ImportSeedActivity extends AppCompatActivity implements ImportSeedV
AccountSeedViewModel accountSeedViewModel;
ImportSeedValidator importSeedValidator;
@BindView(R.id.tvPin)
TextView tvPin;
@BindView(R.id.etPin)
EditText etPin;
@BindView(R.id.tvPinError)
TextView tvPinError;
@BindView(R.id.tvPinConfirmation)
TextView tvPinConfirmation;
@BindView(R.id.etPinConfirmation)
EditText etPinConfirmation;
@BindView(R.id.tvPinConfirmationError)
TextView tvPinConfirmationError;
@BindView(R.id.etSeedWords)
EditText etSeedWords;
@BindView (R.id.etAccountName)
EditText etAccountName;
@BindView(R.id.tvAccountNameError)
TextView tvAccountNameError;
@BindView(R.id.btnImport)
Button btnImport;
@ -59,6 +66,19 @@ public class ImportSeedActivity extends AppCompatActivity implements ImportSeedV
importSeedValidator.setListener(this);
}
@OnTextChanged(value = R.id.etPin,
callback = OnTextChanged.Callback.AFTER_TEXT_CHANGED)
void afterPinChanged(Editable editable) {
this.importSeedValidator.validatePin(editable.toString());
this.importSeedValidator.validatePinConfirmation(etPinConfirmation.getText().toString(),editable.toString());
}
@OnTextChanged(value = R.id.etPinConfirmation,
callback = OnTextChanged.Callback.AFTER_TEXT_CHANGED)
void afterPinConfirmationChanged(Editable editable) {
this.importSeedValidator.validatePinConfirmation(editable.toString(), etPin.getText().toString());
}
@OnTextChanged(value = R.id.etAccountName,
callback = OnTextChanged.Callback.AFTER_TEXT_CHANGED)
void afterAccountNameChanged(Editable editable) {
@ -82,14 +102,32 @@ public class ImportSeedActivity extends AppCompatActivity implements ImportSeedV
}
@Override
public void onValidationSucceeded() {
//Clear all errors
public void onValidationSucceeded(ValidationField field) {
switch (field.getName()){
case "pin":
tvPinError.setText("");
break;
case "pinconfirmation":
tvPinConfirmationError.setText("");
break;
case "accountname":
tvAccountNameError.setText("");
break;
}
}
@Override
public void onValidationFailed(String error) {
//Show errors
Toast.makeText(this, error,
Toast.LENGTH_LONG).show();
public void onValidationFailed(ValidationField field) {
switch (field.getName()){
case "pin":
tvPinError.setText(field.getMessage());
break;
case "pinconfirmation":
tvPinConfirmationError.setText(field.getMessage());
break;
case "accountname":
tvAccountNameError.setText(field.getMessage());
break;
}
}
}

View file

@ -28,8 +28,8 @@ public class ImportSeedValidator {
public ImportSeedValidator(Resources res){
this.res = res;
this.validationFields = new ArrayList<ValidationField>();
//this.validationFields.add(new ValidationField("pin"));
//this.validationFields.add(new ValidationField("pinConfirmation"));
this.validationFields.add(new ValidationField("pin"));
this.validationFields.add(new ValidationField("pinconfirmation"));
this.validationFields.add(new ValidationField("accountname"));
}
@ -59,9 +59,33 @@ public class ImportSeedValidator {
return null;
}
//public validatePin(){
public void validatePin(final String pin){
final ValidationField validationField = getValidationField("pin");
validationField.setLastValue(pin);
//}
if ((pin.length() < 6)){
validationField.setValidForValue(pin,false);
validationField.setMessage(res.getString(R.string.pin_number_warning));
listener.onValidationFailed(validationField);
} else {
validationField.setValidForValue(pin, true);
listener.onValidationSucceeded(validationField);
}
}
public void validatePinConfirmation(final String pinConfirmation, final String pin){
final ValidationField validationField = getValidationField("pinconfirmation");
validationField.setLastValue(pinConfirmation);
if (!pinConfirmation.equals(pin)){
validationField.setValidForValue(pinConfirmation,false);
validationField.setMessage(res.getString(R.string.mismatch_pin));
listener.onValidationFailed(validationField);
} else {
validationField.setValidForValue(pinConfirmation, true);
listener.onValidationSucceeded(validationField);
}
}
public void validateAccountName(final String accountName, final String mnemonic){
final ValidationField validationField = getValidationField("accountname");
@ -74,8 +98,10 @@ public class ImportSeedValidator {
if (!request.getAccountExists()){
validationField.setValidForValue(accountName, false);
validationField.setMessage(res.getString(R.string.account_name_not_exist));
listener.onValidationFailed(validationField);
} else {
validationField.setValidForValue(accountName, true);
listener.onValidationSucceeded(validationField);
}
}
});

View file

@ -6,6 +6,6 @@ package cy.agorise.crystalwallet.viewmodels.validators;
public interface ImportSeedValidatorListener {
public void onValidationSucceeded();
public void onValidationFailed(String error);
public void onValidationSucceeded(ValidationField field);
public void onValidationFailed(ValidationField field);
}

View file

@ -2,62 +2,85 @@
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:background="@color/white"
android:layout_height="match_parent"
android:orientation="vertical"
android:paddingBottom="0dp"
android:paddingLeft="0dp"
android:paddingRight="0dp"
android:paddingTop="@dimen/activity_vertical_margin"
android:orientation="vertical">
android:paddingTop="@dimen/activity_vertical_margin">
<TextView
android:layout_marginLeft="@dimen/activity_horizontal_margin"
android:layout_marginRight="@dimen/activity_horizontal_margin"
android:id="@+id/tvPin"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/txt_6_digits_pin"
android:id="@+id/tvPin"
android:textStyle="bold"
android:layout_marginTop="10dp"/>
<EditText
android:layout_marginLeft="@dimen/activity_horizontal_margin"
android:layout_marginRight="@dimen/activity_horizontal_margin"
android:layout_marginTop="10dp"
android:text="@string/txt_6_digits_pin"
android:textStyle="bold" />
<EditText
android:id="@+id/etPin"
android:layout_width="match_parent"
android:inputType="number"
android:background="@drawable/edittext_bg"
android:maxLines="1"
android:layout_height="40dp"/>
<TextView
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:textColor="@color/black" />
<TextView
android:id="@+id/tvPinError"
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:id="@+id/tvPinConfirmation"
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_6_digits_pin_confirm"
android:textStyle="bold"
android:layout_marginTop="10dp"/>
android:textStyle="bold" />
<EditText
android:layout_marginLeft="@dimen/activity_horizontal_margin"
android:layout_marginRight="@dimen/activity_horizontal_margin"
android:id="@+id/etPinConfirmation"
android:layout_width="match_parent"
android:inputType="number"
android:layout_height="40dp"
android:layout_marginLeft="@dimen/activity_horizontal_margin"
android:layout_marginRight="@dimen/activity_horizontal_margin"
android:background="@drawable/edittext_bg"
android:singleLine="true"
android:inputType="number"
android:maxLines="1"
android:layout_height="40dp" />
android:singleLine="true"
android:textColor="@color/black" />
<TextView
android:layout_marginLeft="@dimen/activity_horizontal_margin"
android:layout_marginRight="@dimen/activity_horizontal_margin"
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/seed_words"
android:textStyle="bold"
android:layout_marginTop="10dp"/>
android:textStyle="bold" />
<EditText
android:id="@+id/etSeedWords"
@ -67,16 +90,17 @@
android:layout_marginRight="@dimen/activity_horizontal_margin"
android:background="@drawable/edittext_bg"
android:gravity="top"
android:inputType="textMultiLine" />
android:inputType="textMultiLine"
android:textColor="@color/black" />
<TextView
android:layout_marginLeft="@dimen/activity_horizontal_margin"
android:layout_marginRight="@dimen/activity_horizontal_margin"
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"
android:layout_marginTop="10dp"/>
android:textStyle="bold" />
<EditText
android:id="@+id/etAccountName"
@ -86,95 +110,110 @@
android:layout_marginRight="@dimen/activity_horizontal_margin"
android:background="@drawable/edittext_bg"
android:gravity="top"
android:inputType="textMultiLine" />
android:inputType="textMultiLine"
android:textColor="@color/black" />
<TextView
android:visibility="gone"
android:layout_marginLeft="@dimen/activity_horizontal_margin"
android:layout_marginRight="@dimen/activity_horizontal_margin"
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" />
<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_brain_key_info"
android:textSize="15dp"
android:layout_marginTop="10dp"/>
android:visibility="gone" />
<LinearLayout
android:layout_marginLeft="@dimen/activity_horizontal_margin"
android:layout_marginRight="@dimen/activity_horizontal_margin"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_marginLeft="@dimen/activity_horizontal_margin"
android:layout_marginRight="@dimen/activity_horizontal_margin"
android:layout_marginTop="10dp"
android:gravity="center">
android:gravity="center"
android:orientation="horizontal">
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@color/pink"
android:textColor="@color/white"
android:layout_margin="10dp"
android:layout_gravity="center"
android:id="@+id/btnCancel"
android:text="@string/cancel"/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@color/green"
android:textColor="@color/white"
android:layout_margin="10dp"
android:padding="10dp"
android:layout_gravity="center"
android:layout_margin="10dp"
android:background="@color/pink"
android:text="@string/cancel"
android:textColor="@color/white" />
<Button
android:id="@+id/btnImport"
android:text="@string/create_wallet"/>
android:layout_width="wrap_content"
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
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="bottom"
android:background="@color/white"
android:gravity="bottom"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/black">
</LinearLayout>
android:background="@color/black"></LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="35dp"
android:background="@color/bottomBarColor"
android:gravity="bottom"
android:orientation="horizontal"
android:background="@color/bottomBarColor">
android:orientation="horizontal">
<TextView
android:text="@string/v_1_0_beta"
android:id="@+id/tvAppVersion_brain_key_activity"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:gravity="center"/>
android:gravity="center"
android:text="@string/v_1_0_beta" />
<TextView
android:layout_width="0dp"
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"/>
android:text="@string/block_number" />
<ImageView
android:id="@+id/ivSocketConnected_brain_key_activity"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="0.5"
android:layout_gravity="center"/>
<ImageView android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="0.5"
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"
/>
android:visibility="invisible" />
</LinearLayout>
</LinearLayout>

View file

@ -1,5 +1,5 @@
<resources>
<string name="app_name" translatable="false">Smartcoins Wallet</string>
<string name="app_name" translatable="false">Crystal Wallet</string>
<string name="dialog_positive">Ok</string>
<string name="send_capital">Send</string>
<string name="send_success">Success!</string>