From e52ab7b71432f4411a7fb884beee9ca828752934 Mon Sep 17 00:00:00 2001 From: Javier Varona Date: Wed, 8 Nov 2017 20:37:23 -0400 Subject: [PATCH] - Change balances to show equivalences with the currency from the preferred country of the user --- .../views/CryptoCoinBalanceViewHolder.java | 47 ++++++++++++------- 1 file changed, 30 insertions(+), 17 deletions(-) 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 1bd1e4f..0a587bc 100644 --- a/app/src/main/java/cy/agorise/crystalwallet/views/CryptoCoinBalanceViewHolder.java +++ b/app/src/main/java/cy/agorise/crystalwallet/views/CryptoCoinBalanceViewHolder.java @@ -15,6 +15,7 @@ import cy.agorise.crystalwallet.models.CryptoCoinBalance; import cy.agorise.crystalwallet.models.CryptoCoinTransaction; import cy.agorise.crystalwallet.models.CryptoCurrency; import cy.agorise.crystalwallet.models.CryptoCurrencyEquivalence; +import cy.agorise.crystalwallet.models.GeneralSetting; /** * Created by Henry Varona on 17/9/2017. @@ -47,27 +48,39 @@ public class CryptoCoinBalanceViewHolder extends RecyclerView.ViewHolder { cryptoCoinBalance.setText(""); cryptoCoinBalanceEquivalence.setText(""); } else { - CryptoCurrency currency = CrystalDatabase.getAppDatabase(this.context).cryptoCurrencyDao().getById(balance.getCryptoCurrencyId()); - CryptoCurrency currencyBitEur = CrystalDatabase.getAppDatabase(this.context).cryptoCurrencyDao().getByName("EUR"); + LiveData preferedCurrencySetting = CrystalDatabase.getAppDatabase(this.context).generalSettingDao().getByName(GeneralSetting.SETTING_NAME_PREFERED_CURRENCY); - LiveData currencyEquivalenceLiveData = CrystalDatabase.getAppDatabase(this.context) - .cryptoCurrencyEquivalenceDao().getByFromTo( - currency.getId(), - currencyBitEur.getId() - ); - - cryptoCoinName.setText(currency.getName()); - cryptoCoinBalance.setText(""+balance.getBalance()); - - currencyEquivalenceLiveData.observe((LifecycleOwner) this.context, new Observer() { + preferedCurrencySetting.observe((LifecycleOwner) this.context, new Observer() { @Override - public void onChanged(@Nullable CryptoCurrencyEquivalence cryptoCurrencyEquivalence) { - if (cryptoCurrencyEquivalence != null){ - CryptoCurrency toCurrency = CrystalDatabase.getAppDatabase(context).cryptoCurrencyDao().getById(cryptoCurrencyEquivalence.getToCurrencyId()); - cryptoCoinBalanceEquivalence.setText(cryptoCurrencyEquivalence.getValue()+" "+toCurrency.getName()); - } + public void onChanged(@Nullable GeneralSetting generalSetting) { + CryptoCurrency currencyFrom = CrystalDatabase.getAppDatabase(context).cryptoCurrencyDao().getById(balance.getCryptoCurrencyId()); + CryptoCurrency currencyTo = CrystalDatabase.getAppDatabase(context).cryptoCurrencyDao().getByName(generalSetting.getValue()); + + LiveData currencyEquivalenceLiveData = CrystalDatabase.getAppDatabase(context) + .cryptoCurrencyEquivalenceDao().getByFromTo( + currencyFrom.getId(), + currencyTo.getId() + ); + + cryptoCoinName.setText(currencyFrom.getName()); + cryptoCoinBalance.setText(""+balance.getBalance()); + + currencyEquivalenceLiveData.observe((LifecycleOwner) context, new Observer() { + @Override + public void onChanged(@Nullable CryptoCurrencyEquivalence cryptoCurrencyEquivalence) { + if (cryptoCurrencyEquivalence != null){ + CryptoCurrency toCurrency = CrystalDatabase.getAppDatabase(context).cryptoCurrencyDao().getById(cryptoCurrencyEquivalence.getToCurrencyId()); + cryptoCoinBalanceEquivalence.setText(cryptoCurrencyEquivalence.getValue()+" "+toCurrency.getName()); + } + } + }); + + } }); + + + } } }