- Adding send and cancel button to Send DialogFragment

- Adding ReceiveTransaction DialogFragment.
- Generating QrCode to receive transactions
This commit is contained in:
Javier Varona 2017-11-28 21:50:46 -04:00
parent cef71b382b
commit a541a70c1a
13 changed files with 533 additions and 38 deletions

View file

@ -49,6 +49,8 @@ dependencies {
compile 'org.tukaani:xz:1.6' compile 'org.tukaani:xz:1.6'
compile 'com.jakewharton:butterknife:8.8.1' compile 'com.jakewharton:butterknife:8.8.1'
compile 'com.github.bilthon:graphenej:0.4.6-alpha1' compile 'com.github.bilthon:graphenej:0.4.6-alpha1'
compile 'com.google.zxing:core:3.3.1';
testCompile 'junit:junit:4.12' testCompile 'junit:junit:4.12'
testCompile 'org.mockito:mockito-core:1.10.19' testCompile 'org.mockito:mockito-core:1.10.19'
annotationProcessor 'android.arch.lifecycle:compiler:1.0.0' annotationProcessor 'android.arch.lifecycle:compiler:1.0.0'

View file

@ -33,7 +33,7 @@ import cy.agorise.crystalwallet.views.CryptoCurrencyAdapter;
public class ReceiveTransactionActivity extends AppCompatActivity { public class ReceiveTransactionActivity extends AppCompatActivity {
@BindView(R.id.tvReceiveAddress) //@BindView(R.id.tvReceiveAddress)
TextView tvReceiveAddress; TextView tvReceiveAddress;
private long cryptoNetAccountId; private long cryptoNetAccountId;

View file

@ -64,9 +64,9 @@ public class SendTransactionActivity extends AppCompatActivity implements UIVali
EditText etMemo; EditText etMemo;
@BindView(R.id.tvMemoError) @BindView(R.id.tvMemoError)
TextView tvMemoError; TextView tvMemoError;
@BindView(R.id.btnSend) //@BindView(R.id.btnSend)
Button btnSend; Button btnSend;
@BindView(R.id.btnCancel) //@BindView(R.id.btnCancel)
Button btnCancel; Button btnCancel;
private long cryptoNetAccountId; private long cryptoNetAccountId;
@ -153,7 +153,7 @@ public class SendTransactionActivity extends AppCompatActivity implements UIVali
this.finish(); this.finish();
} }
@OnClick(R.id.btnSend) //@OnClick(R.id.btnSend)
public void importSend(){ public void importSend(){
if (this.sendTransactionValidator.isValid()) { if (this.sendTransactionValidator.isValid()) {
//TODO convert the amount to long type using the precision of the currency //TODO convert the amount to long type using the precision of the currency

View file

@ -0,0 +1,278 @@
package cy.agorise.crystalwallet.fragments;
import android.app.Dialog;
import android.app.LauncherActivity;
import android.arch.lifecycle.LiveData;
import android.arch.lifecycle.Observer;
import android.content.DialogInterface;
import android.graphics.Bitmap;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v4.app.DialogFragment;
import android.support.v7.app.AlertDialog;
import android.text.Editable;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.Spinner;
import android.widget.TextView;
import com.google.zxing.BarcodeFormat;
import com.google.zxing.MultiFormatWriter;
import com.google.zxing.WriterException;
import com.google.zxing.common.BitMatrix;
import cy.agorise.graphenej.Invoice;
import java.util.ArrayList;
import java.util.List;
import butterknife.BindView;
import butterknife.ButterKnife;
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.ReceiveTransactionValidator;
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;
import cy.agorise.graphenej.LineItem;
public class ReceiveTransactionFragment extends DialogFragment implements UIValidatorListener {
ReceiveTransactionValidator receiveTransactionValidator;
@BindView(R.id.etAmount)
EditText etAmount;
@BindView(R.id.tvAmountError)
TextView tvAmountError;
@BindView(R.id.spAsset)
Spinner spAsset;
@BindView(R.id.tvAssetError)
TextView tvAssetError;
@BindView(R.id.ivQrCode)
ImageView ivQrCode;
private Button btnShareQrCode;
private Button btnClose;
private long cryptoNetAccountId;
private CryptoNetAccount cryptoNetAccount;
private CryptoCurrency cryptoCurrency;
private GrapheneAccount grapheneAccount;
private CrystalDatabase db;
private Invoice invoice;
private ArrayList<LineItem> invoiceItems;
public static ReceiveTransactionFragment newInstance(long cryptoNetAccountId) {
ReceiveTransactionFragment f = new ReceiveTransactionFragment();
// Supply num input as an argument.
Bundle args = new Bundle();
args.putLong("CRYPTO_NET_ACCOUNT_ID", cryptoNetAccountId);
f.setArguments(args);
f.invoiceItems = new ArrayList<LineItem>();
f.invoice = new Invoice("","","","",null,"","");
return f;
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
}
@NonNull
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
builder.setTitle("Receive Assets");
LayoutInflater inflater = getActivity().getLayoutInflater();
View view = inflater.inflate(R.layout.receive_transaction, null);
ButterKnife.bind(this, view);
this.cryptoNetAccountId = getArguments().getLong("CRYPTO_NET_ACCOUNT_ID",-1);
if (this.cryptoNetAccountId != -1) {
db = CrystalDatabase.getAppDatabase(this.getContext());
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<List<CryptoCoinBalance>> balancesList = db.cryptoCoinBalanceDao().getBalancesFromAccount(cryptoNetAccountId);
balancesList.observe(this, new Observer<List<CryptoCoinBalance>>() {
@Override
public void onChanged(@Nullable List<CryptoCoinBalance> cryptoCoinBalances) {
ArrayList<Long> assetIds = new ArrayList<Long>();
for (CryptoCoinBalance nextBalance : balancesList.getValue()) {
assetIds.add(nextBalance.getCryptoCurrencyId());
}
List<CryptoCurrency> cryptoCurrencyList = db.cryptoCurrencyDao().getByIds(assetIds);
CryptoCurrencyAdapter assetAdapter = new CryptoCurrencyAdapter(getContext(), android.R.layout.simple_spinner_item, cryptoCurrencyList);
spAsset.setAdapter(assetAdapter);
}
});
receiveTransactionValidator = new ReceiveTransactionValidator(this.getContext(), this.cryptoNetAccount, spAsset, etAmount);
receiveTransactionValidator.setListener(this);
}
builder.setView(view);
builder.setPositiveButton("Share this QR", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
shareQrCode();
}
});
builder.setNegativeButton("Close", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
}
});
AlertDialog dialog = builder.create();
dialog.setOnShowListener(new DialogInterface.OnShowListener() {
@Override
public void onShow(DialogInterface dialog) {
btnShareQrCode = ((AlertDialog)dialog).getButton(AlertDialog.BUTTON_POSITIVE);
btnClose = ((AlertDialog)dialog).getButton(AlertDialog.BUTTON_NEGATIVE);
btnShareQrCode.setEnabled(false);
}
});
return dialog;
}
@OnTextChanged(value = R.id.etAmount,
callback = OnTextChanged.Callback.AFTER_TEXT_CHANGED)
void afterAmountChanged(Editable editable) {
this.receiveTransactionValidator.validate();
}
@OnItemSelected(R.id.spAsset)
public void afterAssetSelected(Spinner spinner, int position) {
this.cryptoCurrency = (CryptoCurrency)spinner.getSelectedItem();
this.receiveTransactionValidator.validate();
}
public void shareQrCode(){
if (this.receiveTransactionValidator.isValid()) {
//Share Qr Code
}
}
@Override
public void onValidationSucceeded(final ValidationField field) {
final ReceiveTransactionFragment fragment = this;
if (field.getView() == etAmount){
tvAmountError.setText("");
} else if (field.getView() == spAsset){
tvAssetError.setText("");
}
if (btnShareQrCode != null) {
if (receiveTransactionValidator.isValid()) {
createQrCode();
btnShareQrCode.setEnabled(true);
} else {
btnShareQrCode.setEnabled(false);
}
}
}
@Override
public void onValidationFailed(ValidationField field) {
if (field.getView() == spAsset){
tvAssetError.setText(field.getMessage());
} else if (field.getView() == etAmount){
tvAmountError.setText(field.getMessage());
}
ivQrCode.setImageResource(android.R.color.transparent);
}
public void createQrCode(){
Double amount = 0.0;
try{
amount = Double.valueOf(this.etAmount.getText().toString());
} catch(NumberFormatException e){
Log.e("ReceiveFragment","Amount casting error.");
}
this.invoiceItems.clear();
this.invoiceItems.add(
new LineItem("transfer", 1, amount)
);
LineItem items[] = new LineItem[this.invoiceItems.size()];
items = this.invoiceItems.toArray(items);
this.invoice.setLineItems(items);
this.invoice.setTo(this.grapheneAccount.getName());
this.invoice.setCurrency(this.cryptoCurrency.getName());
try {
Bitmap bitmap = textToImageEncode(Invoice.toQrCode(invoice));
ivQrCode.setImageBitmap(bitmap);
} catch (WriterException e) {
Log.e("ReceiveFragment", "Error creating QrCode");
}
}
Bitmap textToImageEncode(String Value) throws WriterException {
//TODO: do this in another thread
BitMatrix bitMatrix;
try {
bitMatrix = new MultiFormatWriter().encode(
Value,
BarcodeFormat.DATA_MATRIX.QR_CODE,
ivQrCode.getWidth(), ivQrCode.getHeight(), null
);
} catch (IllegalArgumentException Illegalargumentexception) {
return null;
}
int bitMatrixWidth = bitMatrix.getWidth();
int bitMatrixHeight = bitMatrix.getHeight();
int[] pixels = new int[bitMatrixWidth * bitMatrixHeight];
for (int y = 0; y < bitMatrixHeight; y++) {
int offset = y * bitMatrixWidth;
for (int x = 0; x < bitMatrixWidth; x++) {
pixels[offset + x] = bitMatrix.get(x, y) ?
getResources().getColor(R.color.QRCodeBlackColor):getResources().getColor(R.color.QRCodeWhiteColor);
}
}
Bitmap bitmap = Bitmap.createBitmap(bitMatrixWidth, bitMatrixHeight, Bitmap.Config.ARGB_4444);
bitmap.setPixels(pixels, 0, ivQrCode.getWidth(), 0, 0, bitMatrixWidth, bitMatrixHeight);
return bitmap;
}
}

View file

@ -1,11 +1,15 @@
package cy.agorise.crystalwallet.fragments; package cy.agorise.crystalwallet.fragments;
import android.app.Dialog;
import android.arch.lifecycle.LiveData; import android.arch.lifecycle.LiveData;
import android.arch.lifecycle.Observer; import android.arch.lifecycle.Observer;
import android.content.DialogInterface;
import android.os.Bundle; import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable; import android.support.annotation.Nullable;
import android.support.v4.app.DialogFragment; import android.support.v4.app.DialogFragment;
import android.support.v4.app.Fragment; import android.support.v4.app.Fragment;
import android.support.v7.app.AlertDialog;
import android.support.v7.app.AppCompatActivity; import android.support.v7.app.AppCompatActivity;
import android.text.Editable; import android.text.Editable;
import android.view.LayoutInflater; import android.view.LayoutInflater;
@ -60,9 +64,9 @@ public class SendTransactionFragment extends DialogFragment implements UIValidat
EditText etMemo; EditText etMemo;
@BindView(R.id.tvMemoError) @BindView(R.id.tvMemoError)
TextView tvMemoError; TextView tvMemoError;
@BindView(R.id.btnSend) //@BindView(R.id.btnSend)
Button btnSend; Button btnSend;
@BindView(R.id.btnCancel) //@BindView(R.id.btnCancel)
Button btnCancel; Button btnCancel;
private long cryptoNetAccountId; private long cryptoNetAccountId;
@ -86,12 +90,15 @@ public class SendTransactionFragment extends DialogFragment implements UIValidat
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
} }
public View onCreateView(LayoutInflater inflater, ViewGroup container, @NonNull
Bundle savedInstanceState){ @Override
View view = inflater.inflate(R.layout.send_transaction, container, false); public Dialog onCreateDialog(Bundle savedInstanceState) {
ButterKnife.bind(this, view); AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
builder.setTitle("Send");
btnSend.setEnabled(false); LayoutInflater inflater = getActivity().getLayoutInflater();
View view = inflater.inflate(R.layout.send_transaction, null);
ButterKnife.bind(this, view);
this.cryptoNetAccountId = getArguments().getLong("CRYPTO_NET_ACCOUNT_ID",-1); this.cryptoNetAccountId = getArguments().getLong("CRYPTO_NET_ACCOUNT_ID",-1);
@ -126,8 +133,74 @@ public class SendTransactionFragment extends DialogFragment implements UIValidat
etFrom.setText(this.grapheneAccount.getName()); etFrom.setText(this.grapheneAccount.getName());
} }
return view; builder.setView(view);
builder.setPositiveButton("Send", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
sendTransaction();
} }
});
builder.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
}
});
AlertDialog dialog = builder.create();
dialog.setOnShowListener(new DialogInterface.OnShowListener() {
@Override
public void onShow(DialogInterface dialog) {
btnSend = ((AlertDialog)dialog).getButton(AlertDialog.BUTTON_POSITIVE);
btnCancel = ((AlertDialog)dialog).getButton(AlertDialog.BUTTON_NEGATIVE);
btnSend.setEnabled(false);
}
});
return dialog;
}
/*public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState){
View view = inflater.inflate(R.layout.send_transaction, container, false);
ButterKnife.bind(this, view);
btnSend.setEnabled(false);
this.cryptoNetAccountId = getArguments().getLong("CRYPTO_NET_ACCOUNT_ID",-1);
if (this.cryptoNetAccountId != -1) {
db = CrystalDatabase.getAppDatabase(this.getContext());
this.cryptoNetAccount = db.cryptoNetAccountDao().getById(this.cryptoNetAccountId);
this.grapheneAccount = new GrapheneAccount(this.cryptoNetAccount);
this.grapheneAccount.loadInfo(db.grapheneAccountInfoDao().getByAccountId(this.cryptoNetAccountId));
final LiveData<List<CryptoCoinBalance>> balancesList = db.cryptoCoinBalanceDao().getBalancesFromAccount(cryptoNetAccountId);
balancesList.observe(this, new Observer<List<CryptoCoinBalance>>() {
@Override
public void onChanged(@Nullable List<CryptoCoinBalance> cryptoCoinBalances) {
ArrayList<Long> assetIds = new ArrayList<Long>();
for (CryptoCoinBalance nextBalance : balancesList.getValue()) {
assetIds.add(nextBalance.getCryptoCurrencyId());
}
List<CryptoCurrency> cryptoCurrencyList = db.cryptoCurrencyDao().getByIds(assetIds);
CryptoCurrencyAdapter assetAdapter = new CryptoCurrencyAdapter(getContext(), android.R.layout.simple_spinner_item, cryptoCurrencyList);
spAsset.setAdapter(assetAdapter);
}
});
sendTransactionValidator = new SendTransactionValidator(this.getContext(), this.cryptoNetAccount, etFrom, etTo, spAsset, etAmount, etMemo);
sendTransactionValidator.setListener(this);
etFrom.setText(this.grapheneAccount.getName());
}
return view;
}*/
@OnTextChanged(value = R.id.etFrom, @OnTextChanged(value = R.id.etFrom,
callback = OnTextChanged.Callback.AFTER_TEXT_CHANGED) callback = OnTextChanged.Callback.AFTER_TEXT_CHANGED)
@ -164,8 +237,8 @@ public class SendTransactionFragment extends DialogFragment implements UIValidat
// this.finish(); // this.finish();
//} //}
@OnClick(R.id.btnSend) //@OnClick(R.id.btnSend)
public void importSend(){ public void sendTransaction(){
if (this.sendTransactionValidator.isValid()) { if (this.sendTransactionValidator.isValid()) {
//TODO convert the amount to long type using the precision of the currency //TODO convert the amount to long type using the precision of the currency
ValidateBitsharesSendRequest sendRequest = new ValidateBitsharesSendRequest( ValidateBitsharesSendRequest sendRequest = new ValidateBitsharesSendRequest(
@ -198,12 +271,14 @@ public class SendTransactionFragment extends DialogFragment implements UIValidat
tvMemoError.setText(""); tvMemoError.setText("");
} }
if (btnSend != null) {
if (sendTransactionValidator.isValid()) { if (sendTransactionValidator.isValid()) {
btnSend.setEnabled(true); btnSend.setEnabled(true);
} else { } else {
btnSend.setEnabled(false); btnSend.setEnabled(false);
} }
} }
}
@Override @Override
public void onValidationFailed(ValidationField field) { public void onValidationFailed(ValidationField field) {

View file

@ -0,0 +1,34 @@
package cy.agorise.crystalwallet.viewmodels.validators;
import android.content.Context;
import android.widget.EditText;
import android.widget.Spinner;
import cy.agorise.crystalwallet.models.CryptoNetAccount;
import cy.agorise.crystalwallet.viewmodels.validators.validationfields.AmountValidationField;
import cy.agorise.crystalwallet.viewmodels.validators.validationfields.AssetValidationField;
import cy.agorise.crystalwallet.viewmodels.validators.validationfields.FromValidationField;
import cy.agorise.crystalwallet.viewmodels.validators.validationfields.MemoValidationField;
import cy.agorise.crystalwallet.viewmodels.validators.validationfields.ReceiveAmountValidationField;
import cy.agorise.crystalwallet.viewmodels.validators.validationfields.ToValidationField;
/**
* Created by Henry Varona on 2/10/2017.
*/
public class ReceiveTransactionValidator extends UIValidator {
private CryptoNetAccount account;
public ReceiveTransactionValidator(Context context, CryptoNetAccount account, Spinner assetSpinner, EditText amountEdit){
super(context);
this.account = account;
this.addField(new AssetValidationField(assetSpinner));
this.addField(new ReceiveAmountValidationField(amountEdit));
}
public CryptoNetAccount getAccount() {
return account;
}
}

View file

@ -27,9 +27,13 @@ public class AssetValidationField extends ValidationField {
if (cryptoCurrencySelected != null) { if (cryptoCurrencySelected != null) {
final String newValue = "" + cryptoCurrencySelected.getId(); final String newValue = "" + cryptoCurrencySelected.getId();
this.setLastValue(newValue); this.setLastValue(newValue);
setValidForValue(newValue, true);
validator.validationSucceeded(this); validator.validationSucceeded(this);
} else { } else {
final String newValue = ""+-1;
setMessage("Select a currency"); setMessage("Select a currency");
this.setLastValue(newValue);
setValidForValue(newValue, false);
validator.validationFailed(this); validator.validationFailed(this);
} }
} }

View file

@ -0,0 +1,41 @@
package cy.agorise.crystalwallet.viewmodels.validators.validationfields;
import android.widget.EditText;
import android.widget.Spinner;
import cy.agorise.crystalwallet.R;
import cy.agorise.crystalwallet.dao.CrystalDatabase;
import cy.agorise.crystalwallet.models.CryptoCoinBalance;
import cy.agorise.crystalwallet.models.CryptoCurrency;
import cy.agorise.crystalwallet.models.CryptoNetAccount;
/**
* Created by Henry Varona on 26/11/2017.
*/
public class ReceiveAmountValidationField extends ValidationField {
private EditText amountField;
public ReceiveAmountValidationField(EditText amountField) {
super(amountField);
this.amountField = amountField;
}
public void validate(){
String newAmountText = amountField.getText().toString();
try {
final float newAmountValue = Float.parseFloat(newAmountText);
} catch (NumberFormatException e){
this.setLastValue(newAmountText);
setValidForValue(newAmountText, false);
validator.validationFailed(this);
return;
}
this.setLastValue(newAmountText);
this.startValidating();
setValidForValue(newAmountText, true);
validator.validationSucceeded(this);
}
}

View file

@ -17,7 +17,7 @@ public class ToValidationField extends ValidationField {
private EditText toField; private EditText toField;
public ToValidationField(EditText fromField, EditText toField){ public ToValidationField(EditText fromField, EditText toField){
super(fromField); super(toField);
this.fromField = fromField; this.fromField = fromField;
this.toField = toField; this.toField = toField;
} }
@ -25,20 +25,27 @@ public class ToValidationField extends ValidationField {
public void validate(){ public void validate(){
final String fromNewValue = fromField.getText().toString(); final String fromNewValue = fromField.getText().toString();
final String toNewValue = toField.getText().toString(); final String toNewValue = toField.getText().toString();
this.setLastValue(toNewValue); final String mixedValue = fromNewValue+"_"+toNewValue;
this.setLastValue(mixedValue);
this.startValidating(); this.startValidating();
final ValidationField field = this; final ValidationField field = this;
if (fromNewValue.equals(toNewValue)){
setValidForValue(mixedValue, false);
setMessage(validator.getContext().getResources().getString(R.string.warning_msg_same_account));
validator.validationFailed(field);
} else {
final ValidateExistBitsharesAccountRequest request = new ValidateExistBitsharesAccountRequest(toNewValue); final ValidateExistBitsharesAccountRequest request = new ValidateExistBitsharesAccountRequest(toNewValue);
request.setListener(new CryptoNetInfoRequestListener() { request.setListener(new CryptoNetInfoRequestListener() {
@Override @Override
public void onCarryOut() { public void onCarryOut() {
if (!request.getAccountExists()) { if (!request.getAccountExists()) {
setValidForValue(toNewValue, false); setValidForValue(mixedValue, false);
setMessage(validator.getContext().getResources().getString(R.string.account_name_not_exist)); setMessage(validator.getContext().getResources().getString(R.string.account_name_not_exist));
validator.validationFailed(field); validator.validationFailed(field);
} else { } else {
setValidForValue(toNewValue, true); setValidForValue(mixedValue, true);
validator.validationSucceeded(field); validator.validationSucceeded(field);
} }
} }
@ -46,3 +53,4 @@ public class ToValidationField extends ValidationField {
CryptoNetInfoRequests.getInstance().addRequest(request); CryptoNetInfoRequests.getInstance().addRequest(request);
} }
} }
}

View file

@ -23,6 +23,7 @@ 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.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;
@ -58,6 +59,12 @@ public class CryptoNetBalanceViewHolder extends RecyclerView.ViewHolder {
@BindView(R.id.btnSendFromThisAccount) @BindView(R.id.btnSendFromThisAccount)
Button btnSendFromThisAccount; Button btnSendFromThisAccount;
/*
* The button for receiving transactions to this crypto net balance account
*/
@BindView(R.id.btnReceiveWithThisAccount)
Button btnReceiveToThisAccount;
Context context; Context context;
/* /*
@ -81,6 +88,7 @@ public class CryptoNetBalanceViewHolder extends RecyclerView.ViewHolder {
cryptoNetName = (TextView) itemView.findViewById(R.id.tvCryptoNetName); cryptoNetName = (TextView) itemView.findViewById(R.id.tvCryptoNetName);
cryptoCoinBalanceListView = (CryptoCoinBalanceListView) itemView.findViewById(R.id.cryptoCoinBalancesListView); cryptoCoinBalanceListView = (CryptoCoinBalanceListView) itemView.findViewById(R.id.cryptoCoinBalancesListView);
btnSendFromThisAccount = (Button) itemView.findViewById(R.id.btnSendFromThisAccount); btnSendFromThisAccount = (Button) itemView.findViewById(R.id.btnSendFromThisAccount);
btnReceiveToThisAccount = (Button) itemView.findViewById(R.id.btnReceiveWithThisAccount);
//Setting the send button //Setting the send button
btnSendFromThisAccount.setOnClickListener(new View.OnClickListener() { btnSendFromThisAccount.setOnClickListener(new View.OnClickListener() {
@ -89,6 +97,12 @@ public class CryptoNetBalanceViewHolder extends RecyclerView.ViewHolder {
sendFromThisAccount(); sendFromThisAccount();
} }
}); });
btnReceiveToThisAccount.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
receiveToThisAccount();
}
});
this.fragment = fragment; this.fragment = fragment;
this.context = itemView.getContext(); this.context = itemView.getContext();
} }
@ -127,6 +141,22 @@ public class CryptoNetBalanceViewHolder extends RecyclerView.ViewHolder {
newFragment.show(ft, "SendDialog"); newFragment.show(ft, "SendDialog");
} }
/*
* dispatch the user to the receive activity using this account
*/
public void receiveToThisAccount(){
FragmentTransaction ft = fragment.getFragmentManager().beginTransaction();
Fragment prev = fragment.getFragmentManager().findFragmentByTag("ReceiveDialog");
if (prev != null) {
ft.remove(prev);
}
ft.addToBackStack(null);
// Create and show the dialog.
ReceiveTransactionFragment newFragment = ReceiveTransactionFragment.newInstance(this.cryptoNetAccountId);
newFragment.show(ft, "ReceiveDialog");
}
/* /*
* Binds this view with the data of an element of the list * Binds this view with the data of an element of the list
*/ */

View file

@ -5,8 +5,29 @@
android:orientation="vertical" android:orientation="vertical"
android:weightSum="1"> android:weightSum="1">
<TextView <EditText
android:id="@+id/etAmount"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<TextView
android:id="@+id/tvAmountError"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<Spinner
android:id="@+id/spAsset"
android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:id="@+id/tvReceiveAddress"/> android:gravity="top"
android:inputType="textMultiLine"
android:textColor="@color/white" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/tvAssetError"
android:textColor="@color/red" />
<ImageView
android:id="@+id/ivQrCode"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:adjustViewBounds="true"/>
</LinearLayout> </LinearLayout>

View file

@ -90,7 +90,7 @@
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:id="@+id/tvMemoError" android:id="@+id/tvMemoError"
android:textColor="@color/red" /> android:textColor="@color/red" />
<Button <!--<Button
android:id="@+id/btnCancel" android:id="@+id/btnCancel"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
@ -101,5 +101,5 @@
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:text="@string/send_capital"> android:text="@string/send_capital">
</Button> </Button>-->
</LinearLayout> </LinearLayout>

View file

@ -36,4 +36,6 @@
<color name="color_preloader_start">#000000</color> <color name="color_preloader_start">#000000</color>
<color name="color_preloader_center">#000000</color> <color name="color_preloader_center">#000000</color>
<color name="color_preloader_end">#ff56a9c7</color> <color name="color_preloader_end">#ff56a9c7</color>
<color name="QRCodeBlackColor">#000000</color>
<color name="QRCodeWhiteColor">#ffffff</color>
</resources> </resources>