- Added GrapheneAccountInfo for graphene specific information of accounts

- Added type of account in crypto_net_account
This commit is contained in:
Javier Varona 2017-10-17 20:35:37 -04:00
parent a1ec57044c
commit 7123c01aff
14 changed files with 147 additions and 21 deletions

View file

@ -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<CryptoCoinBalance> balances = RandomCryptoCoinBalanceGenerator.generateCryptoCoinBalances(accounts,5,1,20);
for(int i=0;i<balances.size();i++) {
long newId = db.cryptoCoinBalanceDao().insertCryptoCoinBalance(balances.get(i))[0];
balances.get(i).setId(newId);
}
List<CryptoCoinTransaction> transactions = RandomTransactionsGenerator.generateTransactions(accounts,100,1262304001,1496275201,1,999999999);
for(int i=0;i<transactions.size();i++) {
long newId = db.transactionDao().insertTransaction(transactions.get(i))[0];

View file

@ -19,7 +19,7 @@ public interface CryptoCurrencyDao {
@Query("SELECT * FROM crypto_currency")
List<CryptoCurrency> 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)

View file

@ -23,6 +23,9 @@ public interface CryptoNetAccountDao {
@Query("SELECT * FROM crypto_net_account")
List<CryptoNetAccount> getAll();
@Query("SELECT * FROM crypto_net_account WHERE type = 1")
LiveData<List<CryptoNetAccount>> getGrapheneAccounts();
@Insert(onConflict = OnConflictStrategy.REPLACE)
public long[] insertCryptoNetAccount(CryptoNetAccount... accounts);

View file

@ -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 ");
}
};*/
}

View file

@ -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<List<GrapheneAccountInfo>> getAll();
@Insert(onConflict = OnConflictStrategy.REPLACE)
public long[] insertGrapheneAccountInfo(GrapheneAccountInfo... accounts);
}

View file

@ -23,8 +23,8 @@ public interface TransactionDao {
@Query("SELECT * FROM crypto_coin_transaction ORDER BY date ASC")
LivePagedListProvider<Integer, CryptoCoinTransaction> transactionsByDate();
@Query("SELECT * FROM crypto_coin_transaction WHERE account_id := idAccount ORDER BY date ASC")
LiveData<List<CryptoCoinTransaction>> getByIdAccount(long idAccount);
@Query("SELECT * FROM crypto_coin_transaction WHERE account_id = :idAccount ORDER BY date ASC")
LiveData<List<CryptoCoinTransaction>> getByIdAccount(long idAccount);
@Insert(onConflict = OnConflictStrategy.REPLACE)
public long[] insertTransaction(CryptoCoinTransaction... transactions);

View file

@ -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<CryptoCoin> getByCryptoNet(CryptoNet cryptoNet){
List<CryptoCoin> result = new ArrayList<CryptoCoin>();
for (CryptoCoin nextCryptoCoin : CryptoCoin.values()){
if (nextCryptoCoin.getCryptoNet().equals(cryptoNet)) {
result.add(nextCryptoCoin);
}
}
return result;
}
}

View file

@ -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;
}
}

View file

@ -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;

View file

@ -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;
}
}

View file

@ -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<CryptoCoinBalance> data){

View file

@ -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());
}
}
}

View file

@ -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<PagedList<CryptoCoinTransaction>> transactionData = transactionListViewModel.getTransactionList();
transactionListView.setData(null);
transactionData.observe(this, new Observer<PagedList<CryptoCoinTransaction>>() {
@Override
public void onChanged(PagedList<CryptoCoinTransaction> cryptoCoinTransactions) {
transactionListView.setData(cryptoCoinTransactions);
}
});
cryptoCoinBalanceListView.setData();*/
}
}
}

View file

@ -35,7 +35,7 @@
<cy.agorise.crystalwallet.views.CryptoCoinBalanceListView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/cryptoCoinBalanceListView">
android:id="@+id/cryptoCoinBalancesListView">
</cy.agorise.crystalwallet.views.CryptoCoinBalanceListView>