- Fixed string "infinity" in equivalent totals when the equivalence value of a currency is 0

- Added equivalent currency name in the cryptonet equivalent totals
This commit is contained in:
Javier Varona 2018-09-26 22:45:09 -04:00
parent d16f2d7378
commit 6eab51c89f
3 changed files with 30 additions and 8 deletions

View file

@ -105,12 +105,19 @@ public class CryptoCoinBalanceViewHolder extends RecyclerView.ViewHolder {
public void onChanged(@Nullable CryptoCurrencyEquivalence cryptoCurrencyEquivalence) { public void onChanged(@Nullable CryptoCurrencyEquivalence cryptoCurrencyEquivalence) {
if (cryptoCurrencyEquivalence != null) { if (cryptoCurrencyEquivalence != null) {
CryptoCurrency toCurrency = CrystalDatabase.getAppDatabase(context).cryptoCurrencyDao().getById(cryptoCurrencyEquivalence.getFromCurrencyId()); CryptoCurrency toCurrency = CrystalDatabase.getAppDatabase(context).cryptoCurrencyDao().getById(cryptoCurrencyEquivalence.getFromCurrencyId());
double equivalentValue = (balance.getBalance() / Math.pow(10, currencyFrom.getPrecision())) / double equivalentValue = 0;
String equivalenceString = "";
if (cryptoCurrencyEquivalence.getValue() > 0) {
equivalentValue = (balance.getBalance() / Math.pow(10, currencyFrom.getPrecision())) /
(cryptoCurrencyEquivalence.getValue() / Math.pow(10, toCurrency.getPrecision())); (cryptoCurrencyEquivalence.getValue() / Math.pow(10, toCurrency.getPrecision()));
String equivalenceString = String.format( equivalenceString = String.format(
"%.2f", "%.2f",
equivalentValue equivalentValue
); );
} else {
equivalentValue = 0;
equivalenceString = "0";
}
cryptoNetBalanceViewHolder.setEquivalentBalance(balance,equivalentValue); cryptoNetBalanceViewHolder.setEquivalentBalance(balance,equivalentValue);
cryptoCoinBalanceEquivalence.setText( cryptoCoinBalanceEquivalence.setText(

View file

@ -3,6 +3,7 @@ package cy.agorise.crystalwallet.views;
import android.app.Activity; import android.app.Activity;
import android.content.Context; import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment; import android.support.v4.app.Fragment;
import android.arch.lifecycle.LifecycleOwner; import android.arch.lifecycle.LifecycleOwner;
import android.arch.lifecycle.LiveData; import android.arch.lifecycle.LiveData;
@ -24,12 +25,14 @@ import butterknife.ButterKnife;
import butterknife.OnClick; import butterknife.OnClick;
import cy.agorise.crystalwallet.R; import cy.agorise.crystalwallet.R;
import cy.agorise.crystalwallet.activities.SendTransactionActivity; import cy.agorise.crystalwallet.activities.SendTransactionActivity;
import cy.agorise.crystalwallet.dao.CrystalDatabase;
import cy.agorise.crystalwallet.fragments.ReceiveTransactionFragment; import cy.agorise.crystalwallet.fragments.ReceiveTransactionFragment;
import cy.agorise.crystalwallet.fragments.SendTransactionFragment; import cy.agorise.crystalwallet.fragments.SendTransactionFragment;
import cy.agorise.crystalwallet.models.CryptoCoinBalance; import cy.agorise.crystalwallet.models.CryptoCoinBalance;
import cy.agorise.crystalwallet.models.CryptoCoinTransaction; import cy.agorise.crystalwallet.models.CryptoCoinTransaction;
import cy.agorise.crystalwallet.models.CryptoCurrencyEquivalence; import cy.agorise.crystalwallet.models.CryptoCurrencyEquivalence;
import cy.agorise.crystalwallet.models.CryptoNetBalance; import cy.agorise.crystalwallet.models.CryptoNetBalance;
import cy.agorise.crystalwallet.models.GeneralSetting;
import cy.agorise.crystalwallet.viewmodels.CryptoCoinBalanceListViewModel; import cy.agorise.crystalwallet.viewmodels.CryptoCoinBalanceListViewModel;
/** /**
@ -86,6 +89,8 @@ public class CryptoNetBalanceViewHolder extends RecyclerView.ViewHolder {
*/ */
private Fragment fragment; private Fragment fragment;
String preferredCurrency = "";
public CryptoNetBalanceViewHolder(View itemView, Fragment fragment) { public CryptoNetBalanceViewHolder(View itemView, Fragment fragment) {
super(itemView); super(itemView);
//-1 represents a crypto net account not loaded yet //-1 represents a crypto net account not loaded yet
@ -114,6 +119,16 @@ public class CryptoNetBalanceViewHolder extends RecyclerView.ViewHolder {
}); });
this.fragment = fragment; this.fragment = fragment;
this.context = itemView.getContext(); this.context = itemView.getContext();
LiveData<GeneralSetting> preferedCurrencySetting = CrystalDatabase.getAppDatabase(this.context).generalSettingDao().getByName(GeneralSetting.SETTING_NAME_PREFERRED_CURRENCY);
preferedCurrencySetting.observe((LifecycleOwner)this.itemView.getContext(), new Observer<GeneralSetting>() {
@Override
public void onChanged(@Nullable GeneralSetting generalSetting) {
preferredCurrency = generalSetting.getValue();
}
});
} }
public void clear(){ public void clear(){
@ -179,7 +194,7 @@ public class CryptoNetBalanceViewHolder extends RecyclerView.ViewHolder {
totalEquivalent += nextEquivalent; totalEquivalent += nextEquivalent;
} }
this.cryptoNetEquivalentTotal.setText(""+totalEquivalent); this.cryptoNetEquivalentTotal.setText(""+totalEquivalent+" "+preferredCurrency);
} }
} }

View file

@ -186,7 +186,7 @@
app:layout_constraintStart_toStartOf="parent" app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/tvMemoError" /> app:layout_constraintTop_toBottomOf="@id/tvMemoError" />
<ImageView <me.dm7.barcodescanner.zxing.ZXingScannerView
android:id="@+id/ivCamera" android:id="@+id/ivCamera"
android:layout_width="180dp" android:layout_width="180dp"
android:layout_height="180dp" android:layout_height="180dp"