Merge remote-tracking branch 'origin/master'

This commit is contained in:
henry 2017-10-18 22:47:03 -04:00
commit fa2da6b88b
10 changed files with 51 additions and 29 deletions

View file

@ -73,7 +73,7 @@ public class Converters {
if (net == null) { if (net == null) {
return ""; return "";
} else { } else {
return net.getLabel(); return net.name();
} }
} }

View file

@ -52,12 +52,14 @@ public class BalanceFragment extends Fragment {
cryptoNetBalanceListViewModel = ViewModelProviders.of(this).get(CryptoNetBalanceListViewModel.class); cryptoNetBalanceListViewModel = ViewModelProviders.of(this).get(CryptoNetBalanceListViewModel.class);
LiveData<List<CryptoNetBalance>> cryptoNetBalanceData = cryptoNetBalanceListViewModel.getCryptoNetBalanceList(); LiveData<List<CryptoNetBalance>> cryptoNetBalanceData = cryptoNetBalanceListViewModel.getCryptoNetBalanceList();
vCryptoNetBalanceListView.setData(null); vCryptoNetBalanceListView.setData(null, this);
final Fragment fragment = this;
cryptoNetBalanceData.observe(this, new Observer<List<CryptoNetBalance>>() { cryptoNetBalanceData.observe(this, new Observer<List<CryptoNetBalance>>() {
@Override @Override
public void onChanged(List<CryptoNetBalance> cryptoNetBalances) { public void onChanged(List<CryptoNetBalance> cryptoNetBalances) {
vCryptoNetBalanceListView.setData(cryptoNetBalances); vCryptoNetBalanceListView.setData(cryptoNetBalances, fragment);
} }
}); });

View file

@ -56,11 +56,11 @@ public class CryptoCoinBalance {
this.mAccountId = accountId; this.mAccountId = accountId;
} }
public long getCryptoCurrency() { public long getCryptoCurrencyId() {
return mCryptoCurrencyId; return mCryptoCurrencyId;
} }
public void setCryptoCurrency(long cryptoCurrencyId) { public void setCryptoCurrencyId(long cryptoCurrencyId) {
this.mCryptoCurrencyId = cryptoCurrencyId; this.mCryptoCurrencyId = cryptoCurrencyId;
} }
@ -76,7 +76,7 @@ public class CryptoCoinBalance {
@Override @Override
public boolean areItemsTheSame( public boolean areItemsTheSame(
@NonNull CryptoCoinBalance oldBalance, @NonNull CryptoCoinBalance newBalance) { @NonNull CryptoCoinBalance oldBalance, @NonNull CryptoCoinBalance newBalance) {
return oldBalance.getCryptoCurrency() == newBalance.getCryptoCurrency(); return oldBalance.getCryptoCurrencyId() == newBalance.getCryptoCurrencyId();
} }
@Override @Override
public boolean areContentsTheSame( public boolean areContentsTheSame(

View file

@ -4,6 +4,7 @@ package cy.agorise.crystalwallet.models;
import android.arch.persistence.room.ColumnInfo; import android.arch.persistence.room.ColumnInfo;
import android.arch.persistence.room.Entity; import android.arch.persistence.room.Entity;
import android.arch.persistence.room.ForeignKey; import android.arch.persistence.room.ForeignKey;
import android.arch.persistence.room.Ignore;
import android.arch.persistence.room.Index; import android.arch.persistence.room.Index;
import android.arch.persistence.room.PrimaryKey; import android.arch.persistence.room.PrimaryKey;
@ -50,6 +51,7 @@ public class CryptoNetAccount {
public CryptoNetAccount() { public CryptoNetAccount() {
} }
@Ignore
public CryptoNetAccount(long mId, long mSeedId, int mAccountIndex, CryptoNet mCryptoNet) { public CryptoNetAccount(long mId, long mSeedId, int mAccountIndex, CryptoNet mCryptoNet) {
this.mId = mId; this.mId = mId;
this.mSeedId = mSeedId; this.mSeedId = mSeedId;

View file

@ -37,7 +37,7 @@ public class RandomCryptoCoinBalanceGenerator {
randomBalance = new CryptoCoinBalance(); randomBalance = new CryptoCoinBalance();
randomBalance.setAccountId(randomSelectedAccount.getId()); randomBalance.setAccountId(randomSelectedAccount.getId());
randomBalance.setBalance(randomAmount); randomBalance.setBalance(randomAmount);
randomBalance.setCoin(randomCryptoCoin); //randomBalance.setCoin(randomCryptoCoin);
result.add(randomBalance); result.add(randomBalance);
} }

View file

@ -20,10 +20,13 @@ public class CryptoCoinBalanceListViewModel extends AndroidViewModel {
private LiveData<List<CryptoCoinBalance>> cryptoCoinBalanceList; private LiveData<List<CryptoCoinBalance>> cryptoCoinBalanceList;
private CrystalDatabase db; private CrystalDatabase db;
public CryptoCoinBalanceListViewModel(Application application, CryptoNetAccount account) { public CryptoCoinBalanceListViewModel(Application application) {
super(application); super(application);
this.db = CrystalDatabase.getAppDatabase(application.getApplicationContext()); this.db = CrystalDatabase.getAppDatabase(application.getApplicationContext());
this.cryptoCoinBalanceList = this.db.cryptoCoinBalanceDao().getBalancesFromAccount(account.getId()); }
public void init(long cryptoNetAccountId){
this.cryptoCoinBalanceList = this.db.cryptoCoinBalanceDao().getBalancesFromAccount(cryptoNetAccountId);
} }
public LiveData<List<CryptoCoinBalance>> getCryptoCoinBalanceList(){ public LiveData<List<CryptoCoinBalance>> getCryptoCoinBalanceList(){

View file

@ -33,7 +33,7 @@ public class CryptoCoinBalanceViewHolder extends RecyclerView.ViewHolder {
cryptoCoinName.setText("loading..."); cryptoCoinName.setText("loading...");
cryptoCoinBalance.setText(""); cryptoCoinBalance.setText("");
} else { } else {
cryptoCoinName.setText(balance.getCoin().getLabel()); //cryptoCoinName.setText(balance.getCoin().getLabel());
cryptoCoinBalance.setText(""+balance.getBalance()); cryptoCoinBalance.setText(""+balance.getBalance());
} }
} }

View file

@ -1,6 +1,7 @@
package cy.agorise.crystalwallet.views; package cy.agorise.crystalwallet.views;
import android.support.v4.app.Fragment;
import android.support.v7.recyclerview.extensions.ListAdapter; import android.support.v7.recyclerview.extensions.ListAdapter;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.View; import android.view.View;
@ -8,6 +9,7 @@ import android.view.ViewGroup;
import cy.agorise.crystalwallet.R; import cy.agorise.crystalwallet.R;
import cy.agorise.crystalwallet.models.CryptoNetBalance; import cy.agorise.crystalwallet.models.CryptoNetBalance;
import cy.agorise.crystalwallet.viewmodels.CryptoCoinBalanceListViewModel;
/** /**
* Created by Henry Varona on 11/9/2017. * Created by Henry Varona on 11/9/2017.
@ -15,8 +17,11 @@ import cy.agorise.crystalwallet.models.CryptoNetBalance;
public class CryptoNetBalanceListAdapter extends ListAdapter<CryptoNetBalance, CryptoNetBalanceViewHolder> { public class CryptoNetBalanceListAdapter extends ListAdapter<CryptoNetBalance, CryptoNetBalanceViewHolder> {
public CryptoNetBalanceListAdapter() { Fragment fragment;
public CryptoNetBalanceListAdapter(Fragment fragment) {
super(CryptoNetBalance.DIFF_CALLBACK); super(CryptoNetBalance.DIFF_CALLBACK);
this.fragment = fragment;
} }
@Override @Override
@ -24,7 +29,7 @@ public class CryptoNetBalanceListAdapter extends ListAdapter<CryptoNetBalance, C
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 CryptoNetBalanceViewHolder(v); return new CryptoNetBalanceViewHolder(v, fragment);
} }
@Override @Override

View file

@ -1,6 +1,7 @@
package cy.agorise.crystalwallet.views; package cy.agorise.crystalwallet.views;
import android.content.Context; import android.content.Context;
import android.support.v4.app.Fragment;
import android.support.v7.widget.LinearLayoutManager; import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView; import android.support.v7.widget.RecyclerView;
import android.util.AttributeSet; import android.util.AttributeSet;
@ -12,6 +13,7 @@ import java.util.List;
import cy.agorise.crystalwallet.R; import cy.agorise.crystalwallet.R;
import cy.agorise.crystalwallet.models.CryptoNetBalance; import cy.agorise.crystalwallet.models.CryptoNetBalance;
import cy.agorise.crystalwallet.viewmodels.CryptoCoinBalanceListViewModel;
import cy.agorise.crystalwallet.viewmodels.CryptoNetBalanceListViewModel; import cy.agorise.crystalwallet.viewmodels.CryptoNetBalanceListViewModel;
/** /**
@ -58,9 +60,9 @@ public class CryptoNetBalanceListView extends RelativeLayout {
this.listView.setNestedScrollingEnabled(false); this.listView.setNestedScrollingEnabled(false);
} }
public void setData(List<CryptoNetBalance> data){ public void setData(List<CryptoNetBalance> data, Fragment fragment){
if (this.listAdapter == null) { if (this.listAdapter == null) {
this.listAdapter = new CryptoNetBalanceListAdapter(); this.listAdapter = new CryptoNetBalanceListAdapter(fragment);
this.listView.setAdapter(this.listAdapter); this.listView.setAdapter(this.listAdapter);
} }

View file

@ -1,14 +1,24 @@
package cy.agorise.crystalwallet.views; package cy.agorise.crystalwallet.views;
import android.app.Activity;
import android.support.v4.app.Fragment;
import android.arch.lifecycle.LifecycleOwner;
import android.arch.lifecycle.LiveData;
import android.arch.lifecycle.Observer;
import android.arch.lifecycle.ViewModelProviders; import android.arch.lifecycle.ViewModelProviders;
import android.arch.paging.PagedList;
import android.support.v7.widget.RecyclerView; import android.support.v7.widget.RecyclerView;
import android.view.View; import android.view.View;
import android.widget.ImageView; import android.widget.ImageView;
import android.widget.TextView; import android.widget.TextView;
import java.util.List;
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;
import cy.agorise.crystalwallet.models.CryptoNetBalance; import cy.agorise.crystalwallet.models.CryptoNetBalance;
import cy.agorise.crystalwallet.viewmodels.CryptoCoinBalanceListViewModel;
/** /**
* Created by Henry Varona on 17/9/2017. * Created by Henry Varona on 17/9/2017.
@ -19,13 +29,14 @@ public class CryptoNetBalanceViewHolder extends RecyclerView.ViewHolder {
private TextView cryptoNetName; private TextView cryptoNetName;
private CryptoCoinBalanceListView cryptoCoinBalanceListView; private CryptoCoinBalanceListView cryptoCoinBalanceListView;
private Fragment fragment;
public CryptoNetBalanceViewHolder(View itemView) { public CryptoNetBalanceViewHolder(View itemView, Fragment fragment) {
super(itemView); super(itemView);
cryptoNetIcon = (ImageView) itemView.findViewById(R.id.ivCryptoNetIcon); cryptoNetIcon = (ImageView) itemView.findViewById(R.id.ivCryptoNetIcon);
cryptoNetName = (TextView) itemView.findViewById(R.id.tvCryptoNetName); cryptoNetName = (TextView) itemView.findViewById(R.id.tvCryptoNetName);
cryptoCoinBalanceListView = (CryptoCoinBalanceListView) itemView.findViewById(R.id.cryptoCoinBalancesListView); cryptoCoinBalanceListView = (CryptoCoinBalanceListView) itemView.findViewById(R.id.cryptoCoinBalancesListView);
this.fragment = fragment;
} }
public void clear(){ public void clear(){
@ -38,20 +49,17 @@ public class CryptoNetBalanceViewHolder extends RecyclerView.ViewHolder {
} else { } else {
cryptoNetName.setText(balance.getCryptoNet().getLabel()); cryptoNetName.setText(balance.getCryptoNet().getLabel());
/*transactionListView = this.findViewById(R.id.transaction_list); CryptoCoinBalanceListViewModel cryptoCoinBalanceListViewModel = ViewModelProviders.of(this.fragment).get(CryptoCoinBalanceListViewModel.class);
cryptoCoinBalanceListViewModel.init(balance.getAccountId());
LiveData<List<CryptoCoinBalance>> cryptoCoinBalanceData = cryptoCoinBalanceListViewModel.getCryptoCoinBalanceList();
cryptoCoinBalanceListView.setData(null);
transactionListViewModel = ViewModelProviders.of(getContext).get(TransactionListViewModel.class); cryptoCoinBalanceData.observe((LifecycleOwner)this.itemView.getContext(), new Observer<List<CryptoCoinBalance>>() {
LiveData<PagedList<CryptoCoinTransaction>> transactionData = transactionListViewModel.getTransactionList();
transactionListView.setData(null);
transactionData.observe(this, new Observer<PagedList<CryptoCoinTransaction>>() {
@Override @Override
public void onChanged(PagedList<CryptoCoinTransaction> cryptoCoinTransactions) { public void onChanged(List<CryptoCoinBalance> cryptoCoinBalances) {
transactionListView.setData(cryptoCoinTransactions); cryptoCoinBalanceListView.setData(cryptoCoinBalances);
} }
}); });
cryptoCoinBalanceListView.setData();*/
} }
} }
} }