- Now the balance fragment shows the balances of every cryptonetaccount with its currencies

This commit is contained in:
Javier Varona 2017-10-18 22:35:16 -04:00
parent 119f4ea12b
commit 8e7a596d24
10 changed files with 51 additions and 29 deletions

View file

@ -73,7 +73,7 @@ public class Converters {
if (net == null) {
return "";
} 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);
LiveData<List<CryptoNetBalance>> cryptoNetBalanceData = cryptoNetBalanceListViewModel.getCryptoNetBalanceList();
vCryptoNetBalanceListView.setData(null);
vCryptoNetBalanceListView.setData(null, this);
final Fragment fragment = this;
cryptoNetBalanceData.observe(this, new Observer<List<CryptoNetBalance>>() {
@Override
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;
}
public long getCryptoCurrency() {
public long getCryptoCurrencyId() {
return mCryptoCurrencyId;
}
public void setCryptoCurrency(long cryptoCurrencyId) {
public void setCryptoCurrencyId(long cryptoCurrencyId) {
this.mCryptoCurrencyId = cryptoCurrencyId;
}
@ -76,7 +76,7 @@ public class CryptoCoinBalance {
@Override
public boolean areItemsTheSame(
@NonNull CryptoCoinBalance oldBalance, @NonNull CryptoCoinBalance newBalance) {
return oldBalance.getCryptoCurrency() == newBalance.getCryptoCurrency();
return oldBalance.getCryptoCurrencyId() == newBalance.getCryptoCurrencyId();
}
@Override
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.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;
@ -50,6 +51,7 @@ public class CryptoNetAccount {
public CryptoNetAccount() {
}
@Ignore
public CryptoNetAccount(long mId, long mSeedId, int mAccountIndex, CryptoNet mCryptoNet) {
this.mId = mId;
this.mSeedId = mSeedId;

View file

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

View file

@ -20,10 +20,13 @@ public class CryptoCoinBalanceListViewModel extends AndroidViewModel {
private LiveData<List<CryptoCoinBalance>> cryptoCoinBalanceList;
private CrystalDatabase db;
public CryptoCoinBalanceListViewModel(Application application, CryptoNetAccount account) {
public CryptoCoinBalanceListViewModel(Application application) {
super(application);
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(){

View file

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

View file

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

View file

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

View file

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