- 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, "formatVersion": 1,
"database": { "database": {
"version": 2, "version": 2,
"identityHash": "6f4a0d464f042d577c584ed532bffd2c", "identityHash": "3ec53bc71906b5abcabeaefcd7505bc1",
"entities": [ "entities": [
{ {
"tableName": "account_seed", "tableName": "account_seed",
@ -235,7 +235,7 @@
}, },
{ {
"tableName": "contact", "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": [ "fields": [
{ {
"fieldPath": "mId", "fieldPath": "mId",
@ -249,6 +249,12 @@
"affinity": "TEXT", "affinity": "TEXT",
"notNull": false "notNull": false
}, },
{
"fieldPath": "mEmail",
"columnName": "email",
"affinity": "TEXT",
"notNull": false
},
{ {
"fieldPath": "mGravatar", "fieldPath": "mGravatar",
"columnName": "gravatar", "columnName": "gravatar",
@ -678,7 +684,7 @@
], ],
"setupQueries": [ "setupQueries": [
"CREATE TABLE IF NOT EXISTS room_master_table (id INTEGER PRIMARY KEY,identity_hash TEXT)", "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; EditText etName;
@BindView(R.id.tvNameError) @BindView(R.id.tvNameError)
TextView tvNameError; TextView tvNameError;
@BindView(R.id.etEmail)
EditText etEmail;
@BindView(R.id.tvEmailError)
TextView tvEmailError;
@BindView(R.id.btnCancel) @BindView(R.id.btnCancel)
Button btnCancel; Button btnCancel;
@BindView(R.id.btnCreate) @BindView(R.id.btnCreate)
@ -96,6 +100,7 @@ public class CreateContactActivity extends AppCompatActivity implements UIValida
if (contactChanged != null){ if (contactChanged != null){
contact = contactChanged; contact = contactChanged;
etName.setText(contact.getName()); etName.setText(contact.getName());
etEmail.setText(contact.getEmail());
LiveData<List<ContactAddress>> contactAddresses = contactViewModel.getContactAddresses(); 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); modifyContactValidator.setListener(thisActivity);
btnModify.setVisibility(View.VISIBLE); btnModify.setVisibility(View.VISIBLE);
} else { } else {
@ -120,7 +125,7 @@ public class CreateContactActivity extends AppCompatActivity implements UIValida
} else { } else {
contactAddressList = new ArrayList<ContactAddress>(); contactAddressList = new ArrayList<ContactAddress>();
listAdapter.setList(contactAddressList); listAdapter.setList(contactAddressList);
createContactValidator = new CreateContactValidator(this.getApplicationContext(),etName); createContactValidator = new CreateContactValidator(this.getApplicationContext(),etName,etEmail);
createContactValidator.setListener(this); createContactValidator.setListener(this);
btnCreate.setVisibility(View.VISIBLE); btnCreate.setVisibility(View.VISIBLE);
@ -151,6 +156,13 @@ public class CreateContactActivity extends AppCompatActivity implements UIValida
this.validate(); this.validate();
} }
@OnTextChanged(value = R.id.etEmail,
callback = OnTextChanged.Callback.AFTER_TEXT_CHANGED)
void afterEmailChanged(Editable editable) {
this.validate();
}
@OnClick(R.id.btnAddAddress) @OnClick(R.id.btnAddAddress)
public void addAddress(){ public void addAddress(){
ContactAddress newContactAddress = new ContactAddress(); ContactAddress newContactAddress = new ContactAddress();
@ -167,6 +179,7 @@ public class CreateContactActivity extends AppCompatActivity implements UIValida
public void modifyContact(){ public void modifyContact(){
if (this.modifyContactValidator.isValid()) { if (this.modifyContactValidator.isValid()) {
this.contact.setName(etName.getText().toString()); this.contact.setName(etName.getText().toString());
this.contact.setEmail(etEmail.getText().toString());
this.contact.clearAddresses(); this.contact.clearAddresses();
for (ContactAddress contactAddress : contactAddressList){ for (ContactAddress contactAddress : contactAddressList){
@ -187,6 +200,7 @@ public class CreateContactActivity extends AppCompatActivity implements UIValida
if (this.createContactValidator.isValid()) { if (this.createContactValidator.isValid()) {
Contact newContact = new Contact(); Contact newContact = new Contact();
newContact.setName(etName.getText().toString()); newContact.setName(etName.getText().toString());
newContact.setEmail(etEmail.getText().toString());
for (ContactAddress contactAddress : contactAddressList){ for (ContactAddress contactAddress : contactAddressList){
newContact.addAddress(contactAddress); newContact.addAddress(contactAddress);
@ -210,6 +224,8 @@ public class CreateContactActivity extends AppCompatActivity implements UIValida
if (field.getView() == etName) { if (field.getView() == etName) {
tvNameError.setText(""); tvNameError.setText("");
} else if (field.getView() == etEmail) {
tvEmailError.setText("");
} }
if (activity.isValid()){ if (activity.isValid()){
@ -229,6 +245,8 @@ public class CreateContactActivity extends AppCompatActivity implements UIValida
public void run() { public void run() {
if (field.getView() == etName) { if (field.getView() == etName) {
tvNameError.setText(field.getMessage()); 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") @ColumnInfo(name="name")
private String mName; private String mName;
@ColumnInfo(name="email")
private String mEmail;
@ColumnInfo(name = "gravatar") @ColumnInfo(name = "gravatar")
private String mGravatar; private String mGravatar;
@ -65,6 +68,14 @@ public class Contact {
this.mGravatar = gravatar; this.mGravatar = gravatar;
} }
public String getEmail() {
return mEmail;
}
public void setEmail(String email) {
this.mEmail = email;
}
public int addressesCount(){ public int addressesCount(){
return this.mAddresses.size(); 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.BitsharesAccountNameDoesntExistsValidationField;
import cy.agorise.crystalwallet.viewmodels.validators.validationfields.ContactNameValidationField; 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.PinConfirmationValidationField;
import cy.agorise.crystalwallet.viewmodels.validators.validationfields.PinValidationField; 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 class CreateContactValidator extends UIValidator {
public CreateContactValidator(Context context, EditText nameEdit){ public CreateContactValidator(Context context, EditText nameEdit, EditText emailEdit){
super(context); super(context);
this.addField(new ContactNameValidationField(nameEdit)); 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.models.Contact;
import cy.agorise.crystalwallet.viewmodels.validators.validationfields.ContactNameValidationField; import cy.agorise.crystalwallet.viewmodels.validators.validationfields.ContactNameValidationField;
import cy.agorise.crystalwallet.viewmodels.validators.validationfields.EmailValidationField;
/** /**
* Created by Henry Varona on 2/11/2018. * 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 class ModifyContactValidator extends UIValidator {
public ModifyContactValidator(Context context, Contact contact, EditText nameEdit){ public ModifyContactValidator(Context context, Contact contact, EditText nameEdit, EditText emailEdit){
super(context); super(context);
this.addField(new ContactNameValidationField(nameEdit, contact)); 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:layout_marginRight="@dimen/activity_horizontal_margin"
android:maxLines="1" android:maxLines="1"
android:textColor="@color/red" /> 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 <RelativeLayout
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content"> android:layout_height="wrap_content">