From 3d9357bcdf23cd643816af4233fa85e74ecb2b34 Mon Sep 17 00:00:00 2001 From: Javier Varona Date: Wed, 11 Oct 2017 22:08:42 -0400 Subject: [PATCH] - Adding balances views --- .../crystalwallet/dao/AccountSeedDao.java | 1 + .../dao/CryptoNetAccountDao.java | 10 ++ .../models/CryptoCoinBalance.java | 69 ++++++++++ .../models/CryptoNetAccount.java | 1 + .../models/CryptoNetBalance.java | 120 ++++++++++++++++++ .../CryptoCoinBalanceListViewModel.java | 32 +++++ .../CryptoNetBalanceListViewModel.java | 31 +++++ .../views/BalanceViewHolder.java | 51 -------- .../views/CryptoCoinBalanceListAdapter.java | 2 + .../views/CryptoCoinBalanceListView.java | 6 +- .../views/CryptoCoinBalanceViewHolder.java | 31 ++--- ....java => CryptoNetBalanceListAdapter.java} | 13 +- ...iew.java => CryptoNetBalanceListView.java} | 21 +-- .../views/CryptoNetBalanceViewHolder.java | 41 ++++++ .../views/TransactionListView.java | 4 +- app/src/main/res/layout/balance_list_item.xml | 5 + app/src/main/res/layout/fragment_balance.xml | 7 +- 17 files changed, 350 insertions(+), 95 deletions(-) create mode 100644 app/src/main/java/cy/agorise/crystalwallet/models/CryptoCoinBalance.java create mode 100644 app/src/main/java/cy/agorise/crystalwallet/models/CryptoNetBalance.java create mode 100644 app/src/main/java/cy/agorise/crystalwallet/viewmodels/CryptoCoinBalanceListViewModel.java create mode 100644 app/src/main/java/cy/agorise/crystalwallet/viewmodels/CryptoNetBalanceListViewModel.java delete mode 100644 app/src/main/java/cy/agorise/crystalwallet/views/BalanceViewHolder.java rename app/src/main/java/cy/agorise/crystalwallet/views/{BalanceListAdapter.java => CryptoNetBalanceListAdapter.java} (54%) rename app/src/main/java/cy/agorise/crystalwallet/views/{BalanceListView.java => CryptoNetBalanceListView.java} (71%) create mode 100644 app/src/main/java/cy/agorise/crystalwallet/views/CryptoNetBalanceViewHolder.java diff --git a/app/src/main/java/cy/agorise/crystalwallet/dao/AccountSeedDao.java b/app/src/main/java/cy/agorise/crystalwallet/dao/AccountSeedDao.java index f3e4433..40cacbf 100644 --- a/app/src/main/java/cy/agorise/crystalwallet/dao/AccountSeedDao.java +++ b/app/src/main/java/cy/agorise/crystalwallet/dao/AccountSeedDao.java @@ -10,6 +10,7 @@ import android.arch.persistence.room.Query; import java.util.List; import cy.agorise.crystalwallet.models.AccountSeed; +import cy.agorise.crystalwallet.models.CryptoNetBalance; /** * Created by Henry Varona on 10/9/2017. 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 ee072ea..2368408 100644 --- a/app/src/main/java/cy/agorise/crystalwallet/dao/CryptoNetAccountDao.java +++ b/app/src/main/java/cy/agorise/crystalwallet/dao/CryptoNetAccountDao.java @@ -1,5 +1,6 @@ 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; @@ -8,7 +9,9 @@ import android.arch.persistence.room.Query; import java.util.List; import cy.agorise.crystalwallet.models.AccountSeed; +import cy.agorise.crystalwallet.models.CryptoCoinBalance; import cy.agorise.crystalwallet.models.CryptoNetAccount; +import cy.agorise.crystalwallet.models.CryptoNetBalance; /** * Created by Henry Varona on 10/9/2017. @@ -20,6 +23,13 @@ public interface CryptoNetAccountDao { @Query("SELECT * FROM crypto_net_account") List getAll(); + @Query("SELECT * FROM crypto_net_account") + LiveData> getAllBalances(); + + @Query("SELECT 'Bitshares' as coin, 1 as balance FROM crypto_net_account WHERE id = :accountId") + LiveData> getBalancesFromAccount(long accountId); + + @Insert(onConflict = OnConflictStrategy.REPLACE) public long[] insertCryptoNetAccount(CryptoNetAccount... accounts); diff --git a/app/src/main/java/cy/agorise/crystalwallet/models/CryptoCoinBalance.java b/app/src/main/java/cy/agorise/crystalwallet/models/CryptoCoinBalance.java new file mode 100644 index 0000000..56695f5 --- /dev/null +++ b/app/src/main/java/cy/agorise/crystalwallet/models/CryptoCoinBalance.java @@ -0,0 +1,69 @@ +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; +import android.arch.persistence.room.PrimaryKey; +import android.support.annotation.NonNull; +import android.support.v7.recyclerview.extensions.DiffCallback; + +import cy.agorise.crystalwallet.enums.CryptoCoin; + +/** + * Represents a balance of a specific asset from a CryptoNet + * + * Created by Henry Varona on 6/9/2017. + */ + +@Entity +public class CryptoCoinBalance { + + @ColumnInfo(name = "coin") + private CryptoCoin mCoin; + + @ColumnInfo(name = "balance") + private int mBalance; + + public CryptoCoin getCoin() { + return mCoin; + } + + public void setCoin(CryptoCoin coin) { + this.mCoin = coin; + } + + public int getBalance() { + return mBalance; + } + + public void setBalance(int balance) { + this.mBalance = balance; + } + + public static final DiffCallback DIFF_CALLBACK = new DiffCallback() { + @Override + public boolean areItemsTheSame( + @NonNull CryptoCoinBalance oldBalance, @NonNull CryptoCoinBalance newBalance) { + return oldBalance.getCoin() == newBalance.getCoin(); + } + @Override + public boolean areContentsTheSame( + @NonNull CryptoCoinBalance oldBalance, @NonNull CryptoCoinBalance newBalance) { + return oldBalance.equals(newBalance); + } + }; + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + + CryptoCoinBalance that = (CryptoCoinBalance) o; + + if (this.mCoin != that.mCoin) return false; + return mBalance == that.mBalance; + + } +} 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 21cabb0..df6238d 100644 --- a/app/src/main/java/cy/agorise/crystalwallet/models/CryptoNetAccount.java +++ b/app/src/main/java/cy/agorise/crystalwallet/models/CryptoNetAccount.java @@ -76,4 +76,5 @@ public class CryptoNetAccount { public void setAccountIndex(int mAccountIndex) { this.mAccountIndex = mAccountIndex; } + } diff --git a/app/src/main/java/cy/agorise/crystalwallet/models/CryptoNetBalance.java b/app/src/main/java/cy/agorise/crystalwallet/models/CryptoNetBalance.java new file mode 100644 index 0000000..af05fc5 --- /dev/null +++ b/app/src/main/java/cy/agorise/crystalwallet/models/CryptoNetBalance.java @@ -0,0 +1,120 @@ +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; +import android.arch.persistence.room.PrimaryKey; +import android.support.annotation.NonNull; +import android.support.v7.recyclerview.extensions.DiffCallback; + +import cy.agorise.crystalwallet.enums.CryptoCoin; + +/** + * Represents a geneeric 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")) +public class CryptoNetBalance { + + /** + * The id on the database + */ + @PrimaryKey(autoGenerate = true) + @ColumnInfo(name = "id") + private long mId; + + /** + * The id of the seed used by this account + */ + @ColumnInfo(name = "seed_id") + private long mSeedId; + + /** + * 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 void setId(long id) { + this.mId = id; + } + + public long getSeedId() { + return mSeedId; + } + + 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 static final DiffCallback DIFF_CALLBACK = new DiffCallback() { + @Override + public boolean areItemsTheSame( + @NonNull CryptoNetBalance oldBalance, @NonNull CryptoNetBalance newBalance) { + return oldBalance.getId() == newBalance.getId(); + } + @Override + public boolean areContentsTheSame( + @NonNull CryptoNetBalance oldBalance, @NonNull CryptoNetBalance newBalance) { + return oldBalance.equals(newBalance); + } + }; + + @Override + public boolean equals(Object o) { + if (this == o) return true; + 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; + + } +} diff --git a/app/src/main/java/cy/agorise/crystalwallet/viewmodels/CryptoCoinBalanceListViewModel.java b/app/src/main/java/cy/agorise/crystalwallet/viewmodels/CryptoCoinBalanceListViewModel.java new file mode 100644 index 0000000..5b7deef --- /dev/null +++ b/app/src/main/java/cy/agorise/crystalwallet/viewmodels/CryptoCoinBalanceListViewModel.java @@ -0,0 +1,32 @@ +package cy.agorise.crystalwallet.viewmodels; + +import android.app.Application; +import android.arch.lifecycle.AndroidViewModel; +import android.arch.lifecycle.LiveData; + +import java.util.List; + +import cy.agorise.crystalwallet.dao.CrystalDatabase; +import cy.agorise.crystalwallet.models.CryptoCoinBalance; +import cy.agorise.crystalwallet.models.CryptoNetAccount; +import cy.agorise.crystalwallet.models.CryptoNetBalance; + +/** + * Created by Henry Varona on 27/9/2017. + */ + +public class CryptoCoinBalanceListViewModel extends AndroidViewModel { + + private LiveData> cryptoCoinBalanceList; + private CrystalDatabase db; + + public CryptoCoinBalanceListViewModel(Application application, CryptoNetAccount account) { + super(application); + this.db = CrystalDatabase.getAppDatabase(application.getApplicationContext()); + this.cryptoCoinBalanceList = this.db.cryptoNetAccountDao().getBalancesFromAccount(account.getId()); + } + + public LiveData> getCryptoCoinBalanceList(){ + return this.cryptoCoinBalanceList; + } +} diff --git a/app/src/main/java/cy/agorise/crystalwallet/viewmodels/CryptoNetBalanceListViewModel.java b/app/src/main/java/cy/agorise/crystalwallet/viewmodels/CryptoNetBalanceListViewModel.java new file mode 100644 index 0000000..a2f7785 --- /dev/null +++ b/app/src/main/java/cy/agorise/crystalwallet/viewmodels/CryptoNetBalanceListViewModel.java @@ -0,0 +1,31 @@ +package cy.agorise.crystalwallet.viewmodels; + +import android.app.Application; +import android.arch.lifecycle.AndroidViewModel; +import android.arch.lifecycle.LiveData; + +import java.util.List; + +import cy.agorise.crystalwallet.dao.CrystalDatabase; +import cy.agorise.crystalwallet.models.AccountSeed; +import cy.agorise.crystalwallet.models.CryptoNetBalance; + +/** + * Created by Henry Varona on 27/9/2017. + */ + +public class CryptoNetBalanceListViewModel extends AndroidViewModel { + + private LiveData> cryptoNetBalanceList; + private CrystalDatabase db; + + public CryptoNetBalanceListViewModel(Application application) { + super(application); + this.db = CrystalDatabase.getAppDatabase(application.getApplicationContext()); + this.cryptoNetBalanceList = this.db.cryptoNetAccountDao().getAllBalances(); + } + + public LiveData> getCryptoNetBalanceList(){ + return this.cryptoNetBalanceList; + } +} diff --git a/app/src/main/java/cy/agorise/crystalwallet/views/BalanceViewHolder.java b/app/src/main/java/cy/agorise/crystalwallet/views/BalanceViewHolder.java deleted file mode 100644 index f7cec99..0000000 --- a/app/src/main/java/cy/agorise/crystalwallet/views/BalanceViewHolder.java +++ /dev/null @@ -1,51 +0,0 @@ -package cy.agorise.crystalwallet.views; - -import android.support.v7.widget.RecyclerView; -import android.view.View; -import android.widget.TextView; - -import cy.agorise.crystalwallet.R; -import cy.agorise.crystalwallet.models.CryptoCoinTransaction; - -/** - * Created by Henry Varona on 17/9/2017. - */ - -public class BalanceViewHolder extends RecyclerView.ViewHolder { - private TextView cryptoNetIcon; - private TextView cryptoNetName; - private CryptoNetBalanceListView cryptoNetBalanceListView; - - - public BalanceViewHolder(View itemView) { - super(itemView); - transactionFrom = (TextView) itemView.findViewById(R.id.fromText); - transactionTo = (TextView) itemView.findViewById(R.id.toText); - transactionAmount = (TextView) itemView.findViewById(R.id.amountText); - - } - - public void clear(){ - transactionFrom.setText("loading..."); - transactionTo.setText(""); - transactionAmount.setText(""); - } - - public void bindTo(final CryptoCoinTransaction transaction/*, final OnTransactionClickListener listener*/) { - if (transaction == null){ - transactionFrom.setText("loading..."); - transactionTo.setText(""); - transactionAmount.setText(""); - } else { - transactionFrom.setText(transaction.getFrom()); - transactionTo.setText(transaction.getTo()); - transactionAmount.setText("" + transaction.getAmount()); - /*itemView.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View v) { - listener.onUserClick(user); - } - });*/ - } - } -} diff --git a/app/src/main/java/cy/agorise/crystalwallet/views/CryptoCoinBalanceListAdapter.java b/app/src/main/java/cy/agorise/crystalwallet/views/CryptoCoinBalanceListAdapter.java index 5d6cbd7..538f72a 100644 --- a/app/src/main/java/cy/agorise/crystalwallet/views/CryptoCoinBalanceListAdapter.java +++ b/app/src/main/java/cy/agorise/crystalwallet/views/CryptoCoinBalanceListAdapter.java @@ -1,11 +1,13 @@ package cy.agorise.crystalwallet.views; +import android.support.v7.recyclerview.extensions.ListAdapter; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import cy.agorise.crystalwallet.R; +import cy.agorise.crystalwallet.models.CryptoCoinBalance; /** * Created by Henry Varona on 11/9/2017. 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 3de987d..a30f68a 100644 --- a/app/src/main/java/cy/agorise/crystalwallet/views/CryptoCoinBalanceListView.java +++ b/app/src/main/java/cy/agorise/crystalwallet/views/CryptoCoinBalanceListView.java @@ -8,7 +8,11 @@ import android.view.LayoutInflater; import android.view.View; import android.widget.RelativeLayout; +import java.util.List; + import cy.agorise.crystalwallet.R; +import cy.agorise.crystalwallet.models.CryptoCoinBalance; +import cy.agorise.crystalwallet.viewmodels.CryptoCoinBalanceListViewModel; /** * Created by Henry Varona on 10/9/2017. @@ -22,7 +26,7 @@ public class CryptoCoinBalanceListView extends RelativeLayout { RecyclerView listView; CryptoCoinBalanceListAdapter listAdapter; - CryptoCoinBalanceListViewModel CryptoCoinBalanceListViewModel; + CryptoCoinBalanceListViewModel cryptoCoinBalanceListViewModel; private int visibleThreshold = 5; private boolean loading = true; 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 a9555f2..a88bfc7 100644 --- a/app/src/main/java/cy/agorise/crystalwallet/views/CryptoCoinBalanceViewHolder.java +++ b/app/src/main/java/cy/agorise/crystalwallet/views/CryptoCoinBalanceViewHolder.java @@ -5,6 +5,7 @@ import android.view.View; import android.widget.TextView; import cy.agorise.crystalwallet.R; +import cy.agorise.crystalwallet.models.CryptoCoinBalance; import cy.agorise.crystalwallet.models.CryptoCoinTransaction; /** @@ -17,33 +18,23 @@ public class CryptoCoinBalanceViewHolder extends RecyclerView.ViewHolder { public CryptoCoinBalanceViewHolder(View itemView) { super(itemView); - transactionFrom = (TextView) itemView.findViewById(R.id.fromText); - transactionTo = (TextView) itemView.findViewById(R.id.toText); - transactionAmount = (TextView) itemView.findViewById(R.id.amountText); + cryptoCoinName = (TextView) itemView.findViewById(R.id.tvCryptoCoinName); + cryptoCoinBalance = (TextView) itemView.findViewById(R.id.tvCryptoCoinBalanceAmount); } public void clear(){ - transactionFrom.setText("loading..."); - transactionTo.setText(""); - transactionAmount.setText(""); + cryptoCoinName.setText("loading..."); + cryptoCoinBalance.setText(""); } - public void bindTo(final CryptoCoinTransaction transaction/*, final OnTransactionClickListener listener*/) { - if (transaction == null){ - transactionFrom.setText("loading..."); - transactionTo.setText(""); - transactionAmount.setText(""); + public void bindTo(final CryptoCoinBalance balance/*, final OnTransactionClickListener listener*/) { + if (balance == null){ + cryptoCoinName.setText("loading..."); + cryptoCoinBalance.setText(""); } else { - transactionFrom.setText(transaction.getFrom()); - transactionTo.setText(transaction.getTo()); - transactionAmount.setText("" + transaction.getAmount()); - /*itemView.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View v) { - listener.onUserClick(user); - } - });*/ + cryptoCoinName.setText(balance.getCoin().getLabel()); + cryptoCoinBalance.setText(balance.getBalance()); } } } diff --git a/app/src/main/java/cy/agorise/crystalwallet/views/BalanceListAdapter.java b/app/src/main/java/cy/agorise/crystalwallet/views/CryptoNetBalanceListAdapter.java similarity index 54% rename from app/src/main/java/cy/agorise/crystalwallet/views/BalanceListAdapter.java rename to app/src/main/java/cy/agorise/crystalwallet/views/CryptoNetBalanceListAdapter.java index f430b16..b0e013f 100644 --- a/app/src/main/java/cy/agorise/crystalwallet/views/BalanceListAdapter.java +++ b/app/src/main/java/cy/agorise/crystalwallet/views/CryptoNetBalanceListAdapter.java @@ -1,33 +1,34 @@ package cy.agorise.crystalwallet.views; -import android.arch.paging.PagedListAdapter; +import android.support.v7.recyclerview.extensions.ListAdapter; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import cy.agorise.crystalwallet.R; +import cy.agorise.crystalwallet.models.CryptoNetBalance; /** * Created by Henry Varona on 11/9/2017. */ -public class BalanceListAdapter extends ListAdapter { +public class CryptoNetBalanceListAdapter extends ListAdapter { - public BalanceListAdapter() { + public CryptoNetBalanceListAdapter() { super(CryptoNetBalance.DIFF_CALLBACK); } @Override - public BalanceViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { + public CryptoNetBalanceViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { View v = LayoutInflater.from(parent.getContext()).inflate(R.layout.balance_list_item,parent,false); - return new BalanceViewHolder(v); + return new CryptoNetBalanceViewHolder(v); } @Override - public void onBindViewHolder(BalanceViewHolder holder, int position) { + public void onBindViewHolder(CryptoNetBalanceViewHolder holder, int position) { CryptoNetBalance balance = getItem(position); if (balance != null) { holder.bindTo(balance); diff --git a/app/src/main/java/cy/agorise/crystalwallet/views/BalanceListView.java b/app/src/main/java/cy/agorise/crystalwallet/views/CryptoNetBalanceListView.java similarity index 71% rename from app/src/main/java/cy/agorise/crystalwallet/views/BalanceListView.java rename to app/src/main/java/cy/agorise/crystalwallet/views/CryptoNetBalanceListView.java index 72c86ce..50c137d 100644 --- a/app/src/main/java/cy/agorise/crystalwallet/views/BalanceListView.java +++ b/app/src/main/java/cy/agorise/crystalwallet/views/CryptoNetBalanceListView.java @@ -1,6 +1,5 @@ package cy.agorise.crystalwallet.views; -import android.arch.paging.PagedList; import android.content.Context; import android.support.v7.widget.LinearLayoutManager; import android.support.v7.widget.RecyclerView; @@ -9,40 +8,42 @@ import android.view.LayoutInflater; import android.view.View; import android.widget.RelativeLayout; +import java.util.List; + import cy.agorise.crystalwallet.R; -import cy.agorise.crystalwallet.models.CryptoCoinTransaction; -import cy.agorise.crystalwallet.viewmodels.TransactionListViewModel; +import cy.agorise.crystalwallet.models.CryptoNetBalance; +import cy.agorise.crystalwallet.viewmodels.CryptoNetBalanceListViewModel; /** * Created by Henry Varona on 10/9/2017. */ -public class BalanceListView extends RelativeLayout { +public class CryptoNetBalanceListView extends RelativeLayout { LayoutInflater mInflater; View rootView; RecyclerView listView; - BalanceListAdapter listAdapter; + CryptoNetBalanceListAdapter listAdapter; - BalanceListViewModel balanceListViewModel; + CryptoNetBalanceListViewModel cryptoNetBalanceListViewModel; private int visibleThreshold = 5; private boolean loading = true; - public BalanceListView(Context context){ + public CryptoNetBalanceListView(Context context){ super(context); this.mInflater = LayoutInflater.from(context); init(); } - public BalanceListView(Context context, AttributeSet attrs) { + public CryptoNetBalanceListView(Context context, AttributeSet attrs) { super(context, attrs); this.mInflater = LayoutInflater.from(context); init(); } - public BalanceListView(Context context, AttributeSet attrs, int defStyle){ + public CryptoNetBalanceListView(Context context, AttributeSet attrs, int defStyle){ super(context, attrs, defStyle); this.mInflater = LayoutInflater.from(context); init(); @@ -59,7 +60,7 @@ public class BalanceListView extends RelativeLayout { public void setData(List data){ if (this.listAdapter == null) { - this.listAdapter = new BalanceListAdapter(); + this.listAdapter = new CryptoNetBalanceListAdapter(); this.listView.setAdapter(this.listAdapter); } diff --git a/app/src/main/java/cy/agorise/crystalwallet/views/CryptoNetBalanceViewHolder.java b/app/src/main/java/cy/agorise/crystalwallet/views/CryptoNetBalanceViewHolder.java new file mode 100644 index 0000000..9b99f94 --- /dev/null +++ b/app/src/main/java/cy/agorise/crystalwallet/views/CryptoNetBalanceViewHolder.java @@ -0,0 +1,41 @@ +package cy.agorise.crystalwallet.views; + +import android.support.v7.widget.RecyclerView; +import android.view.View; +import android.widget.ImageView; +import android.widget.TextView; + +import cy.agorise.crystalwallet.R; +import cy.agorise.crystalwallet.models.CryptoCoinTransaction; +import cy.agorise.crystalwallet.models.CryptoNetBalance; + +/** + * Created by Henry Varona on 17/9/2017. + */ + +public class CryptoNetBalanceViewHolder extends RecyclerView.ViewHolder { + private ImageView cryptoNetIcon; + private TextView cryptoNetName; + private CryptoNetBalanceListView cryptoNetBalanceListView; + + + 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); + + } + + public void clear(){ + cryptoNetName.setText("loading..."); + } + + public void bindTo(final CryptoNetBalance balance) { + if (balance == null){ + cryptoNetName.setText("loading..."); + } else { + cryptoNetName.setText(balance.getCryptoCoin().getLabel()); + } + } +} diff --git a/app/src/main/java/cy/agorise/crystalwallet/views/TransactionListView.java b/app/src/main/java/cy/agorise/crystalwallet/views/TransactionListView.java index 95f7f9b..1e7f0b1 100644 --- a/app/src/main/java/cy/agorise/crystalwallet/views/TransactionListView.java +++ b/app/src/main/java/cy/agorise/crystalwallet/views/TransactionListView.java @@ -23,7 +23,7 @@ public class TransactionListView extends RelativeLayout { View rootView; RecyclerView listView; - BalanceListAdapter listAdapter; + TransactionListAdapter listAdapter; TransactionListViewModel transactionListViewModel; @@ -76,7 +76,7 @@ public class TransactionListView extends RelativeLayout { public void setData(PagedList data){ if (this.listAdapter == null) { - this.listAdapter = new BalanceListAdapter(); + this.listAdapter = new TransactionListAdapter(); this.listView.setAdapter(this.listAdapter); } diff --git a/app/src/main/res/layout/balance_list_item.xml b/app/src/main/res/layout/balance_list_item.xml index 2d7fb8d..2315275 100644 --- a/app/src/main/res/layout/balance_list_item.xml +++ b/app/src/main/res/layout/balance_list_item.xml @@ -32,7 +32,12 @@ android:ems="10" android:text="unknown coin" /> + + diff --git a/app/src/main/res/layout/fragment_balance.xml b/app/src/main/res/layout/fragment_balance.xml index af891c5..b0a37b0 100644 --- a/app/src/main/res/layout/fragment_balance.xml +++ b/app/src/main/res/layout/fragment_balance.xml @@ -4,11 +4,8 @@ android:layout_height="match_parent" tools:context="cy.agorise.crystalwallet.fragments.BalanceFragment"> - - + android:layout_height="wrap_content" />