diff --git a/app/schemas/cy.agorise.crystalwallet.dao.CrystalDatabase/2.json b/app/schemas/cy.agorise.crystalwallet.dao.CrystalDatabase/2.json index 01dada3..3153165 100644 --- a/app/schemas/cy.agorise.crystalwallet.dao.CrystalDatabase/2.json +++ b/app/schemas/cy.agorise.crystalwallet.dao.CrystalDatabase/2.json @@ -2,7 +2,7 @@ "formatVersion": 1, "database": { "version": 2, - "identityHash": "6f4a0d464f042d577c584ed532bffd2c", + "identityHash": "3ec53bc71906b5abcabeaefcd7505bc1", "entities": [ { "tableName": "account_seed", @@ -235,7 +235,7 @@ }, { "tableName": "contact", - "createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, `name` TEXT, `gravatar` TEXT)", + "createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, `name` TEXT, `email` TEXT, `gravatar` TEXT)", "fields": [ { "fieldPath": "mId", @@ -249,6 +249,12 @@ "affinity": "TEXT", "notNull": false }, + { + "fieldPath": "mEmail", + "columnName": "email", + "affinity": "TEXT", + "notNull": false + }, { "fieldPath": "mGravatar", "columnName": "gravatar", @@ -678,7 +684,7 @@ ], "setupQueries": [ "CREATE TABLE IF NOT EXISTS room_master_table (id INTEGER PRIMARY KEY,identity_hash TEXT)", - "INSERT OR REPLACE INTO room_master_table (id,identity_hash) VALUES(42, \"6f4a0d464f042d577c584ed532bffd2c\")" + "INSERT OR REPLACE INTO room_master_table (id,identity_hash) VALUES(42, \"3ec53bc71906b5abcabeaefcd7505bc1\")" ] } } \ No newline at end of file diff --git a/app/src/main/java/cy/agorise/crystalwallet/activities/CreateContactActivity.java b/app/src/main/java/cy/agorise/crystalwallet/activities/CreateContactActivity.java index 41c6d00..fcb1469 100644 --- a/app/src/main/java/cy/agorise/crystalwallet/activities/CreateContactActivity.java +++ b/app/src/main/java/cy/agorise/crystalwallet/activities/CreateContactActivity.java @@ -48,6 +48,10 @@ public class CreateContactActivity extends AppCompatActivity implements UIValida EditText etName; @BindView(R.id.tvNameError) TextView tvNameError; + @BindView(R.id.etEmail) + EditText etEmail; + @BindView(R.id.tvEmailError) + TextView tvEmailError; @BindView(R.id.btnCancel) Button btnCancel; @BindView(R.id.btnCreate) @@ -96,6 +100,7 @@ public class CreateContactActivity extends AppCompatActivity implements UIValida if (contactChanged != null){ contact = contactChanged; etName.setText(contact.getName()); + etEmail.setText(contact.getEmail()); LiveData> contactAddresses = contactViewModel.getContactAddresses(); @@ -108,7 +113,7 @@ public class CreateContactActivity extends AppCompatActivity implements UIValida } }); - modifyContactValidator = new ModifyContactValidator(thisActivity.getApplicationContext(),contact,etName); + modifyContactValidator = new ModifyContactValidator(thisActivity.getApplicationContext(),contact,etName,etEmail); modifyContactValidator.setListener(thisActivity); btnModify.setVisibility(View.VISIBLE); } else { @@ -120,7 +125,7 @@ public class CreateContactActivity extends AppCompatActivity implements UIValida } else { contactAddressList = new ArrayList(); listAdapter.setList(contactAddressList); - createContactValidator = new CreateContactValidator(this.getApplicationContext(),etName); + createContactValidator = new CreateContactValidator(this.getApplicationContext(),etName,etEmail); createContactValidator.setListener(this); btnCreate.setVisibility(View.VISIBLE); @@ -151,6 +156,13 @@ public class CreateContactActivity extends AppCompatActivity implements UIValida this.validate(); } + @OnTextChanged(value = R.id.etEmail, + callback = OnTextChanged.Callback.AFTER_TEXT_CHANGED) + void afterEmailChanged(Editable editable) { + this.validate(); + } + + @OnClick(R.id.btnAddAddress) public void addAddress(){ ContactAddress newContactAddress = new ContactAddress(); @@ -167,6 +179,7 @@ public class CreateContactActivity extends AppCompatActivity implements UIValida public void modifyContact(){ if (this.modifyContactValidator.isValid()) { this.contact.setName(etName.getText().toString()); + this.contact.setEmail(etEmail.getText().toString()); this.contact.clearAddresses(); for (ContactAddress contactAddress : contactAddressList){ @@ -187,6 +200,7 @@ public class CreateContactActivity extends AppCompatActivity implements UIValida if (this.createContactValidator.isValid()) { Contact newContact = new Contact(); newContact.setName(etName.getText().toString()); + newContact.setEmail(etEmail.getText().toString()); for (ContactAddress contactAddress : contactAddressList){ newContact.addAddress(contactAddress); @@ -210,6 +224,8 @@ public class CreateContactActivity extends AppCompatActivity implements UIValida if (field.getView() == etName) { tvNameError.setText(""); + } else if (field.getView() == etEmail) { + tvEmailError.setText(""); } if (activity.isValid()){ @@ -229,6 +245,8 @@ public class CreateContactActivity extends AppCompatActivity implements UIValida public void run() { if (field.getView() == etName) { tvNameError.setText(field.getMessage()); + } else if (field.getView() == etEmail) { + tvEmailError.setText(field.getMessage()); } } }); diff --git a/app/src/main/java/cy/agorise/crystalwallet/models/Contact.java b/app/src/main/java/cy/agorise/crystalwallet/models/Contact.java index 3d45464..7700227 100644 --- a/app/src/main/java/cy/agorise/crystalwallet/models/Contact.java +++ b/app/src/main/java/cy/agorise/crystalwallet/models/Contact.java @@ -35,6 +35,9 @@ public class Contact { @ColumnInfo(name="name") private String mName; + @ColumnInfo(name="email") + private String mEmail; + @ColumnInfo(name = "gravatar") private String mGravatar; @@ -65,6 +68,14 @@ public class Contact { this.mGravatar = gravatar; } + public String getEmail() { + return mEmail; + } + + public void setEmail(String email) { + this.mEmail = email; + } + public int addressesCount(){ return this.mAddresses.size(); } diff --git a/app/src/main/java/cy/agorise/crystalwallet/viewmodels/validators/CreateContactValidator.java b/app/src/main/java/cy/agorise/crystalwallet/viewmodels/validators/CreateContactValidator.java index 34e43ae..1b84e43 100644 --- a/app/src/main/java/cy/agorise/crystalwallet/viewmodels/validators/CreateContactValidator.java +++ b/app/src/main/java/cy/agorise/crystalwallet/viewmodels/validators/CreateContactValidator.java @@ -5,6 +5,7 @@ import android.widget.EditText; import cy.agorise.crystalwallet.viewmodels.validators.validationfields.BitsharesAccountNameDoesntExistsValidationField; import cy.agorise.crystalwallet.viewmodels.validators.validationfields.ContactNameValidationField; +import cy.agorise.crystalwallet.viewmodels.validators.validationfields.EmailValidationField; import cy.agorise.crystalwallet.viewmodels.validators.validationfields.PinConfirmationValidationField; import cy.agorise.crystalwallet.viewmodels.validators.validationfields.PinValidationField; @@ -14,8 +15,9 @@ import cy.agorise.crystalwallet.viewmodels.validators.validationfields.PinValida public class CreateContactValidator extends UIValidator { - public CreateContactValidator(Context context, EditText nameEdit){ + public CreateContactValidator(Context context, EditText nameEdit, EditText emailEdit){ super(context); this.addField(new ContactNameValidationField(nameEdit)); + this.addField(new EmailValidationField(emailEdit)); } } diff --git a/app/src/main/java/cy/agorise/crystalwallet/viewmodels/validators/ModifyContactValidator.java b/app/src/main/java/cy/agorise/crystalwallet/viewmodels/validators/ModifyContactValidator.java index 0140e8e..ec640fd 100644 --- a/app/src/main/java/cy/agorise/crystalwallet/viewmodels/validators/ModifyContactValidator.java +++ b/app/src/main/java/cy/agorise/crystalwallet/viewmodels/validators/ModifyContactValidator.java @@ -5,6 +5,7 @@ import android.widget.EditText; import cy.agorise.crystalwallet.models.Contact; import cy.agorise.crystalwallet.viewmodels.validators.validationfields.ContactNameValidationField; +import cy.agorise.crystalwallet.viewmodels.validators.validationfields.EmailValidationField; /** * Created by Henry Varona on 2/11/2018. @@ -12,8 +13,9 @@ import cy.agorise.crystalwallet.viewmodels.validators.validationfields.ContactNa public class ModifyContactValidator extends UIValidator { - public ModifyContactValidator(Context context, Contact contact, EditText nameEdit){ + public ModifyContactValidator(Context context, Contact contact, EditText nameEdit, EditText emailEdit){ super(context); this.addField(new ContactNameValidationField(nameEdit, contact)); + this.addField(new EmailValidationField(emailEdit)); } } diff --git a/app/src/main/java/cy/agorise/crystalwallet/viewmodels/validators/validationfields/EmailValidationField.java b/app/src/main/java/cy/agorise/crystalwallet/viewmodels/validators/validationfields/EmailValidationField.java new file mode 100644 index 0000000..05c4e51 --- /dev/null +++ b/app/src/main/java/cy/agorise/crystalwallet/viewmodels/validators/validationfields/EmailValidationField.java @@ -0,0 +1,49 @@ +package cy.agorise.crystalwallet.viewmodels.validators.validationfields; + +import android.widget.EditText; + +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +import cy.agorise.crystalwallet.R; + +/** + * Created by Henry Varona on 2/21/2017. + */ + +public class EmailValidationField extends ValidationField { + + private EditText emailField; + + public EmailValidationField(EditText emailField){ + super(emailField); + this.emailField = emailField; + } + + public void validate(){ + String newValue = emailField.getText().toString(); + if (!newValue.equals("")) { + + if (!newValue.equals(this.getLastValue())) { + this.setLastValue(newValue); + this.startValidating(); + + String expression = "^[\\w\\.-]+@([\\w\\-]+\\.)+[A-Z]{2,4}$"; + Pattern pattern = Pattern.compile(expression, Pattern.CASE_INSENSITIVE); + Matcher matcher = pattern.matcher(newValue); + + if (!matcher.matches()) { + this.setMessageForValue(newValue, "The email is not valid"); + this.setValidForValue(newValue, false); + } else { + this.setValidForValue(newValue, true); + } + } + } else { + this.setLastValue(""); + this.startValidating(); + this.setMessageForValue("", ""); + this.setValidForValue("", false); + } + } +} diff --git a/app/src/main/res/layout/activity_create_contact.xml b/app/src/main/res/layout/activity_create_contact.xml index f64d603..44df5aa 100644 --- a/app/src/main/res/layout/activity_create_contact.xml +++ b/app/src/main/res/layout/activity_create_contact.xml @@ -36,7 +36,32 @@ android:layout_marginRight="@dimen/activity_horizontal_margin" android:maxLines="1" android:textColor="@color/red" /> - + + +