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 dbf3848..bc94748 100644 --- a/app/src/main/java/cy/agorise/crystalwallet/fragments/ReceiveTransactionFragment.java +++ b/app/src/main/java/cy/agorise/crystalwallet/fragments/ReceiveTransactionFragment.java @@ -29,6 +29,7 @@ import android.widget.EditText; import android.widget.ImageView; import android.widget.Spinner; import android.widget.TextView; +import android.widget.Toast; import com.google.zxing.BarcodeFormat; import com.google.zxing.MultiFormatWriter; @@ -38,6 +39,10 @@ import com.google.zxing.common.BitMatrix; import butterknife.OnClick; import cy.agorise.crystalwallet.enums.CryptoCoin; import cy.agorise.crystalwallet.enums.CryptoNet; +import cy.agorise.crystalwallet.requestmanagers.CalculateBitcoinUriRequest; +import cy.agorise.crystalwallet.requestmanagers.CryptoNetInfoRequestListener; +import cy.agorise.crystalwallet.requestmanagers.CryptoNetInfoRequests; +import cy.agorise.crystalwallet.requestmanagers.NextBitcoinAccountAddressRequest; import cy.agorise.crystalwallet.util.CircularImageView; import cy.agorise.crystalwallet.viewmodels.CryptoNetAccountListViewModel; import cy.agorise.crystalwallet.views.CryptoNetAccountAdapter; @@ -341,52 +346,104 @@ public class ReceiveTransactionFragment extends DialogFragment implements UIVali CryptoNetAccount toAccountSelected = (CryptoNetAccount) spTo.getSelectedItem(); - /* - * this is only for graphene accounts. - * - **/ - GrapheneAccount grapheneAccountSelected = new GrapheneAccount(toAccountSelected); - grapheneAccountSelected.loadInfo(db.grapheneAccountInfoDao().getByAccountId(toAccountSelected.getId())); + if (this.cryptoNetAccount.getCryptoNet() == CryptoNet.BITSHARES) { + /* + * this is only for graphene accounts. + * + **/ + GrapheneAccount grapheneAccountSelected = new GrapheneAccount(toAccountSelected); + grapheneAccountSelected.loadInfo(db.grapheneAccountInfoDao().getByAccountId(toAccountSelected.getId())); - this.invoiceItems.clear(); - this.invoiceItems.add( - new LineItem("transfer", 1, amount) - ); + 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(grapheneAccountSelected.getName()); - this.invoice.setCurrency(this.cryptoCurrency.getName()); + LineItem items[] = new LineItem[this.invoiceItems.size()]; + items = this.invoiceItems.toArray(items); + this.invoice.setLineItems(items); + this.invoice.setTo(grapheneAccountSelected.getName()); + this.invoice.setCurrency(this.cryptoCurrency.getName()); - if (this.qrCodeTask != null){ - this.qrCodeTask.cancel(true); - } + if (this.qrCodeTask != null) { + this.qrCodeTask.cancel(true); + } - this.qrCodeTask = new AsyncTask(){ + this.qrCodeTask = new AsyncTask() { - @Override - protected Void doInBackground(Object... voids) { - try { - final Bitmap bitmap = textToImageEncode(Invoice.toQrCode(invoice)); + @Override + protected Void doInBackground(Object... voids) { + try { + final Bitmap bitmap = textToImageEncode(Invoice.toQrCode(invoice)); - if (!this.isCancelled()) { - ReceiveTransactionFragment.this.getActivity().runOnUiThread(new Runnable() { + if (!this.isCancelled()) { + ReceiveTransactionFragment.this.getActivity().runOnUiThread(new Runnable() { + @Override + public void run() { + ivQrCode.setImageBitmap(bitmap); + } + }); + } + } catch (WriterException e) { + Log.e("ReceiveFragment", "Error creating QrCode"); + } + return null; + } + }; + + this.qrCodeTask.execute(null, null, null); + } else { + final CryptoCoin cryptoCoin = CryptoCoin.getByCryptoNet(this.cryptoNetAccount.getCryptoNet()).get(0); + + //final NextBitcoinAccountAddressRequest addressRequest = new NextBitcoinAccountAddressRequest(this.cryptoNetAccount, cryptoCoin, getContext()); + + //addressRequest.setListener(new CryptoNetInfoRequestListener() { + // @Override + // public void onCarryOut() { + // if (addressRequest.getStatus() == NextBitcoinAccountAddressRequest.StatusCode.SUCCEEDED){ + final CalculateBitcoinUriRequest uriRequest = new CalculateBitcoinUriRequest(cryptoCoin, cryptoNetAccount, getContext()); + + uriRequest.setListener(new CryptoNetInfoRequestListener(){ @Override - public void run() { - ivQrCode.setImageBitmap(bitmap); + public void onCarryOut(){ + if (uriRequest.getUri() != null){ + qrCodeTask = new AsyncTask() { + + @Override + protected Void doInBackground(Object... voids) { + try { + final Bitmap bitmap = textToImageEncode(uriRequest.getUri()); + + if (!this.isCancelled()) { + ReceiveTransactionFragment.this.getActivity().runOnUiThread(new Runnable() { + @Override + public void run() { + ivQrCode.setImageBitmap(bitmap); + } + }); + } + } catch (WriterException e) { + Log.e("ReceiveFragment", "Error creating QrCode"); + } + return null; + } + }; + + qrCodeTask.execute(null, null, null); + } else { + Log.e("ReceiveFragment", "Error obtaining the uri"); + } } }); - } - } catch (WriterException e) { - Log.e("ReceiveFragment", "Error creating QrCode"); - } - return null; - } - }; - this.qrCodeTask.execute(null,null,null); + CryptoNetInfoRequests.getInstance().addRequest(uriRequest); + // } else { + // Toast.makeText(getContext(),"Error creating address",Toast.LENGTH_SHORT); + // } + // } + //}); + } } Bitmap textToImageEncode(String Value) throws WriterException { 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 e3490f4..d60a221 100644 --- a/app/src/main/java/cy/agorise/crystalwallet/fragments/SendTransactionFragment.java +++ b/app/src/main/java/cy/agorise/crystalwallet/fragments/SendTransactionFragment.java @@ -803,8 +803,31 @@ public class SendTransactionFragment extends DialogFragment implements UIValidat df.setDecimalFormatSymbols(new DecimalFormatSymbols(Locale.ENGLISH)); etAmount.setText(df.format(amount)); Log.i("SendFragment", result.getText()); + return; }catch(Exception e){ e.printStackTrace(); } + + //Is not a bitshares QR + /*BitcoinUriParseRequest bitcoinUriParseRequest = new BitcoinUriParseRequest(result.getText()); + + bitcoinUriParseRequest.setListener(new CryptoNetInfoRequestListener() { + @Override + public void onCarryOut() { + if (bitcoinUriParseRequest.getAddress() != null) { + try { + crystalDialog.dismiss(); + thisFragment.dismiss(); + //thisFragment.finalize(); + } catch (Throwable throwable) { + throwable.printStackTrace(); + } + } else { + Toast.makeText(getContext(), "Not a valid QR info", Toast.LENGTH_LONG); + } + } + }); + + CryptoNetInfoRequests.getInstance().addRequest(bitcoinUriParseRequest);*/ } } \ No newline at end of file diff --git a/app/src/main/java/cy/agorise/crystalwallet/requestmanagers/BitcoinUriParseRequest.java b/app/src/main/java/cy/agorise/crystalwallet/requestmanagers/BitcoinUriParseRequest.java new file mode 100644 index 0000000..ad2a5b9 --- /dev/null +++ b/app/src/main/java/cy/agorise/crystalwallet/requestmanagers/BitcoinUriParseRequest.java @@ -0,0 +1,76 @@ +package cy.agorise.crystalwallet.requestmanagers; + +import android.content.Context; + +import cy.agorise.crystalwallet.enums.CryptoCoin; +import cy.agorise.crystalwallet.models.CryptoNetAccount; +import cy.agorise.crystalwallet.models.GrapheneAccount; + +/** + * Class used to make a bitcoin uri parse request. + * + * Created by henry on 11/13/2018. + */ + +public class BitcoinUriParseRequest extends CryptoNetInfoRequest { + /** + * The status code of this request + */ + public enum StatusCode{ + NOT_STARTED, + VALID, + NOT_VALID + } + + private String address; + private Double amount; + private String memo; + + private StatusCode status = StatusCode.NOT_STARTED; + + public BitcoinUriParseRequest(String uri) { + super(CryptoCoin.BITCOIN); + this.address = ""; + this.amount = -1.0; + this.memo = ""; + } + + public String getAddress() { + return address; + } + + public void setAddress(String address) { + this.address = address; + } + + public Double getAmount() { + return amount; + } + + public void setAmount(Double amount) { + this.amount = amount; + } + + public String getMemo() { + return memo; + } + + public void setMemo(String memo) { + this.memo = memo; + } + + public void validate(){ + if ((this.status != StatusCode.NOT_STARTED)){ + this._fireOnCarryOutEvent(); + } + } + + public void setStatus(StatusCode code){ + this.status = code; + this._fireOnCarryOutEvent(); + } + + public StatusCode getStatus() { + return status; + } +}