From 6eab51c89f3af6ba90cedd6982109ecd50315cbe Mon Sep 17 00:00:00 2001 From: Javier Varona Date: Wed, 26 Sep 2018 22:45:09 -0400 Subject: [PATCH] - Fixed string "infinity" in equivalent totals when the equivalence value of a currency is 0 - Added equivalent currency name in the cryptonet equivalent totals --- .../views/CryptoCoinBalanceViewHolder.java | 19 +++++++++++++------ .../views/CryptoNetBalanceViewHolder.java | 17 ++++++++++++++++- app/src/main/res/layout/send_transaction.xml | 2 +- 3 files changed, 30 insertions(+), 8 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 954933b..fbab252 100644 --- a/app/src/main/java/cy/agorise/crystalwallet/views/CryptoCoinBalanceViewHolder.java +++ b/app/src/main/java/cy/agorise/crystalwallet/views/CryptoCoinBalanceViewHolder.java @@ -105,12 +105,19 @@ public class CryptoCoinBalanceViewHolder extends RecyclerView.ViewHolder { public void onChanged(@Nullable CryptoCurrencyEquivalence cryptoCurrencyEquivalence) { if (cryptoCurrencyEquivalence != null) { CryptoCurrency toCurrency = CrystalDatabase.getAppDatabase(context).cryptoCurrencyDao().getById(cryptoCurrencyEquivalence.getFromCurrencyId()); - double equivalentValue = (balance.getBalance() / Math.pow(10, currencyFrom.getPrecision())) / - (cryptoCurrencyEquivalence.getValue() / Math.pow(10, toCurrency.getPrecision())); - String equivalenceString = String.format( - "%.2f", - equivalentValue - ); + double equivalentValue = 0; + String equivalenceString = ""; + if (cryptoCurrencyEquivalence.getValue() > 0) { + equivalentValue = (balance.getBalance() / Math.pow(10, currencyFrom.getPrecision())) / + (cryptoCurrencyEquivalence.getValue() / Math.pow(10, toCurrency.getPrecision())); + equivalenceString = String.format( + "%.2f", + equivalentValue + ); + } else { + equivalentValue = 0; + equivalenceString = "0"; + } cryptoNetBalanceViewHolder.setEquivalentBalance(balance,equivalentValue); cryptoCoinBalanceEquivalence.setText( diff --git a/app/src/main/java/cy/agorise/crystalwallet/views/CryptoNetBalanceViewHolder.java b/app/src/main/java/cy/agorise/crystalwallet/views/CryptoNetBalanceViewHolder.java index 4a2043c..1596577 100644 --- a/app/src/main/java/cy/agorise/crystalwallet/views/CryptoNetBalanceViewHolder.java +++ b/app/src/main/java/cy/agorise/crystalwallet/views/CryptoNetBalanceViewHolder.java @@ -3,6 +3,7 @@ package cy.agorise.crystalwallet.views; import android.app.Activity; import android.content.Context; import android.content.Intent; +import android.support.annotation.Nullable; import android.support.v4.app.Fragment; import android.arch.lifecycle.LifecycleOwner; import android.arch.lifecycle.LiveData; @@ -24,12 +25,14 @@ import butterknife.ButterKnife; import butterknife.OnClick; import cy.agorise.crystalwallet.R; import cy.agorise.crystalwallet.activities.SendTransactionActivity; +import cy.agorise.crystalwallet.dao.CrystalDatabase; import cy.agorise.crystalwallet.fragments.ReceiveTransactionFragment; import cy.agorise.crystalwallet.fragments.SendTransactionFragment; import cy.agorise.crystalwallet.models.CryptoCoinBalance; import cy.agorise.crystalwallet.models.CryptoCoinTransaction; import cy.agorise.crystalwallet.models.CryptoCurrencyEquivalence; import cy.agorise.crystalwallet.models.CryptoNetBalance; +import cy.agorise.crystalwallet.models.GeneralSetting; import cy.agorise.crystalwallet.viewmodels.CryptoCoinBalanceListViewModel; /** @@ -86,6 +89,8 @@ public class CryptoNetBalanceViewHolder extends RecyclerView.ViewHolder { */ private Fragment fragment; + String preferredCurrency = ""; + public CryptoNetBalanceViewHolder(View itemView, Fragment fragment) { super(itemView); //-1 represents a crypto net account not loaded yet @@ -114,6 +119,16 @@ public class CryptoNetBalanceViewHolder extends RecyclerView.ViewHolder { }); this.fragment = fragment; this.context = itemView.getContext(); + + LiveData preferedCurrencySetting = CrystalDatabase.getAppDatabase(this.context).generalSettingDao().getByName(GeneralSetting.SETTING_NAME_PREFERRED_CURRENCY); + + preferedCurrencySetting.observe((LifecycleOwner)this.itemView.getContext(), new Observer() { + @Override + public void onChanged(@Nullable GeneralSetting generalSetting) { + preferredCurrency = generalSetting.getValue(); + } + }); + } public void clear(){ @@ -179,7 +194,7 @@ public class CryptoNetBalanceViewHolder extends RecyclerView.ViewHolder { totalEquivalent += nextEquivalent; } - this.cryptoNetEquivalentTotal.setText(""+totalEquivalent); + this.cryptoNetEquivalentTotal.setText(""+totalEquivalent+" "+preferredCurrency); } } diff --git a/app/src/main/res/layout/send_transaction.xml b/app/src/main/res/layout/send_transaction.xml index 028d967..584e511 100644 --- a/app/src/main/res/layout/send_transaction.xml +++ b/app/src/main/res/layout/send_transaction.xml @@ -186,7 +186,7 @@ app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toBottomOf="@id/tvMemoError" /> -