From 60ef2eb4ba8796967c222de5ef37f5caf4660062 Mon Sep 17 00:00:00 2001 From: Javier Varona Date: Wed, 1 Nov 2017 12:26:52 -0400 Subject: [PATCH] - The send activity can be reached in the balance view - Fixing the Currency Adapter Labels --- .../ReceiveTransactionActivity.java | 85 +++++++++++++++++++ .../activities/SendTransactionActivity.java | 7 +- .../views/CryptoCurrencyAdapter.java | 7 +- .../main/res/layout/receive_transaction.xml | 12 +++ app/src/main/res/layout/send_transaction.xml | 15 ++-- 5 files changed, 114 insertions(+), 12 deletions(-) create mode 100644 app/src/main/java/cy/agorise/crystalwallet/activities/ReceiveTransactionActivity.java create mode 100644 app/src/main/res/layout/receive_transaction.xml diff --git a/app/src/main/java/cy/agorise/crystalwallet/activities/ReceiveTransactionActivity.java b/app/src/main/java/cy/agorise/crystalwallet/activities/ReceiveTransactionActivity.java new file mode 100644 index 0000000..93e0c4a --- /dev/null +++ b/app/src/main/java/cy/agorise/crystalwallet/activities/ReceiveTransactionActivity.java @@ -0,0 +1,85 @@ +package cy.agorise.crystalwallet.activities; + +import android.arch.lifecycle.LiveData; +import android.arch.lifecycle.Observer; +import android.os.Bundle; +import android.support.annotation.Nullable; +import android.support.v7.app.AppCompatActivity; +import android.text.Editable; +import android.widget.Button; +import android.widget.EditText; +import android.widget.Spinner; +import android.widget.TextView; + +import java.util.ArrayList; +import java.util.List; + +import butterknife.BindView; +import butterknife.ButterKnife; +import butterknife.OnClick; +import butterknife.OnItemSelected; +import butterknife.OnTextChanged; +import cy.agorise.crystalwallet.R; +import cy.agorise.crystalwallet.cryptonetinforequests.ValidateBitsharesSendRequest; +import cy.agorise.crystalwallet.dao.CrystalDatabase; +import cy.agorise.crystalwallet.models.CryptoCoinBalance; +import cy.agorise.crystalwallet.models.CryptoCurrency; +import cy.agorise.crystalwallet.models.CryptoNetAccount; +import cy.agorise.crystalwallet.models.GrapheneAccount; +import cy.agorise.crystalwallet.viewmodels.validators.SendTransactionValidator; +import cy.agorise.crystalwallet.viewmodels.validators.UIValidatorListener; +import cy.agorise.crystalwallet.viewmodels.validators.validationfields.ValidationField; +import cy.agorise.crystalwallet.views.CryptoCurrencyAdapter; + +public class ReceiveTransactionActivity extends AppCompatActivity { + + @BindView(R.id.tvReceiveAddress) + TextView tvReceiveAddress; + + private long cryptoNetAccountId; + private CryptoNetAccount cryptoNetAccount; + private GrapheneAccount grapheneAccount; + private CrystalDatabase db; + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.receive_transaction); + + ButterKnife.bind(this); + + this.cryptoNetAccountId = getIntent().getLongExtra("CRYPTO_NET_ACCOUNT_ID", -1); + + if (this.cryptoNetAccountId != -1) { + db = CrystalDatabase.getAppDatabase(this); + this.cryptoNetAccount = db.cryptoNetAccountDao().getById(this.cryptoNetAccountId); + + /* + * this is only for graphene accounts. + * + **/ + this.grapheneAccount = new GrapheneAccount(this.cryptoNetAccount); + this.grapheneAccount.loadInfo(db.grapheneAccountInfoDao().getByAccountId(this.cryptoNetAccountId)); + + final LiveData> balancesList = db.cryptoCoinBalanceDao().getBalancesFromAccount(cryptoNetAccountId); + balancesList.observe(this, new Observer>() { + @Override + public void onChanged(@Nullable List cryptoCoinBalances) { + ArrayList assetIds = new ArrayList(); + for (CryptoCoinBalance nextBalance : balancesList.getValue()) { + assetIds.add(nextBalance.getCryptoCurrencyId()); + } + List cryptoCurrencyList = db.cryptoCurrencyDao().getByIds(assetIds); + + CryptoCurrencyAdapter assetAdapter = new CryptoCurrencyAdapter(getApplicationContext(), android.R.layout.simple_spinner_item, cryptoCurrencyList); + //spAsset.setAdapter(assetAdapter); + } + }); + + //sendTransactionValidator = new SendTransactionValidator(this.getApplicationContext(), this.cryptoNetAccount, etFrom, etTo, spAsset, etAmount, etMemo); + //sendTransactionValidator.setListener(this); + } else { + this.finish(); + } + } +} diff --git a/app/src/main/java/cy/agorise/crystalwallet/activities/SendTransactionActivity.java b/app/src/main/java/cy/agorise/crystalwallet/activities/SendTransactionActivity.java index 76d9576..578daa8 100644 --- a/app/src/main/java/cy/agorise/crystalwallet/activities/SendTransactionActivity.java +++ b/app/src/main/java/cy/agorise/crystalwallet/activities/SendTransactionActivity.java @@ -38,6 +38,7 @@ import cy.agorise.crystalwallet.viewmodels.GrapheneAccountInfoViewModel; import cy.agorise.crystalwallet.viewmodels.validators.SendTransactionValidator; import cy.agorise.crystalwallet.viewmodels.validators.UIValidatorListener; import cy.agorise.crystalwallet.viewmodels.validators.validationfields.ValidationField; +import cy.agorise.crystalwallet.views.CryptoCurrencyAdapter; public class SendTransactionActivity extends AppCompatActivity implements UIValidatorListener { @@ -100,16 +101,12 @@ public class SendTransactionActivity extends AppCompatActivity implements UIVali @Override public void onChanged(@Nullable List cryptoCoinBalances) { ArrayList assetIds = new ArrayList(); - ArrayList assetLabels = new ArrayList(); for (CryptoCoinBalance nextBalance : balancesList.getValue()) { assetIds.add(nextBalance.getCryptoCurrencyId()); } List cryptoCurrencyList = db.cryptoCurrencyDao().getByIds(assetIds); - for (CryptoCurrency nextCurrency : cryptoCurrencyList) { - assetLabels.add(nextCurrency.getName()); - } - ArrayAdapter assetAdapter = new ArrayAdapter(getApplicationContext(), android.R.layout.simple_spinner_item, assetLabels); + CryptoCurrencyAdapter assetAdapter = new CryptoCurrencyAdapter(getApplicationContext(), android.R.layout.simple_spinner_item, cryptoCurrencyList); spAsset.setAdapter(assetAdapter); } }); diff --git a/app/src/main/java/cy/agorise/crystalwallet/views/CryptoCurrencyAdapter.java b/app/src/main/java/cy/agorise/crystalwallet/views/CryptoCurrencyAdapter.java index fc48763..cf5b4f3 100644 --- a/app/src/main/java/cy/agorise/crystalwallet/views/CryptoCurrencyAdapter.java +++ b/app/src/main/java/cy/agorise/crystalwallet/views/CryptoCurrencyAdapter.java @@ -1,8 +1,6 @@ package cy.agorise.crystalwallet.views; import android.content.Context; -import android.support.annotation.LayoutRes; -import android.support.annotation.NonNull; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; @@ -26,6 +24,11 @@ public class CryptoCurrencyAdapter extends ArrayAdapter { this.data = objects; } + @Override + public View getDropDownView(int position, View convertView, ViewGroup parent) { + return getView(position, convertView, parent); + } + @Override public View getView(int position, View convertView, ViewGroup parent) { LayoutInflater inflater = (LayoutInflater)this.getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE); diff --git a/app/src/main/res/layout/receive_transaction.xml b/app/src/main/res/layout/receive_transaction.xml new file mode 100644 index 0000000..bb2946e --- /dev/null +++ b/app/src/main/res/layout/receive_transaction.xml @@ -0,0 +1,12 @@ + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/send_transaction.xml b/app/src/main/res/layout/send_transaction.xml index 4a46560..a749d9c 100644 --- a/app/src/main/res/layout/send_transaction.xml +++ b/app/src/main/res/layout/send_transaction.xml @@ -19,7 +19,8 @@ + android:id="@+id/tvFromError" + android:textColor="@color/red" /> + android:id="@+id/tvToError" + android:textColor="@color/red" /> + android:id="@+id/tvAssetError" + android:textColor="@color/red" /> + android:id="@+id/tvAmountError" + android:textColor="@color/red" /> + android:id="@+id/tvMemoError" + android:textColor="@color/red" />