From a9ec777e5c46156d7d78d2a6acdb5c2caa363032 Mon Sep 17 00:00:00 2001 From: Javier Varona Date: Fri, 10 Nov 2017 22:08:23 -0400 Subject: [PATCH] - Fixed the way the equivalences are loaded in the balances. Now they load independent from the balance amount --- .../views/CryptoCoinBalanceViewHolder.java | 42 +++++++++---------- 1 file changed, 19 insertions(+), 23 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 0a587bc..2b1373b 100644 --- a/app/src/main/java/cy/agorise/crystalwallet/views/CryptoCoinBalanceViewHolder.java +++ b/app/src/main/java/cy/agorise/crystalwallet/views/CryptoCoinBalanceViewHolder.java @@ -49,38 +49,34 @@ public class CryptoCoinBalanceViewHolder extends RecyclerView.ViewHolder { cryptoCoinBalanceEquivalence.setText(""); } else { LiveData preferedCurrencySetting = CrystalDatabase.getAppDatabase(this.context).generalSettingDao().getByName(GeneralSetting.SETTING_NAME_PREFERED_CURRENCY); + final CryptoCurrency currencyFrom = CrystalDatabase.getAppDatabase(context).cryptoCurrencyDao().getById(balance.getCryptoCurrencyId()); + cryptoCoinName.setText(currencyFrom.getName()); + cryptoCoinBalance.setText("" + balance.getBalance()); preferedCurrencySetting.observe((LifecycleOwner) this.context, new Observer() { @Override public void onChanged(@Nullable GeneralSetting generalSetting) { - CryptoCurrency currencyFrom = CrystalDatabase.getAppDatabase(context).cryptoCurrencyDao().getById(balance.getCryptoCurrencyId()); - CryptoCurrency currencyTo = CrystalDatabase.getAppDatabase(context).cryptoCurrencyDao().getByName(generalSetting.getValue()); + if (generalSetting != null) { + CryptoCurrency currencyTo = CrystalDatabase.getAppDatabase(context).cryptoCurrencyDao().getByName(generalSetting.getValue()); - LiveData currencyEquivalenceLiveData = CrystalDatabase.getAppDatabase(context) - .cryptoCurrencyEquivalenceDao().getByFromTo( - currencyFrom.getId(), - currencyTo.getId() - ); + 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()); + 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()); + } } - } - }); - - + }); + } } }); - - - } } }