- 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:
parent
d16f2d7378
commit
6eab51c89f
3 changed files with 30 additions and 8 deletions
|
@ -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(
|
||||
|
|
|
@ -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<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(){
|
||||
|
@ -179,7 +194,7 @@ public class CryptoNetBalanceViewHolder extends RecyclerView.ViewHolder {
|
|||
totalEquivalent += nextEquivalent;
|
||||
}
|
||||
|
||||
this.cryptoNetEquivalentTotal.setText(""+totalEquivalent);
|
||||
this.cryptoNetEquivalentTotal.setText(""+totalEquivalent+" "+preferredCurrency);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -186,7 +186,7 @@
|
|||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@id/tvMemoError" />
|
||||
|
||||
<ImageView
|
||||
<me.dm7.barcodescanner.zxing.ZXingScannerView
|
||||
android:id="@+id/ivCamera"
|
||||
android:layout_width="180dp"
|
||||
android:layout_height="180dp"
|
||||
|
|
Loading…
Reference in a new issue