- Adding TextView under EditText to display errors

master
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' exclude group: 'com.android.support', module: 'support-annotations'
}) })
compile 'com.android.support:appcompat-v7:26.1.0' 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' compile 'com.android.support.constraint:constraint-layout:1.0.2'
testCompile 'junit:junit:4.12' testCompile 'junit:junit:4.12'
testCompile 'org.mockito:mockito-core:1.10.19' testCompile 'org.mockito:mockito-core:1.10.19'

View File

@ -9,7 +9,7 @@
android:label="@string/app_name" android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round" android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true" android:supportsRtl="true"
android:theme="@style/AppTheme"> android:theme="@style/Theme.AppCompat">
<activity android:name=".activities.IntroActivity"> <activity android:name=".activities.IntroActivity">
<intent-filter> <intent-filter>
<action android:name="android.intent.action.MAIN" /> <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.TransactionListViewModel;
import cy.agorise.crystalwallet.viewmodels.validators.ImportSeedValidator; import cy.agorise.crystalwallet.viewmodels.validators.ImportSeedValidator;
import cy.agorise.crystalwallet.viewmodels.validators.ImportSeedValidatorListener; import cy.agorise.crystalwallet.viewmodels.validators.ImportSeedValidatorListener;
import cy.agorise.crystalwallet.viewmodels.validators.ValidationField;
import cy.agorise.crystalwallet.views.TransactionListView; import cy.agorise.crystalwallet.views.TransactionListView;
public class ImportSeedActivity extends AppCompatActivity implements ImportSeedValidatorListener { public class ImportSeedActivity extends AppCompatActivity implements ImportSeedValidatorListener {
@ -31,17 +32,23 @@ public class ImportSeedActivity extends AppCompatActivity implements ImportSeedV
AccountSeedViewModel accountSeedViewModel; AccountSeedViewModel accountSeedViewModel;
ImportSeedValidator importSeedValidator; ImportSeedValidator importSeedValidator;
@BindView(R.id.tvPin) @BindView(R.id.etPin)
TextView tvPin; EditText etPin;
@BindView(R.id.tvPinError)
TextView tvPinError;
@BindView(R.id.tvPinConfirmation) @BindView(R.id.etPinConfirmation)
TextView tvPinConfirmation; EditText etPinConfirmation;
@BindView(R.id.tvPinConfirmationError)
TextView tvPinConfirmationError;
@BindView(R.id.etSeedWords) @BindView(R.id.etSeedWords)
EditText etSeedWords; EditText etSeedWords;
@BindView (R.id.etAccountName) @BindView (R.id.etAccountName)
EditText etAccountName; EditText etAccountName;
@BindView(R.id.tvAccountNameError)
TextView tvAccountNameError;
@BindView(R.id.btnImport) @BindView(R.id.btnImport)
Button btnImport; Button btnImport;
@ -59,6 +66,19 @@ public class ImportSeedActivity extends AppCompatActivity implements ImportSeedV
importSeedValidator.setListener(this); 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, @OnTextChanged(value = R.id.etAccountName,
callback = OnTextChanged.Callback.AFTER_TEXT_CHANGED) callback = OnTextChanged.Callback.AFTER_TEXT_CHANGED)
void afterAccountNameChanged(Editable editable) { void afterAccountNameChanged(Editable editable) {
@ -82,14 +102,32 @@ public class ImportSeedActivity extends AppCompatActivity implements ImportSeedV
} }
@Override @Override
public void onValidationSucceeded() { public void onValidationSucceeded(ValidationField field) {
//Clear all errors switch (field.getName()){
case "pin":
tvPinError.setText("");
break;
case "pinconfirmation":
tvPinConfirmationError.setText("");
break;
case "accountname":
tvAccountNameError.setText("");
break;
}
} }
@Override @Override
public void onValidationFailed(String error) { public void onValidationFailed(ValidationField field) {
//Show errors switch (field.getName()){
Toast.makeText(this, error, case "pin":
Toast.LENGTH_LONG).show(); 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){ public ImportSeedValidator(Resources res){
this.res = res; this.res = res;
this.validationFields = new ArrayList<ValidationField>(); this.validationFields = new ArrayList<ValidationField>();
//this.validationFields.add(new ValidationField("pin")); this.validationFields.add(new ValidationField("pin"));
//this.validationFields.add(new ValidationField("pinConfirmation")); this.validationFields.add(new ValidationField("pinconfirmation"));
this.validationFields.add(new ValidationField("accountname")); this.validationFields.add(new ValidationField("accountname"));
} }
@ -59,9 +59,33 @@ public class ImportSeedValidator {
return null; 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){ public void validateAccountName(final String accountName, final String mnemonic){
final ValidationField validationField = getValidationField("accountname"); final ValidationField validationField = getValidationField("accountname");
@ -74,8 +98,10 @@ public class ImportSeedValidator {
if (!request.getAccountExists()){ if (!request.getAccountExists()){
validationField.setValidForValue(accountName, false); validationField.setValidForValue(accountName, false);
validationField.setMessage(res.getString(R.string.account_name_not_exist)); validationField.setMessage(res.getString(R.string.account_name_not_exist));
listener.onValidationFailed(validationField);
} else { } else {
validationField.setValidForValue(accountName, true); validationField.setValidForValue(accountName, true);
listener.onValidationSucceeded(validationField);
} }
} }
}); });

View File

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

View File

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

View File

@ -1,5 +1,5 @@
<resources> <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="dialog_positive">Ok</string>
<string name="send_capital">Send</string> <string name="send_capital">Send</string>
<string name="send_success">Success!</string> <string name="send_success">Success!</string>