From d41518de0fa477eda1f0f8e9430011f429b3c19d Mon Sep 17 00:00:00 2001 From: henry Date: Wed, 13 Sep 2017 23:13:37 -0400 Subject: [PATCH] Created CryptoAsset --- .../dao/converters/Converters.java | 19 ++++++ .../crystalwallet/enums/CryptoNet.java | 1 - .../crystalwallet/models/CryptoAsset.java | 64 ++++++++++++++++++ .../models/CryptoCoinTransaction.java | 65 ++++++++----------- 4 files changed, 109 insertions(+), 40 deletions(-) diff --git a/app/src/main/java/cy/agorise/crystalwallet/dao/converters/Converters.java b/app/src/main/java/cy/agorise/crystalwallet/dao/converters/Converters.java index 2234b47..aabe614 100644 --- a/app/src/main/java/cy/agorise/crystalwallet/dao/converters/Converters.java +++ b/app/src/main/java/cy/agorise/crystalwallet/dao/converters/Converters.java @@ -5,6 +5,7 @@ import android.arch.persistence.room.TypeConverter; import java.util.Date; import cy.agorise.crystalwallet.enums.CryptoCoin; +import cy.agorise.crystalwallet.enums.CryptoNet; import cy.agorise.crystalwallet.models.CryptoNetAccount; import static cy.agorise.crystalwallet.R.string.account; @@ -65,4 +66,22 @@ public class Converters { return CryptoCoin.valueOf(value); } } + + @TypeConverter + public String cryptoNetToName(CryptoNet net){ + if (net == null) { + return ""; + } else { + return net.getLabel(); + } + } + + @TypeConverter + public CryptoNet nameToCryptoNet(String value) { + if (value.equals("")){ + return null; + } else { + return CryptoNet.valueOf(value); + } + } } diff --git a/app/src/main/java/cy/agorise/crystalwallet/enums/CryptoNet.java b/app/src/main/java/cy/agorise/crystalwallet/enums/CryptoNet.java index 0f75732..d3d81ed 100644 --- a/app/src/main/java/cy/agorise/crystalwallet/enums/CryptoNet.java +++ b/app/src/main/java/cy/agorise/crystalwallet/enums/CryptoNet.java @@ -8,7 +8,6 @@ import java.io.Serializable; * * Created by Henry Varona on 12/9/2017. */ - public enum CryptoNet implements Serializable { BITCOIN("BITCOIN",6), BITCOIN_TEST("BITCOIN(TEST)",6), LITECOIN("LITECOIN",6), DASH("DASH",6), DOGECOIN("DOGECOIN",6), BITSHARES("BITSHARES",1), STEEM("STEEN",1); diff --git a/app/src/main/java/cy/agorise/crystalwallet/models/CryptoAsset.java b/app/src/main/java/cy/agorise/crystalwallet/models/CryptoAsset.java index f2a318e..dbcf9a2 100644 --- a/app/src/main/java/cy/agorise/crystalwallet/models/CryptoAsset.java +++ b/app/src/main/java/cy/agorise/crystalwallet/models/CryptoAsset.java @@ -1,5 +1,12 @@ package cy.agorise.crystalwallet.models; +import android.arch.persistence.room.ColumnInfo; +import android.arch.persistence.room.PrimaryKey; +import android.arch.persistence.room.TypeConverters; + +import cy.agorise.crystalwallet.dao.converters.Converters; +import cy.agorise.crystalwallet.enums.CryptoNet; + /** * Represents each asset in transaction and balances * @@ -7,4 +14,61 @@ package cy.agorise.crystalwallet.models; */ public class CryptoAsset { + + /** + * The id on the database + */ + @PrimaryKey(autoGenerate = true) + @ColumnInfo(name = "id") + private int mId; + + /** + * The name or tag of this seed + */ + @ColumnInfo(name = "name") + private String mName; + + /** + * CryptoCoin network where this assets belongs to + */ + private CryptoNet mCryptoNet; + + + /** + * The decimal point + */ + @ColumnInfo(name = "precision") + private int mPrecision; + + public int getId() { + return mId; + } + + public void setId(int mId) { + this.mId = mId; + } + + public String getName() { + return mName; + } + + public void setName(String mName) { + this.mName = mName; + } + + public CryptoNet getCryptoNet() { + return mCryptoNet; + } + + public void setCryptoNet(CryptoNet cryptoNet) { + this.mCryptoNet = cryptoNet; + } + + public int getPrecision() { + return mPrecision; + } + + public void setPrecision(int precision) { + this.mPrecision = precision; + } } 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 f71e894..d029710 100644 --- a/app/src/main/java/cy/agorise/crystalwallet/models/CryptoCoinTransaction.java +++ b/app/src/main/java/cy/agorise/crystalwallet/models/CryptoCoinTransaction.java @@ -48,61 +48,36 @@ public class CryptoCoinTransaction { @ColumnInfo(name="amount") protected int amount; - public CryptoCoin getCoin() { - return coin; - } - - public void setCoin(CryptoCoin coin) { - this.coin = coin; - } - - public boolean isConfirmed() { - return isConfirmed; - } - - public void setConfirmed(boolean confirmed) { - isConfirmed = confirmed; - } - /** - * The crypto Coin associated with this transaction + * The id of the Crypto Asset to use in the database */ - @ColumnInfo(name="crypto_coin") - protected CryptoCoin coin; + @ColumnInfo(name="id_asset") + private int idAsset; /** * If this transaction is confirmed */ @ColumnInfo(name="is_confirmed") protected boolean isConfirmed; - public int getAmount() { - return amount; - } - - public void setAmount(int amount) { - this.amount = amount; - } - + /** + * The address or account the amount of assets comes from + */ @ColumnInfo(name="from") protected String from; + + /** + * The address or account the amount of assets goes to + */ @ColumnInfo(name="to") protected String to; - public String getFrom() { - return from; - } + public String getFrom() { return from; } - public void setFrom(String from) { - this.from = from; - } + public void setFrom(String from) { this.from = from; } - public String getTo() { - return to; - } + public String getTo() { return to; } - public void setTo(String to) { - this.to = to; - } + public void setTo(String to) { this.to = to; } public int getAccountId() { return accountId; @@ -143,4 +118,16 @@ public class CryptoCoinTransaction { public void setInput(boolean input) { this.isInput = input; } + + public boolean isConfirmed() { return isConfirmed; } + + public void setConfirmed(boolean confirmed) { isConfirmed = confirmed; } + + public int getAmount() { return amount; } + + public void setAmount(int amount) { this.amount = amount; } + + public int getIdAsset() { return idAsset; } + + public void setIdAsset(int idAsset) { this.idAsset = idAsset; } }