Merge remote-tracking branch 'origin/master'

This commit is contained in:
henry 2017-10-02 22:49:30 -04:00
commit 6a92826837
9 changed files with 204 additions and 257 deletions

View file

@ -1,247 +0,0 @@
{
"formatVersion": 1,
"database": {
"version": 2,
"identityHash": "e8e3aa452878e49fb9c7cfa99f356e4e",
"entities": [
{
"tableName": "account_seed",
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, `name` TEXT, `master_seed` TEXT)",
"fields": [
{
"fieldPath": "mId",
"columnName": "id",
"affinity": "INTEGER",
"notNull": true
},
{
"fieldPath": "mName",
"columnName": "name",
"affinity": "TEXT",
"notNull": false
},
{
"fieldPath": "mMasterSeed",
"columnName": "master_seed",
"affinity": "TEXT",
"notNull": false
}
],
"primaryKey": {
"columnNames": [
"id"
],
"autoGenerate": true
},
"indices": [],
"foreignKeys": []
},
{
"tableName": "crypto_net_account",
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, `seed_id` INTEGER NOT NULL, `account_number` INTEGER NOT NULL, `account_index` INTEGER NOT NULL, FOREIGN KEY(`seed_id`) REFERENCES `account_seed`(`id`) ON UPDATE NO ACTION ON DELETE NO ACTION )",
"fields": [
{
"fieldPath": "mId",
"columnName": "id",
"affinity": "INTEGER",
"notNull": true
},
{
"fieldPath": "mSeedId",
"columnName": "seed_id",
"affinity": "INTEGER",
"notNull": true
},
{
"fieldPath": "mAccountNumber",
"columnName": "account_number",
"affinity": "INTEGER",
"notNull": true
},
{
"fieldPath": "mAccountIndex",
"columnName": "account_index",
"affinity": "INTEGER",
"notNull": true
}
],
"primaryKey": {
"columnNames": [
"id"
],
"autoGenerate": true
},
"indices": [
{
"name": "index_crypto_net_account_id",
"unique": false,
"columnNames": [
"id"
],
"createSql": "CREATE INDEX `index_crypto_net_account_id` ON `${TABLE_NAME}` (`id`)"
},
{
"name": "index_crypto_net_account_seed_id",
"unique": false,
"columnNames": [
"seed_id"
],
"createSql": "CREATE INDEX `index_crypto_net_account_seed_id` ON `${TABLE_NAME}` (`seed_id`)"
}
],
"foreignKeys": [
{
"table": "account_seed",
"onDelete": "NO ACTION",
"onUpdate": "NO ACTION",
"columns": [
"seed_id"
],
"referencedColumns": [
"id"
]
}
]
},
{
"tableName": "crypto_coin_transaction",
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`account` INTEGER, `id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, `date` INTEGER, `is_input` INTEGER NOT NULL, `account_id` INTEGER NOT NULL, `amount` INTEGER NOT NULL, `id_currency` INTEGER NOT NULL, `is_confirmed` INTEGER NOT NULL, `from` TEXT, `to` TEXT, FOREIGN KEY(`account_id`) REFERENCES `crypto_net_account`(`id`) ON UPDATE NO ACTION ON DELETE CASCADE , FOREIGN KEY(`id_currency`) REFERENCES `crypto_currency`(`id`) ON UPDATE NO ACTION ON DELETE CASCADE )",
"fields": [
{
"fieldPath": "account",
"columnName": "account",
"affinity": "INTEGER",
"notNull": false
},
{
"fieldPath": "id",
"columnName": "id",
"affinity": "INTEGER",
"notNull": true
},
{
"fieldPath": "date",
"columnName": "date",
"affinity": "INTEGER",
"notNull": false
},
{
"fieldPath": "isInput",
"columnName": "is_input",
"affinity": "INTEGER",
"notNull": true
},
{
"fieldPath": "accountId",
"columnName": "account_id",
"affinity": "INTEGER",
"notNull": true
},
{
"fieldPath": "amount",
"columnName": "amount",
"affinity": "INTEGER",
"notNull": true
},
{
"fieldPath": "idCurrency",
"columnName": "id_currency",
"affinity": "INTEGER",
"notNull": true
},
{
"fieldPath": "isConfirmed",
"columnName": "is_confirmed",
"affinity": "INTEGER",
"notNull": true
},
{
"fieldPath": "from",
"columnName": "from",
"affinity": "TEXT",
"notNull": false
},
{
"fieldPath": "to",
"columnName": "to",
"affinity": "TEXT",
"notNull": false
}
],
"primaryKey": {
"columnNames": [
"id"
],
"autoGenerate": true
},
"indices": [],
"foreignKeys": [
{
"table": "crypto_net_account",
"onDelete": "CASCADE",
"onUpdate": "NO ACTION",
"columns": [
"account_id"
],
"referencedColumns": [
"id"
]
},
{
"table": "crypto_currency",
"onDelete": "CASCADE",
"onUpdate": "NO ACTION",
"columns": [
"id_currency"
],
"referencedColumns": [
"id"
]
}
]
},
{
"tableName": "crypto_currency",
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, `name` TEXT, `crypto_net` TEXT, `precision` INTEGER NOT NULL)",
"fields": [
{
"fieldPath": "mId",
"columnName": "id",
"affinity": "INTEGER",
"notNull": true
},
{
"fieldPath": "mName",
"columnName": "name",
"affinity": "TEXT",
"notNull": false
},
{
"fieldPath": "mCryptoNet",
"columnName": "crypto_net",
"affinity": "TEXT",
"notNull": false
},
{
"fieldPath": "mPrecision",
"columnName": "precision",
"affinity": "INTEGER",
"notNull": true
}
],
"primaryKey": {
"columnNames": [
"id"
],
"autoGenerate": true
},
"indices": [],
"foreignKeys": []
}
],
"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, \"e8e3aa452878e49fb9c7cfa99f356e4e\")"
]
}
}

View file

@ -5,6 +5,7 @@ import android.arch.lifecycle.ViewModelProviders;
import android.content.Intent; import android.content.Intent;
import android.os.Bundle; import android.os.Bundle;
import android.support.v7.app.AppCompatActivity; import android.support.v7.app.AppCompatActivity;
import android.text.Editable;
import android.widget.Button; import android.widget.Button;
import android.widget.EditText; import android.widget.EditText;
import android.widget.TextView; import android.widget.TextView;
@ -14,16 +15,20 @@ import java.util.List;
import butterknife.BindView; import butterknife.BindView;
import butterknife.ButterKnife; import butterknife.ButterKnife;
import butterknife.OnClick; import butterknife.OnClick;
import butterknife.OnTextChanged;
import cy.agorise.crystalwallet.R; import cy.agorise.crystalwallet.R;
import cy.agorise.crystalwallet.models.AccountSeed; import cy.agorise.crystalwallet.models.AccountSeed;
import cy.agorise.crystalwallet.viewmodels.AccountSeedListViewModel; import cy.agorise.crystalwallet.viewmodels.AccountSeedListViewModel;
import cy.agorise.crystalwallet.viewmodels.AccountSeedViewModel; 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.ImportSeedValidatorListener;
import cy.agorise.crystalwallet.views.TransactionListView; import cy.agorise.crystalwallet.views.TransactionListView;
public class ImportSeedActivity extends AppCompatActivity { public class ImportSeedActivity extends AppCompatActivity implements ImportSeedValidatorListener {
AccountSeedViewModel accountSeedViewModel; AccountSeedViewModel accountSeedViewModel;
ImportSeedValidator importSeedValidator;
@BindView(R.id.tvPin) @BindView(R.id.tvPin)
TextView tvPin; TextView tvPin;
@ -48,11 +53,20 @@ public class ImportSeedActivity extends AppCompatActivity {
ButterKnife.bind(this); ButterKnife.bind(this);
accountSeedViewModel = ViewModelProviders.of(this).get(AccountSeedViewModel.class); accountSeedViewModel = ViewModelProviders.of(this).get(AccountSeedViewModel.class);
//this.seed = new AccountSeed(); importSeedValidator = accountSeedViewModel.getValidator();
importSeedValidator.setListener(this);
}
@OnTextChanged(value = R.id.etAccountName,
callback = OnTextChanged.Callback.AFTER_TEXT_CHANGED)
void afterAccountNameChanged(Editable editable) {
this.validator.validateAccountName(editable.getT);
} }
@OnClick(R.id.btnImport) @OnClick(R.id.btnImport)
public void importSeed(){ public void importSeed(){
if (this.validator)
AccountSeed seed = new AccountSeed(); AccountSeed seed = new AccountSeed();
//TODO verify if PIN and PIN confirmation are not null and are the same //TODO verify if PIN and PIN confirmation are not null and are the same
@ -63,4 +77,14 @@ public class ImportSeedActivity extends AppCompatActivity {
accountSeedViewModel.addSeed(seed); accountSeedViewModel.addSeed(seed);
} }
@Override
public void onValidationSucceeded() {
//Clear all errors
}
@Override
public void onValidationFailed(String error) {
//Show errors
}
} }

View file

@ -4,7 +4,7 @@ package cy.agorise.crystalwallet.cryptonetinforequests;
* Created by Henry Varona on 1/10/2017. * Created by Henry Varona on 1/10/2017.
*/ */
interface CryptoNetInfoRequestListener { public interface CryptoNetInfoRequestListener {
public void onCarryOut(); public void onCarryOut();
} }

View file

@ -10,20 +10,20 @@ import java.util.List;
public class CryptoNetInfoRequests { public class CryptoNetInfoRequests {
private List<CryptoNetInfoRequest> requests; private List<CryptoNetInfoRequest> requests;
private List<CryptoNetInfoRequestsListener> listeners; private List<CryptoNetInfoRequestsListener> listeners;
private CryptoNetInfoRequests instance; private static CryptoNetInfoRequests instance;
private void CryptoNetInfoRequests(){ private void CryptoNetInfoRequests(){
//Private constructor for singleton pattern //Private constructor for singleton pattern
} }
public CryptoNetInfoRequests getInstance(){ public static CryptoNetInfoRequests getInstance(){
if (this.instance == null){ if (CryptoNetInfoRequests.instance == null){
this.instance = new CryptoNetInfoRequests(); CryptoNetInfoRequests.instance = new CryptoNetInfoRequests();
this.requests = new ArrayList<CryptoNetInfoRequest>(); CryptoNetInfoRequests.instance.requests = new ArrayList<CryptoNetInfoRequest>();
this.listeners = new ArrayList<CryptoNetInfoRequestsListener>(); CryptoNetInfoRequests.instance.listeners = new ArrayList<CryptoNetInfoRequestsListener>();
} }
return this.instance; return CryptoNetInfoRequests.instance;
} }
public void addRequest(CryptoNetInfoRequest request){ public void addRequest(CryptoNetInfoRequest request){

View file

@ -22,10 +22,12 @@ public class ValidateImportBitsharesAccountRequest extends CryptoNetInfoRequest
public void setAccountExists(boolean value){ public void setAccountExists(boolean value){
this.accountExists = value; this.accountExists = value;
this.validate();
} }
public void setMnemonicIsCorrect(boolean value){ public void setMnemonicIsCorrect(boolean value){
this.mnemonicIsCorrect = value; this.mnemonicIsCorrect = value;
this.validate();
} }
public boolean getAccountExists(){ public boolean getAccountExists(){

View file

@ -7,8 +7,11 @@ import android.arch.lifecycle.MutableLiveData;
import java.util.List; import java.util.List;
import cy.agorise.crystalwallet.cryptonetinforequests.CryptoNetInfoRequestListener;
import cy.agorise.crystalwallet.dao.CrystalDatabase; import cy.agorise.crystalwallet.dao.CrystalDatabase;
import cy.agorise.crystalwallet.models.AccountSeed; import cy.agorise.crystalwallet.models.AccountSeed;
import cy.agorise.crystalwallet.cryptonetinforequests.ValidateImportBitsharesAccountRequest;
import cy.agorise.crystalwallet.viewmodels.validators.ImportSeedValidator;
/** /**
* Created by Henry Varona on 27/9/2017. * Created by Henry Varona on 27/9/2017.
@ -18,6 +21,7 @@ public class AccountSeedViewModel extends AndroidViewModel {
private LiveData<AccountSeed> accountSeed; private LiveData<AccountSeed> accountSeed;
private CrystalDatabase db; private CrystalDatabase db;
private MutableLiveData<ImportSeedValidator> importSeedValidator;
public AccountSeedViewModel(Application application) { public AccountSeedViewModel(Application application) {
super(application); super(application);
@ -28,6 +32,13 @@ public class AccountSeedViewModel extends AndroidViewModel {
this.accountSeed = this.db.accountSeedDao().findById(seedId); this.accountSeed = this.db.accountSeedDao().findById(seedId);
} }
public ImportSeedValidator getValidator(){
if (this.importSeedValidator == null){
this.importSeedValidator = new ImportSeedValidator();
}
}
public void addSeed(AccountSeed seed){ public void addSeed(AccountSeed seed){
this.db.accountSeedDao().insertAccountSeed(seed); this.db.accountSeedDao().insertAccountSeed(seed);
} }
@ -35,4 +46,18 @@ public class AccountSeedViewModel extends AndroidViewModel {
public LiveData<AccountSeed> getAccountSeed(){ public LiveData<AccountSeed> getAccountSeed(){
return this.accountSeed; return this.accountSeed;
} }
public void validateAccountSeed(){
if (this.accountSeed != null){
AccountSeed seed = this.accountSeed.getValue();
ValidateImportBitsharesAccountRequest request = new ValidateImportBitsharesAccountRequest(seed.getName(),seed.getMasterSeed());
request.setListener(new CryptoNetInfoRequestListener() {
@Override
public void onCarryOut() {
}
});
}
}
} }

View file

@ -0,0 +1,78 @@
package cy.agorise.crystalwallet.viewmodels.validators;
import android.accounts.Account;
import java.util.ArrayList;
import java.util.List;
import cy.agorise.crystalwallet.R;
import cy.agorise.crystalwallet.cryptonetinforequests.CryptoNetInfoRequestListener;
import cy.agorise.crystalwallet.cryptonetinforequests.CryptoNetInfoRequests;
import cy.agorise.crystalwallet.cryptonetinforequests.ValidateImportBitsharesAccountRequest;
import cy.agorise.crystalwallet.models.AccountSeed;
/**
* Created by Henry Varona on 2/10/2017.
*/
public class ImportSeedValidator {
private ImportSeedValidatorListener listener;
private List<ValidationField> validationFields;
private AccountSeed accountSeed;
private boolean isValid = false;
public ImportSeedValidator(AccountSeed seed){
this.accountSeed = seed;
this.validationFields = new ArrayList<ValidationField>();
//this.validationFields.add(new ValidationField("pin"));
//this.validationFields.add(new ValidationField("pinConfirmation"));
this.validationFields.add(new ValidationField("accountname"));
}
public void setListener(ImportSeedValidatorListener listener){
this.listener = listener;
}
public void validate(){
//validatePin();
//validatePinConfirmation();
validateAccountName();
}
public ValidationField getValidationField(String name){
for (int i=0;i<this.validationFields.size();i++){
if (this.validationFields.get(i).getName().equals(name)){
return this.validationFields.get(i);
}
}
return null;
}
//public validatePin(){
//}
public void validateAccountName(String accountName){
final ValidationField validationField = getValidationField("accountname");
if (this.accountSeed != null){
final ValidateImportBitsharesAccountRequest request = new ValidateImportBitsharesAccountRequest(this.accountSeed.getName(),this.accountSeed.getMasterSeed());
request.setListener(new CryptoNetInfoRequestListener() {
@Override
public void onCarryOut() {
if (!request.getAccountExists()){
validationField.setValid(false);
validationField.setMessage(R.string.account_name_not_exist);
} else {
validationField.setValid(true);
}
}
});
CryptoNetInfoRequests.getInstance().addRequest(request);
}
}
}

View file

@ -0,0 +1,11 @@
package cy.agorise.crystalwallet.viewmodels.validators;
/**
* Created by Henry Varona on 2/10/2017.
*/
public interface ImportSeedValidatorListener {
public void onValidationSucceeded();
public void onValidationFailed(String error);
}

View file

@ -0,0 +1,54 @@
package cy.agorise.crystalwallet.viewmodels.validators;
/**
* Created by Henry Varona on 2/10/2017.
*/
public class ValidationField {
public String name;
public String lastValue;
public String message;
public boolean validating;
public boolean valid;
public ValidationField(String name){
this.name = name;
this.lastValue = "";
this.message = "";
this.validating = false;
this.valid = false;
}
public String getName(){
return this.name;
}
public void startValidating(){
this.validating = true;
}
public void stopValidating(){
this.validating = false;
}
public void setValid(boolean newValue){
this.valid = newValue;
}
public void setMessage(String newValue){
this.message = newValue;
}
public String getMessage(){
return this.message;
}
public boolean getValidating(){
return this.validating;
}
public boolean getValid(){
return this.valid;
}
}