- Added a bitcoin parse request to read bitcoin alike URIs
- Now the receive fragment generates bitcoin alike URIs - Added commented code to read QR code URIs in the send fragment
This commit is contained in:
parent
719d6769fc
commit
193f426739
3 changed files with 191 additions and 35 deletions
|
@ -29,6 +29,7 @@ import android.widget.EditText;
|
||||||
import android.widget.ImageView;
|
import android.widget.ImageView;
|
||||||
import android.widget.Spinner;
|
import android.widget.Spinner;
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
|
import android.widget.Toast;
|
||||||
|
|
||||||
import com.google.zxing.BarcodeFormat;
|
import com.google.zxing.BarcodeFormat;
|
||||||
import com.google.zxing.MultiFormatWriter;
|
import com.google.zxing.MultiFormatWriter;
|
||||||
|
@ -38,6 +39,10 @@ import com.google.zxing.common.BitMatrix;
|
||||||
import butterknife.OnClick;
|
import butterknife.OnClick;
|
||||||
import cy.agorise.crystalwallet.enums.CryptoCoin;
|
import cy.agorise.crystalwallet.enums.CryptoCoin;
|
||||||
import cy.agorise.crystalwallet.enums.CryptoNet;
|
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.util.CircularImageView;
|
||||||
import cy.agorise.crystalwallet.viewmodels.CryptoNetAccountListViewModel;
|
import cy.agorise.crystalwallet.viewmodels.CryptoNetAccountListViewModel;
|
||||||
import cy.agorise.crystalwallet.views.CryptoNetAccountAdapter;
|
import cy.agorise.crystalwallet.views.CryptoNetAccountAdapter;
|
||||||
|
@ -341,6 +346,7 @@ public class ReceiveTransactionFragment extends DialogFragment implements UIVali
|
||||||
|
|
||||||
CryptoNetAccount toAccountSelected = (CryptoNetAccount) spTo.getSelectedItem();
|
CryptoNetAccount toAccountSelected = (CryptoNetAccount) spTo.getSelectedItem();
|
||||||
|
|
||||||
|
if (this.cryptoNetAccount.getCryptoNet() == CryptoNet.BITSHARES) {
|
||||||
/*
|
/*
|
||||||
* this is only for graphene accounts.
|
* this is only for graphene accounts.
|
||||||
*
|
*
|
||||||
|
@ -387,6 +393,57 @@ public class ReceiveTransactionFragment extends DialogFragment implements UIVali
|
||||||
};
|
};
|
||||||
|
|
||||||
this.qrCodeTask.execute(null, null, 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 onCarryOut(){
|
||||||
|
if (uriRequest.getUri() != null){
|
||||||
|
qrCodeTask = new AsyncTask<Object, Void, Void>() {
|
||||||
|
|
||||||
|
@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");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
CryptoNetInfoRequests.getInstance().addRequest(uriRequest);
|
||||||
|
// } else {
|
||||||
|
// Toast.makeText(getContext(),"Error creating address",Toast.LENGTH_SHORT);
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
//});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Bitmap textToImageEncode(String Value) throws WriterException {
|
Bitmap textToImageEncode(String Value) throws WriterException {
|
||||||
|
|
|
@ -803,8 +803,31 @@ public class SendTransactionFragment extends DialogFragment implements UIValidat
|
||||||
df.setDecimalFormatSymbols(new DecimalFormatSymbols(Locale.ENGLISH));
|
df.setDecimalFormatSymbols(new DecimalFormatSymbols(Locale.ENGLISH));
|
||||||
etAmount.setText(df.format(amount));
|
etAmount.setText(df.format(amount));
|
||||||
Log.i("SendFragment", result.getText());
|
Log.i("SendFragment", result.getText());
|
||||||
|
return;
|
||||||
}catch(Exception e){
|
}catch(Exception e){
|
||||||
e.printStackTrace();
|
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);*/
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -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;
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue