- Fixed the way the equivalences are loaded in the balances. Now they load independent from the balance amount

This commit is contained in:
Javier Varona 2017-11-10 22:08:23 -04:00
parent 598c58a83f
commit a9ec777e5c

View file

@ -49,11 +49,14 @@ public class CryptoCoinBalanceViewHolder extends RecyclerView.ViewHolder {
cryptoCoinBalanceEquivalence.setText(""); cryptoCoinBalanceEquivalence.setText("");
} else { } else {
LiveData<GeneralSetting> preferedCurrencySetting = CrystalDatabase.getAppDatabase(this.context).generalSettingDao().getByName(GeneralSetting.SETTING_NAME_PREFERED_CURRENCY); LiveData<GeneralSetting> 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<GeneralSetting>() { preferedCurrencySetting.observe((LifecycleOwner) this.context, new Observer<GeneralSetting>() {
@Override @Override
public void onChanged(@Nullable GeneralSetting generalSetting) { public void onChanged(@Nullable GeneralSetting generalSetting) {
CryptoCurrency currencyFrom = CrystalDatabase.getAppDatabase(context).cryptoCurrencyDao().getById(balance.getCryptoCurrencyId()); if (generalSetting != null) {
CryptoCurrency currencyTo = CrystalDatabase.getAppDatabase(context).cryptoCurrencyDao().getByName(generalSetting.getValue()); CryptoCurrency currencyTo = CrystalDatabase.getAppDatabase(context).cryptoCurrencyDao().getByName(generalSetting.getValue());
LiveData<CryptoCurrencyEquivalence> currencyEquivalenceLiveData = CrystalDatabase.getAppDatabase(context) LiveData<CryptoCurrencyEquivalence> currencyEquivalenceLiveData = CrystalDatabase.getAppDatabase(context)
@ -62,9 +65,6 @@ public class CryptoCoinBalanceViewHolder extends RecyclerView.ViewHolder {
currencyTo.getId() currencyTo.getId()
); );
cryptoCoinName.setText(currencyFrom.getName());
cryptoCoinBalance.setText(""+balance.getBalance());
currencyEquivalenceLiveData.observe((LifecycleOwner) context, new Observer<CryptoCurrencyEquivalence>() { currencyEquivalenceLiveData.observe((LifecycleOwner) context, new Observer<CryptoCurrencyEquivalence>() {
@Override @Override
public void onChanged(@Nullable CryptoCurrencyEquivalence cryptoCurrencyEquivalence) { public void onChanged(@Nullable CryptoCurrencyEquivalence cryptoCurrencyEquivalence) {
@ -74,13 +74,9 @@ public class CryptoCoinBalanceViewHolder extends RecyclerView.ViewHolder {
} }
} }
}); });
}
} }
}); });
} }
} }
} }