- Added email field to contacts (to load the gravatar)

This commit is contained in:
Javier Varona 2018-02-21 21:57:59 -04:00
parent e3a20eabaa
commit a131037fd1
7 changed files with 121 additions and 8 deletions

View file

@ -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\")"
]
}
}

View file

@ -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<List<ContactAddress>> 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<ContactAddress>();
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());
}
}
});

View file

@ -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();
}

View file

@ -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));
}
}

View file

@ -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));
}
}

View file

@ -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);
}
}
}

View file

@ -36,7 +36,32 @@
android:layout_marginRight="@dimen/activity_horizontal_margin"
android:maxLines="1"
android:textColor="@color/red" />
<TextView
android:id="@+id/tvEmail"
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="Email"
android:textStyle="bold" />
<EditText
android:id="@+id/etEmail"
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:maxLines="1"
android:textColor="@color/black" />
<TextView
android:id="@+id/tvEmailError"
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:maxLines="1"
android:textColor="@color/red" />
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">