- Change balances to show equivalences with the currency from the preferred country of the user

This commit is contained in:
Javier Varona 2017-11-08 20:37:23 -04:00
parent 6dae8cb681
commit e52ab7b714

View file

@ -15,6 +15,7 @@ import cy.agorise.crystalwallet.models.CryptoCoinBalance;
import cy.agorise.crystalwallet.models.CryptoCoinTransaction; import cy.agorise.crystalwallet.models.CryptoCoinTransaction;
import cy.agorise.crystalwallet.models.CryptoCurrency; import cy.agorise.crystalwallet.models.CryptoCurrency;
import cy.agorise.crystalwallet.models.CryptoCurrencyEquivalence; import cy.agorise.crystalwallet.models.CryptoCurrencyEquivalence;
import cy.agorise.crystalwallet.models.GeneralSetting;
/** /**
* Created by Henry Varona on 17/9/2017. * Created by Henry Varona on 17/9/2017.
@ -47,19 +48,24 @@ public class CryptoCoinBalanceViewHolder extends RecyclerView.ViewHolder {
cryptoCoinBalance.setText(""); cryptoCoinBalance.setText("");
cryptoCoinBalanceEquivalence.setText(""); cryptoCoinBalanceEquivalence.setText("");
} else { } else {
CryptoCurrency currency = CrystalDatabase.getAppDatabase(this.context).cryptoCurrencyDao().getById(balance.getCryptoCurrencyId()); LiveData<GeneralSetting> preferedCurrencySetting = CrystalDatabase.getAppDatabase(this.context).generalSettingDao().getByName(GeneralSetting.SETTING_NAME_PREFERED_CURRENCY);
CryptoCurrency currencyBitEur = CrystalDatabase.getAppDatabase(this.context).cryptoCurrencyDao().getByName("EUR");
LiveData<CryptoCurrencyEquivalence> currencyEquivalenceLiveData = CrystalDatabase.getAppDatabase(this.context) preferedCurrencySetting.observe((LifecycleOwner) this.context, new Observer<GeneralSetting>() {
@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());
LiveData<CryptoCurrencyEquivalence> currencyEquivalenceLiveData = CrystalDatabase.getAppDatabase(context)
.cryptoCurrencyEquivalenceDao().getByFromTo( .cryptoCurrencyEquivalenceDao().getByFromTo(
currency.getId(), currencyFrom.getId(),
currencyBitEur.getId() currencyTo.getId()
); );
cryptoCoinName.setText(currency.getName()); cryptoCoinName.setText(currencyFrom.getName());
cryptoCoinBalance.setText(""+balance.getBalance()); cryptoCoinBalance.setText(""+balance.getBalance());
currencyEquivalenceLiveData.observe((LifecycleOwner) this.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) {
if (cryptoCurrencyEquivalence != null){ if (cryptoCurrencyEquivalence != null){
@ -68,6 +74,13 @@ public class CryptoCoinBalanceViewHolder extends RecyclerView.ViewHolder {
} }
} }
}); });
}
});
} }
} }
} }