From e3a20eabaad5e46b50d953ff0279d9faf64bed3d Mon Sep 17 00:00:00 2001 From: Javier Varona Date: Tue, 20 Feb 2018 21:49:51 -0400 Subject: [PATCH] - Fixed account selection in Receive Fragment - Now the send fragment loads the qr scanned info --- .../activities/BoardActivity.java | 10 ++++++- .../fragments/ReceiveTransactionFragment.java | 16 ++++++++++ .../fragments/SendTransactionFragment.java | 30 ++++++++++++++++++- 3 files changed, 54 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/cy/agorise/crystalwallet/activities/BoardActivity.java b/app/src/main/java/cy/agorise/crystalwallet/activities/BoardActivity.java index e113438..95c7fb4 100644 --- a/app/src/main/java/cy/agorise/crystalwallet/activities/BoardActivity.java +++ b/app/src/main/java/cy/agorise/crystalwallet/activities/BoardActivity.java @@ -221,8 +221,16 @@ public class BoardActivity extends AppCompatActivity { } ft.addToBackStack(null); + long receiveCryptoNetAccountId = -1; + if (this.cryptoNetAccountId != -1){ + receiveCryptoNetAccountId = this.cryptoNetAccountId; + } else { + CryptoNetBalanceListViewModel cryptoNetBalanceListViewModel = ViewModelProviders.of(this).get(CryptoNetBalanceListViewModel.class); + receiveCryptoNetAccountId = cryptoNetBalanceListViewModel.getFirstBitsharesAccountId(); + } + // Create and show the dialog. - ReceiveTransactionFragment newFragment = ReceiveTransactionFragment.newInstance(this.cryptoNetAccountId); + ReceiveTransactionFragment newFragment = ReceiveTransactionFragment.newInstance(receiveCryptoNetAccountId); newFragment.show(ft, "ReceiveDialog"); } diff --git a/app/src/main/java/cy/agorise/crystalwallet/fragments/ReceiveTransactionFragment.java b/app/src/main/java/cy/agorise/crystalwallet/fragments/ReceiveTransactionFragment.java index 3e26231..db94f95 100644 --- a/app/src/main/java/cy/agorise/crystalwallet/fragments/ReceiveTransactionFragment.java +++ b/app/src/main/java/cy/agorise/crystalwallet/fragments/ReceiveTransactionFragment.java @@ -4,6 +4,7 @@ import android.app.Dialog; import android.app.LauncherActivity; import android.arch.lifecycle.LiveData; import android.arch.lifecycle.Observer; +import android.arch.lifecycle.ViewModelProviders; import android.content.DialogInterface; import android.graphics.Bitmap; import android.os.Bundle; @@ -31,6 +32,8 @@ import com.google.zxing.WriterException; import com.google.zxing.common.BitMatrix; import butterknife.OnClick; +import cy.agorise.crystalwallet.viewmodels.CryptoNetAccountListViewModel; +import cy.agorise.crystalwallet.views.CryptoNetAccountAdapter; import cy.agorise.graphenej.Invoice; import java.util.ArrayList; import java.util.List; @@ -57,6 +60,8 @@ public class ReceiveTransactionFragment extends DialogFragment implements UIVali ReceiveTransactionValidator receiveTransactionValidator; + @BindView(R.id.spTo) + Spinner spTo; @BindView(R.id.etAmount) EditText etAmount; @BindView(R.id.tvAmountError) @@ -145,6 +150,12 @@ public class ReceiveTransactionFragment extends DialogFragment implements UIVali receiveTransactionValidator = new ReceiveTransactionValidator(this.getContext(), this.cryptoNetAccount, spAsset, etAmount); receiveTransactionValidator.setListener(this); + + CryptoNetAccountListViewModel cryptoNetAccountListViewModel = ViewModelProviders.of(this).get(CryptoNetAccountListViewModel.class); + List cryptoNetAccounts = cryptoNetAccountListViewModel.getCryptoNetAccountList(); + CryptoNetAccountAdapter toSpinnerAdapter = new CryptoNetAccountAdapter(this.getContext(), android.R.layout.simple_spinner_item, cryptoNetAccounts); + spTo.setAdapter(toSpinnerAdapter); + spTo.setSelection(0); } builder.setView(view); @@ -199,6 +210,11 @@ public class ReceiveTransactionFragment extends DialogFragment implements UIVali }, 400); } + @OnItemSelected(R.id.spTo) + public void afterToSelected(Spinner spinner, int position) { + this.receiveTransactionValidator.validate(); + } + @OnTextChanged(value = R.id.etAmount, callback = OnTextChanged.Callback.AFTER_TEXT_CHANGED) void afterAmountChanged(Editable editable) { 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 981a011..c73b340 100644 --- a/app/src/main/java/cy/agorise/crystalwallet/fragments/SendTransactionFragment.java +++ b/app/src/main/java/cy/agorise/crystalwallet/fragments/SendTransactionFragment.java @@ -32,8 +32,12 @@ import android.widget.Toast; import com.google.zxing.Result; +import java.math.RoundingMode; +import java.text.DecimalFormat; +import java.text.DecimalFormatSymbols; import java.util.ArrayList; import java.util.List; +import java.util.Locale; import butterknife.BindView; import butterknife.ButterKnife; @@ -59,6 +63,8 @@ import cy.agorise.crystalwallet.viewmodels.validators.UIValidatorListener; import cy.agorise.crystalwallet.viewmodels.validators.validationfields.ValidationField; import cy.agorise.crystalwallet.views.CryptoCurrencyAdapter; import cy.agorise.crystalwallet.views.CryptoNetAccountAdapter; +import cy.agorise.graphenej.Invoice; +import cy.agorise.graphenej.LineItem; import me.dm7.barcodescanner.zxing.ZXingScannerView; public class SendTransactionFragment extends DialogFragment implements UIValidatorListener, ZXingScannerView.ResultHandler { @@ -91,6 +97,7 @@ public class SendTransactionFragment extends DialogFragment implements UIValidat TextView btnCancel; @BindView(R.id.ivPeople) ImageView ivPeople; + CryptoCurrencyAdapter assetAdapter; Button btnScanQrCode; @@ -154,7 +161,7 @@ public class SendTransactionFragment extends DialogFragment implements UIValidat } List cryptoCurrencyList = db.cryptoCurrencyDao().getByIds(assetIds); - CryptoCurrencyAdapter assetAdapter = new CryptoCurrencyAdapter(getContext(), android.R.layout.simple_spinner_item, cryptoCurrencyList); + assetAdapter = new CryptoCurrencyAdapter(getContext(), android.R.layout.simple_spinner_item, cryptoCurrencyList); spAsset.setAdapter(assetAdapter); } }); @@ -370,6 +377,27 @@ public class SendTransactionFragment extends DialogFragment implements UIValidat @Override public void handleResult(Result result) { + Invoice invoice = Invoice.fromQrCode(result.getText()); + + etTo.setText(invoice.getTo()); + + for (int i=0;i