- Now the balance fragment is showing the user accounts. Still it needs to show the balances of their assets
This commit is contained in:
parent
b15c5a4710
commit
814d724096
15 changed files with 136 additions and 89 deletions
|
@ -55,7 +55,7 @@ public class IntroActivity extends AppCompatActivity {
|
|||
/*CrystalDatabase db = CrystalDatabase.getAppDatabase(getApplicationContext());
|
||||
List<AccountSeed> seeds = RandomSeedGenerator.generateSeeds(2);
|
||||
for(int i=0;i<seeds.size();i++) {
|
||||
long newId = db.accountSeedDao().insertAccountSeed(seeds.get(i))[0];
|
||||
long newId = db.accountSeedDao().insertAccountSeed(seeds.get(i));
|
||||
seeds.get(i).setId(newId);
|
||||
}
|
||||
List<CryptoNetAccount> accounts = RandomCryptoNetAccountGenerator.generateAccounts(5,seeds);
|
||||
|
|
|
@ -22,8 +22,11 @@ public interface CryptoCoinBalanceDao {
|
|||
@Query("SELECT * FROM crypto_coin_balance")
|
||||
List<CryptoCoinBalance> getAll();
|
||||
|
||||
@Query("SELECT * FROM crypto_net_account WHERE account_id = :acountId")
|
||||
LiveData<List<CryptoNetBalance>> getAllFromAccount(long accountId);
|
||||
@Query("SELECT id as account_id, account_number FROM crypto_net_account")
|
||||
LiveData<List<CryptoNetBalance>> getAllBalances();
|
||||
|
||||
@Query("SELECT * FROM crypto_coin_balance WHERE account_id = :accountId")
|
||||
LiveData<List<CryptoCoinBalance>> getBalancesFromAccount(long accountId);
|
||||
|
||||
@Insert(onConflict = OnConflictStrategy.REPLACE)
|
||||
public long[] insertCryptoCoinBalance(CryptoCoinBalance... balances);
|
||||
|
|
|
@ -23,14 +23,7 @@ public interface CryptoNetAccountDao {
|
|||
@Query("SELECT * FROM crypto_net_account")
|
||||
List<CryptoNetAccount> getAll();
|
||||
|
||||
@Query("SELECT * FROM crypto_net_account")
|
||||
LiveData<List<CryptoNetBalance>> getAllBalances();
|
||||
|
||||
@Query("SELECT 'Bitshares' as coin, 1 as balance FROM crypto_net_account WHERE id = :accountId")
|
||||
LiveData<List<CryptoCoinBalance>> getBalancesFromAccount(long accountId);
|
||||
|
||||
|
||||
@Insert(onConflict = OnConflictStrategy.REPLACE)
|
||||
public long[] insertCryptoNetAccount(CryptoNetAccount... accounts);
|
||||
public long[] insertCryptoNetAccount(CryptoNetAccount... accounts);
|
||||
|
||||
}
|
||||
|
|
|
@ -10,6 +10,7 @@ import android.content.Context;
|
|||
|
||||
import cy.agorise.crystalwallet.dao.converters.Converters;
|
||||
import cy.agorise.crystalwallet.models.AccountSeed;
|
||||
import cy.agorise.crystalwallet.models.CryptoCoinBalance;
|
||||
import cy.agorise.crystalwallet.models.CryptoCoinTransaction;
|
||||
import cy.agorise.crystalwallet.models.CryptoCurrency;
|
||||
import cy.agorise.crystalwallet.models.CryptoNetAccount;
|
||||
|
@ -19,7 +20,7 @@ import cy.agorise.crystalwallet.models.CryptoNetAccount;
|
|||
* Created by Henry Varona on 4/9/2017.
|
||||
*/
|
||||
|
||||
@Database(entities = {AccountSeed.class, CryptoNetAccount.class, CryptoCoinTransaction.class, CryptoCurrency.class}, version = 2)
|
||||
@Database(entities = {AccountSeed.class, CryptoNetAccount.class, CryptoCoinTransaction.class, CryptoCurrency.class, CryptoCoinBalance.class}, version = 2)
|
||||
@TypeConverters({Converters.class})
|
||||
public abstract class CrystalDatabase extends RoomDatabase {
|
||||
|
||||
|
@ -28,6 +29,7 @@ public abstract class CrystalDatabase extends RoomDatabase {
|
|||
public abstract AccountSeedDao accountSeedDao();
|
||||
public abstract CryptoNetAccountDao cryptoNetAccountDao();
|
||||
public abstract TransactionDao transactionDao();
|
||||
public abstract CryptoCoinBalanceDao cryptoCoinBalanceDao();
|
||||
|
||||
public static CrystalDatabase getAppDatabase(Context context) {
|
||||
if (instance == null) {
|
||||
|
|
|
@ -103,4 +103,18 @@ public class Converters {
|
|||
return SeedType.valueOf(value);
|
||||
}
|
||||
}
|
||||
|
||||
@TypeConverter
|
||||
public int cryptoNetToAccountNumber(CryptoNet value) {
|
||||
if (value == null) {
|
||||
return -1;
|
||||
} else {
|
||||
return value.getBip44Index();
|
||||
}
|
||||
}
|
||||
|
||||
@TypeConverter
|
||||
public CryptoNet accountNumberToCryptoNet(int value) {
|
||||
return CryptoNet.fromBip44Index(value);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
package cy.agorise.crystalwallet.enums;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* CryptoNet Enumeration, a Crypto Net is define as the net where a CryptoCoin works, iniside the
|
||||
|
@ -9,16 +11,25 @@ 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);
|
||||
UNKNOWN("UNKNOWN",6,-1), BITCOIN("BITCOIN",6,1), BITCOIN_TEST("BITCOIN(TEST)",6,2), LITECOIN("LITECOIN",6,3), DASH("DASH",6,5), DOGECOIN("DOGECOIN",6,4), BITSHARES("BITSHARES",1,6), STEEM("STEEM",1,7);
|
||||
|
||||
protected String label;
|
||||
|
||||
protected int confirmationsNeeded;
|
||||
|
||||
protected int bip44Index;
|
||||
|
||||
CryptoNet(String label,int confirmationsNeeded){
|
||||
private static Map<Integer, CryptoNet> bip44Map = new HashMap<Integer, CryptoNet>();
|
||||
static {
|
||||
for (CryptoNet cryptoNetEnum : CryptoNet.values()) {
|
||||
bip44Map.put(cryptoNetEnum.bip44Index, cryptoNetEnum);
|
||||
}
|
||||
}
|
||||
|
||||
CryptoNet(String label,int confirmationsNeeded, int bip44Index){
|
||||
this.label = label;
|
||||
this.confirmationsNeeded = confirmationsNeeded;
|
||||
this.bip44Index = bip44Index;
|
||||
}
|
||||
|
||||
public String getLabel(){
|
||||
|
@ -28,4 +39,16 @@ public enum CryptoNet implements Serializable {
|
|||
public int getConfirmationsNeeded(){
|
||||
return this.confirmationsNeeded;
|
||||
}
|
||||
|
||||
public int getBip44Index(){
|
||||
return this.bip44Index;
|
||||
}
|
||||
|
||||
public static CryptoNet fromBip44Index(int index){
|
||||
if (bip44Map.containsKey(index)) {
|
||||
return bip44Map.get(index);
|
||||
} else {
|
||||
return CryptoNet.UNKNOWN;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,5 +1,8 @@
|
|||
package cy.agorise.crystalwallet.fragments;
|
||||
|
||||
import android.arch.lifecycle.LiveData;
|
||||
import android.arch.lifecycle.Observer;
|
||||
import android.arch.lifecycle.ViewModelProviders;
|
||||
import android.content.Context;
|
||||
import android.net.Uri;
|
||||
import android.os.Bundle;
|
||||
|
@ -8,9 +11,22 @@ import android.view.LayoutInflater;
|
|||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import butterknife.BindView;
|
||||
import butterknife.ButterKnife;
|
||||
import cy.agorise.crystalwallet.R;
|
||||
import cy.agorise.crystalwallet.models.CryptoNetBalance;
|
||||
import cy.agorise.crystalwallet.viewmodels.CryptoCoinBalanceListViewModel;
|
||||
import cy.agorise.crystalwallet.viewmodels.CryptoNetBalanceListViewModel;
|
||||
import cy.agorise.crystalwallet.views.CryptoNetBalanceListView;
|
||||
|
||||
public class BalanceFragment extends Fragment {
|
||||
CryptoNetBalanceListViewModel cryptoNetBalanceListViewModel;
|
||||
|
||||
@BindView(R.id.vCryptoNetBalanceListView)
|
||||
CryptoNetBalanceListView vCryptoNetBalanceListView;
|
||||
|
||||
public BalanceFragment() {
|
||||
// Required empty public constructor
|
||||
}
|
||||
|
@ -31,6 +47,20 @@ public class BalanceFragment extends Fragment {
|
|||
public View onCreateView(LayoutInflater inflater, ViewGroup container,
|
||||
Bundle savedInstanceState) {
|
||||
// Inflate the layout for this fragment
|
||||
return inflater.inflate(R.layout.fragment_balance, container, false);
|
||||
View view = inflater.inflate(R.layout.fragment_balance, container, false);
|
||||
ButterKnife.bind(this, view);
|
||||
|
||||
cryptoNetBalanceListViewModel = ViewModelProviders.of(this).get(CryptoNetBalanceListViewModel.class);
|
||||
LiveData<List<CryptoNetBalance>> cryptoNetBalanceData = cryptoNetBalanceListViewModel.getCryptoNetBalanceList();
|
||||
vCryptoNetBalanceListView.setData(null);
|
||||
|
||||
cryptoNetBalanceData.observe(this, new Observer<List<CryptoNetBalance>>() {
|
||||
@Override
|
||||
public void onChanged(List<CryptoNetBalance> cryptoNetBalances) {
|
||||
vCryptoNetBalanceListView.setData(cryptoNetBalances);
|
||||
}
|
||||
});
|
||||
|
||||
return view;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -24,6 +24,13 @@ import cy.agorise.crystalwallet.enums.CryptoCoin;
|
|||
childColumns = "account_id"))
|
||||
public class CryptoCoinBalance {
|
||||
|
||||
/**
|
||||
* The id on the database
|
||||
*/
|
||||
@PrimaryKey(autoGenerate = true)
|
||||
@ColumnInfo(name = "id")
|
||||
private long mId;
|
||||
|
||||
@ColumnInfo(name="account_id")
|
||||
private long mAccountId;
|
||||
|
||||
|
@ -33,6 +40,14 @@ public class CryptoCoinBalance {
|
|||
@ColumnInfo(name = "balance")
|
||||
private int mBalance;
|
||||
|
||||
public long getId() {
|
||||
return mId;
|
||||
}
|
||||
|
||||
public void setId(long id) {
|
||||
this.mId = id;
|
||||
}
|
||||
|
||||
public long getAccountId() {
|
||||
return mAccountId;
|
||||
}
|
||||
|
|
|
@ -4,98 +4,59 @@ 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.Ignore;
|
||||
import android.arch.persistence.room.Index;
|
||||
import android.arch.persistence.room.PrimaryKey;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.v7.recyclerview.extensions.DiffCallback;
|
||||
|
||||
import cy.agorise.crystalwallet.enums.CryptoCoin;
|
||||
import cy.agorise.crystalwallet.enums.CryptoNet;
|
||||
|
||||
import static android.arch.persistence.room.ColumnInfo.INTEGER;
|
||||
|
||||
/**
|
||||
* Represents a geneeric CryptoNet Account Balance
|
||||
* Represents a generic CryptoNet Account Balance
|
||||
*
|
||||
* Created by Henry Varona on 6/9/2017.
|
||||
*/
|
||||
|
||||
@Entity(tableName = "crypto_net_account",
|
||||
indices = {@Index("id"),@Index("seed_id")},
|
||||
foreignKeys = @ForeignKey(entity = AccountSeed.class,
|
||||
parentColumns = "id",
|
||||
childColumns = "seed_id"))
|
||||
@Entity
|
||||
public class CryptoNetBalance {
|
||||
|
||||
/**
|
||||
* The id on the database
|
||||
* The id of the account of this balance
|
||||
*/
|
||||
@PrimaryKey(autoGenerate = true)
|
||||
@ColumnInfo(name = "id")
|
||||
private long mId;
|
||||
@ColumnInfo(name = "account_id")
|
||||
private long mAccountId;
|
||||
|
||||
/**
|
||||
* The id of the seed used by this account
|
||||
* The cryptonet of the account
|
||||
*/
|
||||
@ColumnInfo(name = "seed_id")
|
||||
private long mSeedId;
|
||||
@ColumnInfo(name = "account_number", typeAffinity = INTEGER)
|
||||
private CryptoNet mCryptoNet;
|
||||
|
||||
/**
|
||||
* The account number on the bip44 or slip44
|
||||
*/
|
||||
@ColumnInfo(name = "account_number")
|
||||
private int mAccountNumber;
|
||||
|
||||
/**
|
||||
* The account index on this wallet
|
||||
*/
|
||||
@ColumnInfo(name = "account_index")
|
||||
private int mAccountIndex;
|
||||
|
||||
private CryptoCoin mCryptoCoin;
|
||||
|
||||
public long getId() {
|
||||
return mId;
|
||||
public long getAccountId() {
|
||||
return mAccountId;
|
||||
}
|
||||
|
||||
public void setId(long id) {
|
||||
this.mId = id;
|
||||
public CryptoNet getCryptoNet() {
|
||||
return mCryptoNet;
|
||||
}
|
||||
|
||||
public long getSeedId() {
|
||||
return mSeedId;
|
||||
public void setAccountId(long accountId) {
|
||||
this.mAccountId = accountId;
|
||||
}
|
||||
|
||||
public void setSeedId(long seedId) {
|
||||
this.mSeedId = seedId;
|
||||
}
|
||||
|
||||
public int getAccountNumber() {
|
||||
return mAccountNumber;
|
||||
}
|
||||
|
||||
public void setAccountNumber(int accountNumber) {
|
||||
this.mAccountNumber = accountNumber;
|
||||
}
|
||||
|
||||
public int getAccountIndex() {
|
||||
return mAccountIndex;
|
||||
}
|
||||
|
||||
public void setAccountIndex(int accountIndex) {
|
||||
this.mAccountIndex = accountIndex;
|
||||
}
|
||||
|
||||
public CryptoCoin getCryptoCoin() {
|
||||
return mCryptoCoin;
|
||||
}
|
||||
|
||||
public void setCryptoCoin(CryptoCoin cryptoCoin) {
|
||||
this.mCryptoCoin = cryptoCoin;
|
||||
public void setCryptoNet(CryptoNet cryptoNet) {
|
||||
this.mCryptoNet = cryptoNet;
|
||||
}
|
||||
|
||||
public static final DiffCallback<CryptoNetBalance> DIFF_CALLBACK = new DiffCallback<CryptoNetBalance>() {
|
||||
@Override
|
||||
public boolean areItemsTheSame(
|
||||
@NonNull CryptoNetBalance oldBalance, @NonNull CryptoNetBalance newBalance) {
|
||||
return oldBalance.getId() == newBalance.getId();
|
||||
return oldBalance.getAccountId() == newBalance.getAccountId();
|
||||
}
|
||||
@Override
|
||||
public boolean areContentsTheSame(
|
||||
|
@ -110,11 +71,7 @@ public class CryptoNetBalance {
|
|||
if (o == null || getClass() != o.getClass()) return false;
|
||||
|
||||
CryptoNetBalance that = (CryptoNetBalance) o;
|
||||
|
||||
if (mId != that.mId) return false;
|
||||
if (mSeedId != that.mSeedId) return false;
|
||||
if (mAccountNumber != that.mAccountNumber) return false;
|
||||
return mAccountIndex == that.mAccountIndex;
|
||||
return mAccountId == that.mAccountId;
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,9 +1,11 @@
|
|||
package cy.agorise.crystalwallet.randomdatagenerators;
|
||||
|
||||
import java.lang.reflect.Array;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Random;
|
||||
|
||||
import cy.agorise.crystalwallet.enums.CryptoNet;
|
||||
import cy.agorise.crystalwallet.models.AccountSeed;
|
||||
import cy.agorise.crystalwallet.models.CryptoNetAccount;
|
||||
|
||||
|
@ -17,12 +19,19 @@ public class RandomCryptoNetAccountGenerator {
|
|||
ArrayList<CryptoNetAccount> result = new ArrayList<CryptoNetAccount>();
|
||||
Random randomGenerator = new Random();
|
||||
CryptoNetAccount randomAccount;
|
||||
ArrayList<CryptoNet> cryptoNetList = new ArrayList<CryptoNet>();
|
||||
|
||||
for (CryptoNet cryptoNet : CryptoNet.values()){
|
||||
if (!cryptoNet.name().equals("UNKNOWN")) {
|
||||
cryptoNetList.add(cryptoNet);
|
||||
}
|
||||
}
|
||||
|
||||
for (int i=0;i<numberOfAccounts;i++){
|
||||
int randomSeedIndex = randomGenerator.nextInt(seeds.size());
|
||||
AccountSeed randomSelectedSeed = seeds.get(randomSeedIndex);
|
||||
int randomAccountNumber = cryptoNetList.get(randomGenerator.nextInt(cryptoNetList.size())).getBip44Index();
|
||||
int randomAccountIndex = randomGenerator.nextInt(1000);
|
||||
int randomAccountNumber = randomGenerator.nextInt(1000);
|
||||
|
||||
randomAccount = new CryptoNetAccount();
|
||||
randomAccount.setSeedId(randomSelectedSeed.getId());
|
||||
|
|
|
@ -23,7 +23,7 @@ public class CryptoCoinBalanceListViewModel extends AndroidViewModel {
|
|||
public CryptoCoinBalanceListViewModel(Application application, CryptoNetAccount account) {
|
||||
super(application);
|
||||
this.db = CrystalDatabase.getAppDatabase(application.getApplicationContext());
|
||||
this.cryptoCoinBalanceList = this.db.cryptoNetAccountDao().getBalancesFromAccount(account.getId());
|
||||
this.cryptoCoinBalanceList = this.db.cryptoCoinBalanceDao().getBalancesFromAccount(account.getId());
|
||||
}
|
||||
|
||||
public LiveData<List<CryptoCoinBalance>> getCryptoCoinBalanceList(){
|
||||
|
|
|
@ -22,7 +22,7 @@ public class CryptoNetBalanceListViewModel extends AndroidViewModel {
|
|||
public CryptoNetBalanceListViewModel(Application application) {
|
||||
super(application);
|
||||
this.db = CrystalDatabase.getAppDatabase(application.getApplicationContext());
|
||||
this.cryptoNetBalanceList = this.db.cryptoNetAccountDao().getAllBalances();
|
||||
this.cryptoNetBalanceList = this.db.cryptoCoinBalanceDao().getAllBalances();
|
||||
}
|
||||
|
||||
public LiveData<List<CryptoNetBalance>> getCryptoNetBalanceList(){
|
||||
|
|
|
@ -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 = 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){
|
||||
|
|
|
@ -16,14 +16,14 @@ import cy.agorise.crystalwallet.models.CryptoNetBalance;
|
|||
public class CryptoNetBalanceViewHolder extends RecyclerView.ViewHolder {
|
||||
private ImageView cryptoNetIcon;
|
||||
private TextView cryptoNetName;
|
||||
private CryptoNetBalanceListView cryptoNetBalanceListView;
|
||||
private CryptoCoinBalanceListView cryptoCoinBalanceListView;
|
||||
|
||||
|
||||
public CryptoNetBalanceViewHolder(View itemView) {
|
||||
super(itemView);
|
||||
cryptoNetIcon = (ImageView) itemView.findViewById(R.id.ivCryptoNetIcon);
|
||||
cryptoNetName = (TextView) itemView.findViewById(R.id.tvCryptoNetName);
|
||||
cryptoNetBalanceListView = (CryptoNetBalanceListView) itemView.findViewById(R.id.cryptoCoinBalanceListView);
|
||||
cryptoCoinBalanceListView = (CryptoCoinBalanceListView) itemView.findViewById(R.id.cryptoCoinBalanceListView);
|
||||
|
||||
}
|
||||
|
||||
|
@ -35,7 +35,7 @@ public class CryptoNetBalanceViewHolder extends RecyclerView.ViewHolder {
|
|||
if (balance == null){
|
||||
cryptoNetName.setText("loading...");
|
||||
} else {
|
||||
cryptoNetName.setText(balance.getCryptoCoin().getLabel());
|
||||
cryptoNetName.setText(balance.getCryptoNet().getLabel());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -6,6 +6,7 @@
|
|||
|
||||
<cy.agorise.crystalwallet.views.CryptoNetBalanceListView
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content" />
|
||||
android:layout_height="wrap_content"
|
||||
android:id="@+id/vCryptoNetBalanceListView" />
|
||||
|
||||
</FrameLayout>
|
||||
|
|
Loading…
Reference in a new issue