- Adding balances views

This commit is contained in:
Javier Varona 2017-10-11 22:08:42 -04:00
parent 9670d23dc1
commit 3d9357bcdf
17 changed files with 350 additions and 95 deletions

View file

@ -10,6 +10,7 @@ import android.arch.persistence.room.Query;
import java.util.List; import java.util.List;
import cy.agorise.crystalwallet.models.AccountSeed; import cy.agorise.crystalwallet.models.AccountSeed;
import cy.agorise.crystalwallet.models.CryptoNetBalance;
/** /**
* Created by Henry Varona on 10/9/2017. * Created by Henry Varona on 10/9/2017.

View file

@ -1,5 +1,6 @@
package cy.agorise.crystalwallet.dao; package cy.agorise.crystalwallet.dao;
import android.arch.lifecycle.LiveData;
import android.arch.persistence.room.Dao; import android.arch.persistence.room.Dao;
import android.arch.persistence.room.Insert; import android.arch.persistence.room.Insert;
import android.arch.persistence.room.OnConflictStrategy; import android.arch.persistence.room.OnConflictStrategy;
@ -8,7 +9,9 @@ import android.arch.persistence.room.Query;
import java.util.List; import java.util.List;
import cy.agorise.crystalwallet.models.AccountSeed; import cy.agorise.crystalwallet.models.AccountSeed;
import cy.agorise.crystalwallet.models.CryptoCoinBalance;
import cy.agorise.crystalwallet.models.CryptoNetAccount; import cy.agorise.crystalwallet.models.CryptoNetAccount;
import cy.agorise.crystalwallet.models.CryptoNetBalance;
/** /**
* Created by Henry Varona on 10/9/2017. * Created by Henry Varona on 10/9/2017.
@ -20,6 +23,13 @@ public interface CryptoNetAccountDao {
@Query("SELECT * FROM crypto_net_account") @Query("SELECT * FROM crypto_net_account")
List<CryptoNetAccount> getAll(); 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) @Insert(onConflict = OnConflictStrategy.REPLACE)
public long[] insertCryptoNetAccount(CryptoNetAccount... accounts); public long[] insertCryptoNetAccount(CryptoNetAccount... accounts);

View file

@ -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<CryptoCoinBalance> DIFF_CALLBACK = new DiffCallback<CryptoCoinBalance>() {
@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;
}
}

View file

@ -76,4 +76,5 @@ public class CryptoNetAccount {
public void setAccountIndex(int mAccountIndex) { public void setAccountIndex(int mAccountIndex) {
this.mAccountIndex = mAccountIndex; this.mAccountIndex = mAccountIndex;
} }
} }

View file

@ -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<CryptoNetBalance> DIFF_CALLBACK = new DiffCallback<CryptoNetBalance>() {
@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;
}
}

View file

@ -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<List<CryptoCoinBalance>> 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<List<CryptoCoinBalance>> getCryptoCoinBalanceList(){
return this.cryptoCoinBalanceList;
}
}

View file

@ -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<List<CryptoNetBalance>> cryptoNetBalanceList;
private CrystalDatabase db;
public CryptoNetBalanceListViewModel(Application application) {
super(application);
this.db = CrystalDatabase.getAppDatabase(application.getApplicationContext());
this.cryptoNetBalanceList = this.db.cryptoNetAccountDao().getAllBalances();
}
public LiveData<List<CryptoNetBalance>> getCryptoNetBalanceList(){
return this.cryptoNetBalanceList;
}
}

View file

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

View file

@ -1,11 +1,13 @@
package cy.agorise.crystalwallet.views; package cy.agorise.crystalwallet.views;
import android.support.v7.recyclerview.extensions.ListAdapter;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.View; import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
import cy.agorise.crystalwallet.R; import cy.agorise.crystalwallet.R;
import cy.agorise.crystalwallet.models.CryptoCoinBalance;
/** /**
* Created by Henry Varona on 11/9/2017. * Created by Henry Varona on 11/9/2017.

View file

@ -8,7 +8,11 @@ import android.view.LayoutInflater;
import android.view.View; import android.view.View;
import android.widget.RelativeLayout; import android.widget.RelativeLayout;
import java.util.List;
import cy.agorise.crystalwallet.R; 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. * Created by Henry Varona on 10/9/2017.
@ -22,7 +26,7 @@ public class CryptoCoinBalanceListView extends RelativeLayout {
RecyclerView listView; RecyclerView listView;
CryptoCoinBalanceListAdapter listAdapter; CryptoCoinBalanceListAdapter listAdapter;
CryptoCoinBalanceListViewModel CryptoCoinBalanceListViewModel; CryptoCoinBalanceListViewModel cryptoCoinBalanceListViewModel;
private int visibleThreshold = 5; private int visibleThreshold = 5;
private boolean loading = true; private boolean loading = true;

View file

@ -5,6 +5,7 @@ import android.view.View;
import android.widget.TextView; import android.widget.TextView;
import cy.agorise.crystalwallet.R; import cy.agorise.crystalwallet.R;
import cy.agorise.crystalwallet.models.CryptoCoinBalance;
import cy.agorise.crystalwallet.models.CryptoCoinTransaction; import cy.agorise.crystalwallet.models.CryptoCoinTransaction;
/** /**
@ -17,33 +18,23 @@ public class CryptoCoinBalanceViewHolder extends RecyclerView.ViewHolder {
public CryptoCoinBalanceViewHolder(View itemView) { public CryptoCoinBalanceViewHolder(View itemView) {
super(itemView); super(itemView);
transactionFrom = (TextView) itemView.findViewById(R.id.fromText); cryptoCoinName = (TextView) itemView.findViewById(R.id.tvCryptoCoinName);
transactionTo = (TextView) itemView.findViewById(R.id.toText); cryptoCoinBalance = (TextView) itemView.findViewById(R.id.tvCryptoCoinBalanceAmount);
transactionAmount = (TextView) itemView.findViewById(R.id.amountText);
} }
public void clear(){ public void clear(){
transactionFrom.setText("loading..."); cryptoCoinName.setText("loading...");
transactionTo.setText(""); cryptoCoinBalance.setText("");
transactionAmount.setText("");
} }
public void bindTo(final CryptoCoinTransaction transaction/*, final OnTransactionClickListener listener*/) { public void bindTo(final CryptoCoinBalance balance/*, final OnTransactionClickListener listener*/) {
if (transaction == null){ if (balance == null){
transactionFrom.setText("loading..."); cryptoCoinName.setText("loading...");
transactionTo.setText(""); cryptoCoinBalance.setText("");
transactionAmount.setText("");
} else { } else {
transactionFrom.setText(transaction.getFrom()); cryptoCoinName.setText(balance.getCoin().getLabel());
transactionTo.setText(transaction.getTo()); cryptoCoinBalance.setText(balance.getBalance());
transactionAmount.setText("" + transaction.getAmount());
/*itemView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
listener.onUserClick(user);
}
});*/
} }
} }
} }

View file

@ -1,33 +1,34 @@
package cy.agorise.crystalwallet.views; package cy.agorise.crystalwallet.views;
import android.arch.paging.PagedListAdapter; import android.support.v7.recyclerview.extensions.ListAdapter;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.View; import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
import cy.agorise.crystalwallet.R; import cy.agorise.crystalwallet.R;
import cy.agorise.crystalwallet.models.CryptoNetBalance;
/** /**
* Created by Henry Varona on 11/9/2017. * Created by Henry Varona on 11/9/2017.
*/ */
public class BalanceListAdapter extends ListAdapter<CryptoNetBalance, BalanceViewHolder> { public class CryptoNetBalanceListAdapter extends ListAdapter<CryptoNetBalance, CryptoNetBalanceViewHolder> {
public BalanceListAdapter() { public CryptoNetBalanceListAdapter() {
super(CryptoNetBalance.DIFF_CALLBACK); super(CryptoNetBalance.DIFF_CALLBACK);
} }
@Override @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); View v = LayoutInflater.from(parent.getContext()).inflate(R.layout.balance_list_item,parent,false);
return new BalanceViewHolder(v); return new CryptoNetBalanceViewHolder(v);
} }
@Override @Override
public void onBindViewHolder(BalanceViewHolder holder, int position) { public void onBindViewHolder(CryptoNetBalanceViewHolder holder, int position) {
CryptoNetBalance balance = getItem(position); CryptoNetBalance balance = getItem(position);
if (balance != null) { if (balance != null) {
holder.bindTo(balance); holder.bindTo(balance);

View file

@ -1,6 +1,5 @@
package cy.agorise.crystalwallet.views; package cy.agorise.crystalwallet.views;
import android.arch.paging.PagedList;
import android.content.Context; import android.content.Context;
import android.support.v7.widget.LinearLayoutManager; import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView; import android.support.v7.widget.RecyclerView;
@ -9,40 +8,42 @@ import android.view.LayoutInflater;
import android.view.View; import android.view.View;
import android.widget.RelativeLayout; import android.widget.RelativeLayout;
import java.util.List;
import cy.agorise.crystalwallet.R; import cy.agorise.crystalwallet.R;
import cy.agorise.crystalwallet.models.CryptoCoinTransaction; import cy.agorise.crystalwallet.models.CryptoNetBalance;
import cy.agorise.crystalwallet.viewmodels.TransactionListViewModel; import cy.agorise.crystalwallet.viewmodels.CryptoNetBalanceListViewModel;
/** /**
* Created by Henry Varona on 10/9/2017. * Created by Henry Varona on 10/9/2017.
*/ */
public class BalanceListView extends RelativeLayout { public class CryptoNetBalanceListView extends RelativeLayout {
LayoutInflater mInflater; LayoutInflater mInflater;
View rootView; View rootView;
RecyclerView listView; RecyclerView listView;
BalanceListAdapter listAdapter; CryptoNetBalanceListAdapter listAdapter;
BalanceListViewModel balanceListViewModel; CryptoNetBalanceListViewModel cryptoNetBalanceListViewModel;
private int visibleThreshold = 5; private int visibleThreshold = 5;
private boolean loading = true; private boolean loading = true;
public BalanceListView(Context context){ public CryptoNetBalanceListView(Context context){
super(context); super(context);
this.mInflater = LayoutInflater.from(context); this.mInflater = LayoutInflater.from(context);
init(); init();
} }
public BalanceListView(Context context, AttributeSet attrs) { public CryptoNetBalanceListView(Context context, AttributeSet attrs) {
super(context, attrs); super(context, attrs);
this.mInflater = LayoutInflater.from(context); this.mInflater = LayoutInflater.from(context);
init(); init();
} }
public BalanceListView(Context context, AttributeSet attrs, int defStyle){ public CryptoNetBalanceListView(Context context, AttributeSet attrs, int defStyle){
super(context, attrs, defStyle); super(context, attrs, defStyle);
this.mInflater = LayoutInflater.from(context); this.mInflater = LayoutInflater.from(context);
init(); init();
@ -59,7 +60,7 @@ public class BalanceListView extends RelativeLayout {
public void setData(List<CryptoNetBalance> data){ public void setData(List<CryptoNetBalance> data){
if (this.listAdapter == null) { if (this.listAdapter == null) {
this.listAdapter = new BalanceListAdapter(); this.listAdapter = new CryptoNetBalanceListAdapter();
this.listView.setAdapter(this.listAdapter); this.listView.setAdapter(this.listAdapter);
} }

View file

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

View file

@ -23,7 +23,7 @@ public class TransactionListView extends RelativeLayout {
View rootView; View rootView;
RecyclerView listView; RecyclerView listView;
BalanceListAdapter listAdapter; TransactionListAdapter listAdapter;
TransactionListViewModel transactionListViewModel; TransactionListViewModel transactionListViewModel;
@ -76,7 +76,7 @@ public class TransactionListView extends RelativeLayout {
public void setData(PagedList<CryptoCoinTransaction> data){ public void setData(PagedList<CryptoCoinTransaction> data){
if (this.listAdapter == null) { if (this.listAdapter == null) {
this.listAdapter = new BalanceListAdapter(); this.listAdapter = new TransactionListAdapter();
this.listView.setAdapter(this.listAdapter); this.listView.setAdapter(this.listAdapter);
} }

View file

@ -32,7 +32,12 @@
android:ems="10" android:ems="10"
android:text="unknown coin" /> android:text="unknown coin" />
</LinearLayout> </LinearLayout>
<cy.agorise.crystalwallet.views.CryptoCoinBalanceListView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/cryptoCoinBalanceListView">
</cy.agorise.crystalwallet.views.CryptoCoinBalanceListView>
</RelativeLayout> </RelativeLayout>

View file

@ -4,11 +4,8 @@
android:layout_height="match_parent" android:layout_height="match_parent"
tools:context="cy.agorise.crystalwallet.fragments.BalanceFragment"> tools:context="cy.agorise.crystalwallet.fragments.BalanceFragment">
<!-- TODO: Update blank fragment layout --> <cy.agorise.crystalwallet.views.CryptoNetBalanceListView
<TextView
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="wrap_content" />
android:text="Balance Fragment"
android:textColor="@android:color/white" />
</FrameLayout> </FrameLayout>