- Fixed account selection in Receive Fragment
- Now the send fragment loads the qr scanned info
This commit is contained in:
parent
09ae532446
commit
e3a20eabaa
3 changed files with 54 additions and 2 deletions
|
@ -221,8 +221,16 @@ public class BoardActivity extends AppCompatActivity {
|
||||||
}
|
}
|
||||||
ft.addToBackStack(null);
|
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.
|
// Create and show the dialog.
|
||||||
ReceiveTransactionFragment newFragment = ReceiveTransactionFragment.newInstance(this.cryptoNetAccountId);
|
ReceiveTransactionFragment newFragment = ReceiveTransactionFragment.newInstance(receiveCryptoNetAccountId);
|
||||||
newFragment.show(ft, "ReceiveDialog");
|
newFragment.show(ft, "ReceiveDialog");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -4,6 +4,7 @@ import android.app.Dialog;
|
||||||
import android.app.LauncherActivity;
|
import android.app.LauncherActivity;
|
||||||
import android.arch.lifecycle.LiveData;
|
import android.arch.lifecycle.LiveData;
|
||||||
import android.arch.lifecycle.Observer;
|
import android.arch.lifecycle.Observer;
|
||||||
|
import android.arch.lifecycle.ViewModelProviders;
|
||||||
import android.content.DialogInterface;
|
import android.content.DialogInterface;
|
||||||
import android.graphics.Bitmap;
|
import android.graphics.Bitmap;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
|
@ -31,6 +32,8 @@ import com.google.zxing.WriterException;
|
||||||
import com.google.zxing.common.BitMatrix;
|
import com.google.zxing.common.BitMatrix;
|
||||||
|
|
||||||
import butterknife.OnClick;
|
import butterknife.OnClick;
|
||||||
|
import cy.agorise.crystalwallet.viewmodels.CryptoNetAccountListViewModel;
|
||||||
|
import cy.agorise.crystalwallet.views.CryptoNetAccountAdapter;
|
||||||
import cy.agorise.graphenej.Invoice;
|
import cy.agorise.graphenej.Invoice;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
@ -57,6 +60,8 @@ public class ReceiveTransactionFragment extends DialogFragment implements UIVali
|
||||||
|
|
||||||
ReceiveTransactionValidator receiveTransactionValidator;
|
ReceiveTransactionValidator receiveTransactionValidator;
|
||||||
|
|
||||||
|
@BindView(R.id.spTo)
|
||||||
|
Spinner spTo;
|
||||||
@BindView(R.id.etAmount)
|
@BindView(R.id.etAmount)
|
||||||
EditText etAmount;
|
EditText etAmount;
|
||||||
@BindView(R.id.tvAmountError)
|
@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 = new ReceiveTransactionValidator(this.getContext(), this.cryptoNetAccount, spAsset, etAmount);
|
||||||
receiveTransactionValidator.setListener(this);
|
receiveTransactionValidator.setListener(this);
|
||||||
|
|
||||||
|
CryptoNetAccountListViewModel cryptoNetAccountListViewModel = ViewModelProviders.of(this).get(CryptoNetAccountListViewModel.class);
|
||||||
|
List<CryptoNetAccount> 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);
|
builder.setView(view);
|
||||||
|
@ -199,6 +210,11 @@ public class ReceiveTransactionFragment extends DialogFragment implements UIVali
|
||||||
}, 400);
|
}, 400);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@OnItemSelected(R.id.spTo)
|
||||||
|
public void afterToSelected(Spinner spinner, int position) {
|
||||||
|
this.receiveTransactionValidator.validate();
|
||||||
|
}
|
||||||
|
|
||||||
@OnTextChanged(value = R.id.etAmount,
|
@OnTextChanged(value = R.id.etAmount,
|
||||||
callback = OnTextChanged.Callback.AFTER_TEXT_CHANGED)
|
callback = OnTextChanged.Callback.AFTER_TEXT_CHANGED)
|
||||||
void afterAmountChanged(Editable editable) {
|
void afterAmountChanged(Editable editable) {
|
||||||
|
|
|
@ -32,8 +32,12 @@ import android.widget.Toast;
|
||||||
|
|
||||||
import com.google.zxing.Result;
|
import com.google.zxing.Result;
|
||||||
|
|
||||||
|
import java.math.RoundingMode;
|
||||||
|
import java.text.DecimalFormat;
|
||||||
|
import java.text.DecimalFormatSymbols;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Locale;
|
||||||
|
|
||||||
import butterknife.BindView;
|
import butterknife.BindView;
|
||||||
import butterknife.ButterKnife;
|
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.viewmodels.validators.validationfields.ValidationField;
|
||||||
import cy.agorise.crystalwallet.views.CryptoCurrencyAdapter;
|
import cy.agorise.crystalwallet.views.CryptoCurrencyAdapter;
|
||||||
import cy.agorise.crystalwallet.views.CryptoNetAccountAdapter;
|
import cy.agorise.crystalwallet.views.CryptoNetAccountAdapter;
|
||||||
|
import cy.agorise.graphenej.Invoice;
|
||||||
|
import cy.agorise.graphenej.LineItem;
|
||||||
import me.dm7.barcodescanner.zxing.ZXingScannerView;
|
import me.dm7.barcodescanner.zxing.ZXingScannerView;
|
||||||
|
|
||||||
public class SendTransactionFragment extends DialogFragment implements UIValidatorListener, ZXingScannerView.ResultHandler {
|
public class SendTransactionFragment extends DialogFragment implements UIValidatorListener, ZXingScannerView.ResultHandler {
|
||||||
|
@ -91,6 +97,7 @@ public class SendTransactionFragment extends DialogFragment implements UIValidat
|
||||||
TextView btnCancel;
|
TextView btnCancel;
|
||||||
@BindView(R.id.ivPeople)
|
@BindView(R.id.ivPeople)
|
||||||
ImageView ivPeople;
|
ImageView ivPeople;
|
||||||
|
CryptoCurrencyAdapter assetAdapter;
|
||||||
|
|
||||||
Button btnScanQrCode;
|
Button btnScanQrCode;
|
||||||
|
|
||||||
|
@ -154,7 +161,7 @@ public class SendTransactionFragment extends DialogFragment implements UIValidat
|
||||||
}
|
}
|
||||||
List<CryptoCurrency> cryptoCurrencyList = db.cryptoCurrencyDao().getByIds(assetIds);
|
List<CryptoCurrency> 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);
|
spAsset.setAdapter(assetAdapter);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -370,6 +377,27 @@ public class SendTransactionFragment extends DialogFragment implements UIValidat
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void handleResult(Result result) {
|
public void handleResult(Result result) {
|
||||||
|
Invoice invoice = Invoice.fromQrCode(result.getText());
|
||||||
|
|
||||||
|
etTo.setText(invoice.getTo());
|
||||||
|
|
||||||
|
for (int i=0;i<assetAdapter.getCount();i++) {
|
||||||
|
if (assetAdapter.getItem(i).getName().equals(invoice.getCurrency())) {
|
||||||
|
spAsset.setSelection(i);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
etMemo.setText(invoice.getMemo());
|
||||||
|
|
||||||
|
|
||||||
|
double amount = 0.0;
|
||||||
|
for (LineItem nextItem : invoice.getLineItems()) {
|
||||||
|
amount += nextItem.getQuantity() * nextItem.getPrice();
|
||||||
|
}
|
||||||
|
DecimalFormat df = new DecimalFormat("####.####");
|
||||||
|
df.setRoundingMode(RoundingMode.CEILING);
|
||||||
|
df.setDecimalFormatSymbols(new DecimalFormatSymbols(Locale.ENGLISH));
|
||||||
|
etAmount.setText(df.format(amount));
|
||||||
Log.i("SendFragment",result.getText());
|
Log.i("SendFragment",result.getText());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue