diff --git a/app/src/main/java/cy/agorise/crystalwallet/fragments/SendTransactionFragment.java b/app/src/main/java/cy/agorise/crystalwallet/fragments/SendTransactionFragment.java index 3055135..14bc512 100644 --- a/app/src/main/java/cy/agorise/crystalwallet/fragments/SendTransactionFragment.java +++ b/app/src/main/java/cy/agorise/crystalwallet/fragments/SendTransactionFragment.java @@ -36,6 +36,7 @@ import android.widget.ImageView; import android.widget.ScrollView; import android.widget.Spinner; import android.widget.TextView; +import android.widget.Toast; import com.google.zxing.BarcodeFormat; import com.google.zxing.Result; @@ -56,6 +57,7 @@ import butterknife.OnClick; import butterknife.OnItemSelected; import butterknife.OnTextChanged; import cy.agorise.crystalwallet.R; +import cy.agorise.crystalwallet.dialogs.material.CrystalDialog; import cy.agorise.crystalwallet.requestmanagers.CryptoNetInfoRequestListener; import cy.agorise.crystalwallet.requestmanagers.CryptoNetInfoRequests; import cy.agorise.crystalwallet.requestmanagers.ValidateBitsharesSendRequest; @@ -131,7 +133,10 @@ public class SendTransactionFragment extends DialogFragment implements UIValidat private FloatingActionButton fabSend; private AlertDialog.Builder builder; - + /* + Dialog for loading + */ + private CrystalDialog crystalDialog; public static SendTransactionFragment newInstance(long cryptoNetAccountId) { SendTransactionFragment f = new SendTransactionFragment(); @@ -408,6 +413,8 @@ public class SendTransactionFragment extends DialogFragment implements UIValidat @OnClick(R.id.btnSend) public void sendTransaction(){ + final SendTransactionFragment thisFragment = this; + if (this.sendTransactionValidator.isValid()) { CryptoNetAccount fromAccountSelected = (CryptoNetAccount) spFrom.getItems().get(spFrom.getSelectedIndex()); @@ -439,13 +446,26 @@ public class SendTransactionFragment extends DialogFragment implements UIValidat public void onCarryOut() { if (sendRequest.getStatus().equals(ValidateBitsharesSendRequest.StatusCode.SUCCEEDED)){ try { - this.finalize(); + crystalDialog.dismiss(); + thisFragment.dismiss(); + //thisFragment.finalize(); } catch (Throwable throwable) { throwable.printStackTrace(); } + } else { + Toast.makeText(getContext(), getContext().getString(R.string.unable_to_send_amount), Toast.LENGTH_LONG); } } }); + + /* + * Show loading dialog + * */ + crystalDialog = new CrystalDialog((Activity) getContext()); + crystalDialog.setText("Sending"); + crystalDialog.progress(); + crystalDialog.show(); + CryptoNetInfoRequests.getInstance().addRequest(sendRequest); } } diff --git a/app/src/main/java/cy/agorise/crystalwallet/manager/BitsharesAccountManager.java b/app/src/main/java/cy/agorise/crystalwallet/manager/BitsharesAccountManager.java index 32a0591..fb0fc48 100644 --- a/app/src/main/java/cy/agorise/crystalwallet/manager/BitsharesAccountManager.java +++ b/app/src/main/java/cy/agorise/crystalwallet/manager/BitsharesAccountManager.java @@ -2,6 +2,7 @@ package cy.agorise.crystalwallet.manager; import android.annotation.SuppressLint; import android.content.Context; +import android.util.Log; import com.google.common.primitives.UnsignedLong; @@ -127,7 +128,7 @@ public class BitsharesAccountManager implements CryptoAccountManager, CryptoNetI long[] idAccount = db.cryptoNetAccountDao().insertCryptoNetAccount(grapheneAccount); grapheneAccount.setId(idAccount[0]); db.grapheneAccountInfoDao().insertGrapheneAccountInfo(new GrapheneAccountInfo(grapheneAccount)); - subscribeBitsharesAccount(grapheneAccount.getId(),grapheneAccount.getAccountId(),context); + //subscribeBitsharesAccount(grapheneAccount.getId(),grapheneAccount.getAccountId(),context); } @Override @@ -145,7 +146,7 @@ public class BitsharesAccountManager implements CryptoAccountManager, CryptoNetI CrystalDatabase db = CrystalDatabase.getAppDatabase(context); db.cryptoNetAccountDao().insertCryptoNetAccount(grapheneAccount); db.grapheneAccountInfoDao().insertGrapheneAccountInfo(new GrapheneAccountInfo(grapheneAccount)); - subscribeBitsharesAccount(grapheneAccount.getId(),grapheneAccount.getAccountId(),context); + //subscribeBitsharesAccount(grapheneAccount.getId(),grapheneAccount.getAccountId(),context); } @Override @@ -157,7 +158,7 @@ public class BitsharesAccountManager implements CryptoAccountManager, CryptoNetI CrystalDatabase db = CrystalDatabase.getAppDatabase(context); db.cryptoNetAccountDao().insertCryptoNetAccount(grapheneAccount); db.grapheneAccountInfoDao().insertGrapheneAccountInfo(new GrapheneAccountInfo(grapheneAccount)); - subscribeBitsharesAccount(grapheneAccount.getId(), grapheneAccount.getAccountId(), context); + //subscribeBitsharesAccount(grapheneAccount.getId(), grapheneAccount.getAccountId(), context); } } } 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" /> -