From 7123c01aff5b81dd12c6445dfbf0791df87f3bdc Mon Sep 17 00:00:00 2001 From: Javier Varona Date: Tue, 17 Oct 2017 20:35:37 -0400 Subject: [PATCH] - Added GrapheneAccountInfo for graphene specific information of accounts - Added type of account in crypto_net_account --- .../activities/IntroActivity.java | 7 +++ .../crystalwallet/dao/CryptoCurrencyDao.java | 2 +- .../dao/CryptoNetAccountDao.java | 3 ++ .../crystalwallet/dao/CrystalDatabase.java | 20 +++----- .../dao/GrapheneAccountInfoDao.java | 28 ++++++++++ .../crystalwallet/dao/TransactionDao.java | 4 +- .../crystalwallet/enums/CryptoCoin.java | 13 +++++ .../models/CryptoNetAccount.java | 13 +++++ .../crystalwallet/models/GrapheneAccount.java | 1 + .../models/GrapheneAccountInfo.java | 51 +++++++++++++++++++ .../views/CryptoCoinBalanceListView.java | 4 +- .../views/CryptoCoinBalanceViewHolder.java | 2 +- .../views/CryptoNetBalanceViewHolder.java | 18 ++++++- app/src/main/res/layout/balance_list_item.xml | 2 +- 14 files changed, 147 insertions(+), 21 deletions(-) create mode 100644 app/src/main/java/cy/agorise/crystalwallet/dao/GrapheneAccountInfoDao.java create mode 100644 app/src/main/java/cy/agorise/crystalwallet/models/GrapheneAccountInfo.java diff --git a/app/src/main/java/cy/agorise/crystalwallet/activities/IntroActivity.java b/app/src/main/java/cy/agorise/crystalwallet/activities/IntroActivity.java index 68ae134..e268e7a 100644 --- a/app/src/main/java/cy/agorise/crystalwallet/activities/IntroActivity.java +++ b/app/src/main/java/cy/agorise/crystalwallet/activities/IntroActivity.java @@ -18,8 +18,10 @@ import java.util.List; import cy.agorise.crystalwallet.R; import cy.agorise.crystalwallet.dao.CrystalDatabase; import cy.agorise.crystalwallet.models.AccountSeed; +import cy.agorise.crystalwallet.models.CryptoCoinBalance; import cy.agorise.crystalwallet.models.CryptoCoinTransaction; import cy.agorise.crystalwallet.models.CryptoNetAccount; +import cy.agorise.crystalwallet.randomdatagenerators.RandomCryptoCoinBalanceGenerator; import cy.agorise.crystalwallet.randomdatagenerators.RandomCryptoNetAccountGenerator; import cy.agorise.crystalwallet.randomdatagenerators.RandomSeedGenerator; import cy.agorise.crystalwallet.randomdatagenerators.RandomTransactionsGenerator; @@ -63,6 +65,11 @@ public class IntroActivity extends AppCompatActivity { long newId = db.cryptoNetAccountDao().insertCryptoNetAccount(accounts.get(i))[0]; accounts.get(i).setId(newId); } + List balances = RandomCryptoCoinBalanceGenerator.generateCryptoCoinBalances(accounts,5,1,20); + for(int i=0;i transactions = RandomTransactionsGenerator.generateTransactions(accounts,100,1262304001,1496275201,1,999999999); for(int i=0;i getAll(); - @Query("SELECT * FROM crypto_currency WHERE id := id") + @Query("SELECT * FROM crypto_currency WHERE id = :id") CryptoCurrency getById(int id); @Insert(onConflict = OnConflictStrategy.REPLACE) diff --git a/app/src/main/java/cy/agorise/crystalwallet/dao/CryptoNetAccountDao.java b/app/src/main/java/cy/agorise/crystalwallet/dao/CryptoNetAccountDao.java index a480fb7..ff63c70 100644 --- a/app/src/main/java/cy/agorise/crystalwallet/dao/CryptoNetAccountDao.java +++ b/app/src/main/java/cy/agorise/crystalwallet/dao/CryptoNetAccountDao.java @@ -23,6 +23,9 @@ public interface CryptoNetAccountDao { @Query("SELECT * FROM crypto_net_account") List getAll(); + @Query("SELECT * FROM crypto_net_account WHERE type = 1") + LiveData> getGrapheneAccounts(); + @Insert(onConflict = OnConflictStrategy.REPLACE) public long[] insertCryptoNetAccount(CryptoNetAccount... accounts); 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 da2e73c..13a00c9 100644 --- a/app/src/main/java/cy/agorise/crystalwallet/dao/CrystalDatabase.java +++ b/app/src/main/java/cy/agorise/crystalwallet/dao/CrystalDatabase.java @@ -1,11 +1,9 @@ package cy.agorise.crystalwallet.dao; -import android.arch.persistence.db.SupportSQLiteDatabase; import android.arch.persistence.room.Database; import android.arch.persistence.room.Room; import android.arch.persistence.room.RoomDatabase; import android.arch.persistence.room.TypeConverters; -import android.arch.persistence.room.migration.Migration; import android.content.Context; import cy.agorise.crystalwallet.dao.converters.Converters; @@ -14,13 +12,14 @@ import cy.agorise.crystalwallet.models.CryptoCoinBalance; import cy.agorise.crystalwallet.models.CryptoCoinTransaction; import cy.agorise.crystalwallet.models.CryptoCurrency; import cy.agorise.crystalwallet.models.CryptoNetAccount; +import cy.agorise.crystalwallet.models.GrapheneAccountInfo; /** * Manage the Database * Created by Henry Varona on 4/9/2017. */ -@Database(entities = {AccountSeed.class, CryptoNetAccount.class, CryptoCoinTransaction.class, CryptoCurrency.class, CryptoCoinBalance.class}, version = 2) +@Database(entities = {AccountSeed.class, CryptoNetAccount.class, CryptoCoinTransaction.class, CryptoCurrency.class, CryptoCoinBalance.class, GrapheneAccountInfo.class}, version = 2) @TypeConverters({Converters.class}) public abstract class CrystalDatabase extends RoomDatabase { @@ -28,6 +27,7 @@ public abstract class CrystalDatabase extends RoomDatabase { public abstract AccountSeedDao accountSeedDao(); public abstract CryptoNetAccountDao cryptoNetAccountDao(); + public abstract GrapheneAccountInfoDao grapheneAccountInfoDao(); public abstract TransactionDao transactionDao(); public abstract CryptoCoinBalanceDao cryptoCoinBalanceDao(); public abstract CryptoCurrencyDao cryptoCurrencyDao(); @@ -49,16 +49,10 @@ public abstract class CrystalDatabase extends RoomDatabase { /*static final Migration MIGRATION_1_2 = new Migration(1, 2) { @Override public void migrate(SupportSQLiteDatabase database) { - database.execSQL("CREATE TABLE 'account_seed' ('id' INTEGER PRIMARY KEY AUTOINCREMENT, " - + "'name' TEXT, 'master_seed' NUMERIC)"); - database.execSQL("CREATE TABLE 'crypto_net_account' ('id' INTEGER PRIMARY KEY AUTOINCREMENT, " - + "'seed_id' INTEGER, " - + "'account_number' INT, 'account_index' INT," - + "FOREIGN_KEY(seed_id) REFERENCES seed(id))"); - database.execSQL("CREATE TABLE 'crypto_coin_transaction' ('id' INTEGER PRIMARY KEY AUTOINCREMENT, " - + "'account_id' INTEGER, " - + "'date' INT, 'is_input' INT, amount INT, crypto_coin TEXT, is_confirmed INT, " - + "FOREIGN_KEY(account_id) REFERENCES crypto_net_account(id))"); + database.execSQL("UPDATE TABLE 'crypto_net_account' ADD " + + "'subclass' INT, " + + "'bitshares_account_name' STRING, " + + "'bitshares_account_id' STRING "); } };*/ } diff --git a/app/src/main/java/cy/agorise/crystalwallet/dao/GrapheneAccountInfoDao.java b/app/src/main/java/cy/agorise/crystalwallet/dao/GrapheneAccountInfoDao.java new file mode 100644 index 0000000..2cfe5f6 --- /dev/null +++ b/app/src/main/java/cy/agorise/crystalwallet/dao/GrapheneAccountInfoDao.java @@ -0,0 +1,28 @@ +package cy.agorise.crystalwallet.dao; + +import android.arch.lifecycle.LiveData; +import android.arch.persistence.room.Dao; +import android.arch.persistence.room.Insert; +import android.arch.persistence.room.OnConflictStrategy; +import android.arch.persistence.room.Query; + +import java.util.List; + +import cy.agorise.crystalwallet.models.CryptoNetAccount; +import cy.agorise.crystalwallet.models.GrapheneAccount; +import cy.agorise.crystalwallet.models.GrapheneAccountInfo; + +/** + * Created by Henry Varona on 10/9/2017. + */ + +@Dao +public interface GrapheneAccountInfoDao { + + @Query("SELECT * FROM graphene_account WHERE subclass = 1") + LiveData> getAll(); + + @Insert(onConflict = OnConflictStrategy.REPLACE) + public long[] insertGrapheneAccountInfo(GrapheneAccountInfo... accounts); + +} diff --git a/app/src/main/java/cy/agorise/crystalwallet/dao/TransactionDao.java b/app/src/main/java/cy/agorise/crystalwallet/dao/TransactionDao.java index bbc8d39..dbe6763 100644 --- a/app/src/main/java/cy/agorise/crystalwallet/dao/TransactionDao.java +++ b/app/src/main/java/cy/agorise/crystalwallet/dao/TransactionDao.java @@ -23,8 +23,8 @@ public interface TransactionDao { @Query("SELECT * FROM crypto_coin_transaction ORDER BY date ASC") LivePagedListProvider transactionsByDate(); - @Query("SELECT * FROM crypto_coin_transaction WHERE account_id := idAccount ORDER BY date ASC") - LiveData> getByIdAccount(long idAccount); + @Query("SELECT * FROM crypto_coin_transaction WHERE account_id = :idAccount ORDER BY date ASC") + LiveData> getByIdAccount(long idAccount); @Insert(onConflict = OnConflictStrategy.REPLACE) public long[] insertTransaction(CryptoCoinTransaction... transactions); diff --git a/app/src/main/java/cy/agorise/crystalwallet/enums/CryptoCoin.java b/app/src/main/java/cy/agorise/crystalwallet/enums/CryptoCoin.java index 0dc377c..3bf8ff7 100644 --- a/app/src/main/java/cy/agorise/crystalwallet/enums/CryptoCoin.java +++ b/app/src/main/java/cy/agorise/crystalwallet/enums/CryptoCoin.java @@ -1,6 +1,8 @@ package cy.agorise.crystalwallet.enums; import java.io.Serializable; +import java.util.ArrayList; +import java.util.List; /** * Created by Henry Varona on 12/9/2017. @@ -34,5 +36,16 @@ public enum CryptoCoin implements Serializable { public int getPrecision(){ return this.precision; } + public static List getByCryptoNet(CryptoNet cryptoNet){ + List result = new ArrayList(); + + for (CryptoCoin nextCryptoCoin : CryptoCoin.values()){ + if (nextCryptoCoin.getCryptoNet().equals(cryptoNet)) { + result.add(nextCryptoCoin); + } + } + + return result; + } } 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 df6238d..eb09632 100644 --- a/app/src/main/java/cy/agorise/crystalwallet/models/CryptoNetAccount.java +++ b/app/src/main/java/cy/agorise/crystalwallet/models/CryptoNetAccount.java @@ -45,6 +45,12 @@ public class CryptoNetAccount { @ColumnInfo(name = "account_index") private int mAccountIndex; + /** + * The type of the account + */ + @ColumnInfo(name = "type") + private int type; + public long getId() { return mId; } @@ -77,4 +83,11 @@ public class CryptoNetAccount { this.mAccountIndex = mAccountIndex; } + public int getType() { + return type; + } + + public void setType(int type) { + this.type = type; + } } diff --git a/app/src/main/java/cy/agorise/crystalwallet/models/GrapheneAccount.java b/app/src/main/java/cy/agorise/crystalwallet/models/GrapheneAccount.java index 915c4b7..85ad344 100644 --- a/app/src/main/java/cy/agorise/crystalwallet/models/GrapheneAccount.java +++ b/app/src/main/java/cy/agorise/crystalwallet/models/GrapheneAccount.java @@ -6,6 +6,7 @@ package cy.agorise.crystalwallet.models; public class GrapheneAccount extends CryptoNetAccount { + public static int subclass = 1; protected String name; protected String accountId; diff --git a/app/src/main/java/cy/agorise/crystalwallet/models/GrapheneAccountInfo.java b/app/src/main/java/cy/agorise/crystalwallet/models/GrapheneAccountInfo.java new file mode 100644 index 0000000..25d4b47 --- /dev/null +++ b/app/src/main/java/cy/agorise/crystalwallet/models/GrapheneAccountInfo.java @@ -0,0 +1,51 @@ +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.Index; + +/** + * Created by henry on 24/9/2017. + */ + +@Entity(tableName = "graphene_account", + indices = {@Index("id"),@Index(value = "crypto_net_account_id",unique=true)}, + foreignKeys = @ForeignKey(entity = CryptoNetAccount.class, + parentColumns = "id", + childColumns = "crypto_net_account_id")) +public class GrapheneAccountInfo { + + @ColumnInfo(name = "crypto_net_account_id") + protected String cryptoNetAccountId; + + @ColumnInfo(name = "account_name") + protected String name; + + @ColumnInfo(name = "account_id") + protected String accountId; + + public String getCryptoNetAccountId() { + return cryptoNetAccountId; + } + + public void setCryptoNetAccountId(String cryptoNetAccountId) { + this.cryptoNetAccountId = cryptoNetAccountId; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getAccountId() { + return accountId; + } + + public void setAccountId(String accountId) { + this.accountId = accountId; + } +} diff --git a/app/src/main/java/cy/agorise/crystalwallet/views/CryptoCoinBalanceListView.java b/app/src/main/java/cy/agorise/crystalwallet/views/CryptoCoinBalanceListView.java index 3d173a1..bd03126 100644 --- a/app/src/main/java/cy/agorise/crystalwallet/views/CryptoCoinBalanceListView.java +++ b/app/src/main/java/cy/agorise/crystalwallet/views/CryptoCoinBalanceListView.java @@ -51,11 +51,11 @@ public class CryptoCoinBalanceListView extends RelativeLayout { public void init(){ rootView = mInflater.inflate(R.layout.crypto_coin_balance_list, this, true); - /*this.listView = rootView.findViewById(R.id.cryptoCoinBalanceListView); + this.listView = (RecyclerView) rootView.findViewById(R.id.cryptoCoinBalanceListView); final LinearLayoutManager linearLayoutManager = new LinearLayoutManager(this.getContext()); this.listView.setLayoutManager(linearLayoutManager); - this.listView.setNestedScrollingEnabled(false);*/ + this.listView.setNestedScrollingEnabled(false); } public void setData(List data){ diff --git a/app/src/main/java/cy/agorise/crystalwallet/views/CryptoCoinBalanceViewHolder.java b/app/src/main/java/cy/agorise/crystalwallet/views/CryptoCoinBalanceViewHolder.java index a88bfc7..3619f4d 100644 --- a/app/src/main/java/cy/agorise/crystalwallet/views/CryptoCoinBalanceViewHolder.java +++ b/app/src/main/java/cy/agorise/crystalwallet/views/CryptoCoinBalanceViewHolder.java @@ -34,7 +34,7 @@ public class CryptoCoinBalanceViewHolder extends RecyclerView.ViewHolder { cryptoCoinBalance.setText(""); } else { cryptoCoinName.setText(balance.getCoin().getLabel()); - cryptoCoinBalance.setText(balance.getBalance()); + cryptoCoinBalance.setText(""+balance.getBalance()); } } } diff --git a/app/src/main/java/cy/agorise/crystalwallet/views/CryptoNetBalanceViewHolder.java b/app/src/main/java/cy/agorise/crystalwallet/views/CryptoNetBalanceViewHolder.java index b62965d..0db7099 100644 --- a/app/src/main/java/cy/agorise/crystalwallet/views/CryptoNetBalanceViewHolder.java +++ b/app/src/main/java/cy/agorise/crystalwallet/views/CryptoNetBalanceViewHolder.java @@ -1,5 +1,6 @@ package cy.agorise.crystalwallet.views; +import android.arch.lifecycle.ViewModelProviders; import android.support.v7.widget.RecyclerView; import android.view.View; import android.widget.ImageView; @@ -23,7 +24,7 @@ public class CryptoNetBalanceViewHolder extends RecyclerView.ViewHolder { super(itemView); cryptoNetIcon = (ImageView) itemView.findViewById(R.id.ivCryptoNetIcon); cryptoNetName = (TextView) itemView.findViewById(R.id.tvCryptoNetName); - cryptoCoinBalanceListView = (CryptoCoinBalanceListView) itemView.findViewById(R.id.cryptoCoinBalanceListView); + cryptoCoinBalanceListView = (CryptoCoinBalanceListView) itemView.findViewById(R.id.cryptoCoinBalancesListView); } @@ -36,6 +37,21 @@ public class CryptoNetBalanceViewHolder extends RecyclerView.ViewHolder { cryptoNetName.setText("loading..."); } else { cryptoNetName.setText(balance.getCryptoNet().getLabel()); + + /*transactionListView = this.findViewById(R.id.transaction_list); + + transactionListViewModel = ViewModelProviders.of(getContext).get(TransactionListViewModel.class); + LiveData> transactionData = transactionListViewModel.getTransactionList(); + transactionListView.setData(null); + + transactionData.observe(this, new Observer>() { + @Override + public void onChanged(PagedList cryptoCoinTransactions) { + transactionListView.setData(cryptoCoinTransactions); + } + }); + + cryptoCoinBalanceListView.setData();*/ } } } diff --git a/app/src/main/res/layout/balance_list_item.xml b/app/src/main/res/layout/balance_list_item.xml index 2315275..e0f9ad0 100644 --- a/app/src/main/res/layout/balance_list_item.xml +++ b/app/src/main/res/layout/balance_list_item.xml @@ -35,7 +35,7 @@ + android:id="@+id/cryptoCoinBalancesListView">