diff --git a/app/src/main/java/cy/agorise/crystalwallet/dao/CrystalDatabase.java b/app/src/main/java/cy/agorise/crystalwallet/dao/CrystalDatabase.java index f43c374..18e261e 100644 --- a/app/src/main/java/cy/agorise/crystalwallet/dao/CrystalDatabase.java +++ b/app/src/main/java/cy/agorise/crystalwallet/dao/CrystalDatabase.java @@ -11,6 +11,7 @@ import android.content.Context; import cy.agorise.crystalwallet.dao.converters.Converters; import cy.agorise.crystalwallet.models.AccountSeed; import cy.agorise.crystalwallet.models.CryptoCoinTransaction; +import cy.agorise.crystalwallet.models.CryptoCurrency; import cy.agorise.crystalwallet.models.CryptoNetAccount; /** @@ -18,7 +19,7 @@ import cy.agorise.crystalwallet.models.CryptoNetAccount; * Created by Henry Varona on 4/9/2017. */ -@Database(entities = {AccountSeed.class, CryptoNetAccount.class, CryptoCoinTransaction.class}, version = 2) +@Database(entities = {AccountSeed.class, CryptoNetAccount.class, CryptoCoinTransaction.class, CryptoCurrency.class}, version = 2) @TypeConverters({Converters.class}) public abstract class CrystalDatabase extends RoomDatabase { diff --git a/app/src/main/java/cy/agorise/crystalwallet/manager/CryptoAccountManager.java b/app/src/main/java/cy/agorise/crystalwallet/manager/CryptoAccountManager.java new file mode 100644 index 0000000..709a1ba --- /dev/null +++ b/app/src/main/java/cy/agorise/crystalwallet/manager/CryptoAccountManager.java @@ -0,0 +1,34 @@ +package cy.agorise.crystalwallet.manager; + +import cy.agorise.crystalwallet.models.AccountSeed; +import cy.agorise.crystalwallet.models.CryptoNetAccount; + +/** + * Manager of each crypto coin account + * + * Created by henry on 24/9/2017. + */ + +public interface CryptoAccountManager { + + /** + * Creates a CryptoCoin Account, with the values of the account + * @param account The values to be created, + * @returnThe CruptoNetAccount created, or null if it couldn't be created + */ + public CryptoNetAccount createAccountFromSeed(CryptoNetAccount account); + + /** + * Imports a CryptoCoin account from a seed + * @param account A CryptoNetAccount with the parameters to be imported + * @returnThe CruptoNetAccount imported + */ + public CryptoNetAccount importAccountFromSeed(CryptoNetAccount account); + + /** + * Loads account data from the database + * + * @param account The CryptoNetAccount to be loaded + */ + public void loadAccountFromDB(CryptoNetAccount account); +} diff --git a/app/src/main/java/cy/agorise/crystalwallet/models/CryptoCoinTransaction.java b/app/src/main/java/cy/agorise/crystalwallet/models/CryptoCoinTransaction.java index 07c9117..00f173d 100644 --- a/app/src/main/java/cy/agorise/crystalwallet/models/CryptoCoinTransaction.java +++ b/app/src/main/java/cy/agorise/crystalwallet/models/CryptoCoinTransaction.java @@ -2,6 +2,7 @@ package cy.agorise.crystalwallet.models; import android.arch.persistence.room.ColumnInfo; import android.arch.persistence.room.Entity; +import android.arch.persistence.room.ForeignKey; import android.arch.persistence.room.PrimaryKey; import android.support.annotation.NonNull; import android.support.v7.recyclerview.extensions.DiffCallback; @@ -15,7 +16,17 @@ import cy.agorise.crystalwallet.enums.CryptoCoin; * * Created by Henry Varona on 11/9/2017. */ -@Entity(tableName="crypto_coin_transaction") +@Entity(tableName="crypto_coin_transaction", + foreignKeys = {@ForeignKey(entity = CryptoNetAccount.class, + parentColumns = "id", + childColumns = "account_id", + onDelete = ForeignKey.CASCADE), + @ForeignKey(entity = CryptoCurrency.class, + parentColumns = "id", + childColumns = "id_currency", + onDelete = ForeignKey.CASCADE) +} + ) public class CryptoCoinTransaction { /** @@ -51,10 +62,10 @@ public class CryptoCoinTransaction { protected int amount; /** - * The id of the Crypto Asset to use in the database + * The id of the Crypto Currency to use in the database */ - @ColumnInfo(name="id_asset") - private int idAsset; + @ColumnInfo(name="id_currency") + protected int idCurrency; /** * If this transaction is confirmed */ @@ -129,9 +140,9 @@ public class CryptoCoinTransaction { public void setAmount(int amount) { this.amount = amount; } - public int getIdAsset() { return idAsset; } + public int getIdCurrency() { return idCurrency; } - public void setIdAsset(int idAsset) { this.idAsset = idAsset; } + public void setIdCurrency(int idCurrency) { this.idCurrency = idCurrency; } public static final DiffCallback DIFF_CALLBACK = new DiffCallback() { @@ -158,7 +169,7 @@ public class CryptoCoinTransaction { if (isInput != that.isInput) return false; if (accountId != that.accountId) return false; if (amount != that.amount) return false; - if (idAsset != that.idAsset) return false; + if (idCurrency != that.idCurrency) return false; if (isConfirmed != that.isConfirmed) return false; if (date != null ? !date.equals(that.date) : that.date != null) return false; if (from != null ? !from.equals(that.from) : that.from != null) return false; diff --git a/app/src/main/java/cy/agorise/crystalwallet/models/CryptoAsset.java b/app/src/main/java/cy/agorise/crystalwallet/models/CryptoCurrency.java similarity index 79% rename from app/src/main/java/cy/agorise/crystalwallet/models/CryptoAsset.java rename to app/src/main/java/cy/agorise/crystalwallet/models/CryptoCurrency.java index dbcf9a2..78cb47c 100644 --- a/app/src/main/java/cy/agorise/crystalwallet/models/CryptoAsset.java +++ b/app/src/main/java/cy/agorise/crystalwallet/models/CryptoCurrency.java @@ -1,6 +1,7 @@ package cy.agorise.crystalwallet.models; import android.arch.persistence.room.ColumnInfo; +import android.arch.persistence.room.Entity; import android.arch.persistence.room.PrimaryKey; import android.arch.persistence.room.TypeConverters; @@ -8,12 +9,12 @@ import cy.agorise.crystalwallet.dao.converters.Converters; import cy.agorise.crystalwallet.enums.CryptoNet; /** - * Represents each asset in transaction and balances + * Represents each currency in transaction and balances * * Created by henry Henry Varona on 11/9/2017. */ - -public class CryptoAsset { +@Entity(tableName="crypto_currency") +public class CryptoCurrency { /** * The id on the database @@ -23,14 +24,16 @@ public class CryptoAsset { private int mId; /** - * The name or tag of this seed + * The name or tag of this currency */ @ColumnInfo(name = "name") private String mName; /** - * CryptoCoin network where this assets belongs to + * CryptoCoin network where this currency belongs to */ + @ColumnInfo(name = "crypto_net") + @TypeConverters(Converters.class) private CryptoNet mCryptoNet; diff --git a/app/src/main/java/cy/agorise/crystalwallet/models/CryptoNetAccount.java b/app/src/main/java/cy/agorise/crystalwallet/models/CryptoNetAccount.java index b6d73a4..8eb8640 100644 --- a/app/src/main/java/cy/agorise/crystalwallet/models/CryptoNetAccount.java +++ b/app/src/main/java/cy/agorise/crystalwallet/models/CryptoNetAccount.java @@ -40,7 +40,7 @@ public class CryptoNetAccount { private int mAccountNumber; /** - * The account index + * The account index on this wallet */ @ColumnInfo(name = "account_index") private int mAccountIndex; diff --git a/app/src/main/java/cy/agorise/crystalwallet/models/GrapheneAccount.java b/app/src/main/java/cy/agorise/crystalwallet/models/GrapheneAccount.java new file mode 100644 index 0000000..7f8e84d --- /dev/null +++ b/app/src/main/java/cy/agorise/crystalwallet/models/GrapheneAccount.java @@ -0,0 +1,11 @@ +package cy.agorise.crystalwallet.models; + +/** + * Created by henry on 24/9/2017. + */ + +public class GrapheneAccount extends CryptoNetAccount { + + protected String name; + +}