diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index e0ea990..fb29478 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -24,6 +24,14 @@ + + + + + + + + { Context ctx = getContext(); if (ctx != null) { @@ -236,27 +246,11 @@ public class SendBottomSheetDialog extends BottomSheetDialogFragment { } private void pasteAddress(String address) { - HashMap params = new HashMap<>(); - String[] uriParts = address.replace(Constants.URI_PREFIX, "").split("\\?"); - String finalAddress = uriParts[0]; - String queryParams = ""; - if(uriParts.length > 1) { - queryParams = uriParts[1]; - String[] queryParts = queryParams.split("&"); - for (String param : queryParts) { - String[] paramParts = param.split("="); - String variable = paramParts[0]; - String value = paramParts[1]; - params.put(variable, value); - } - } - boolean isValid = Wallet.isAddressValid(finalAddress); - if (isValid) { - addressEditText.setText(finalAddress); - if(!params.isEmpty()) { - if(params.containsKey(Constants.URI_ARG_AMOUNT)) { - amountEditText.setText(params.get(Constants.URI_ARG_AMOUNT)); - } + UriData uriData = UriData.parse(address); + if (uriData != null) { + addressEditText.setText(uriData.getAddress()); + if(uriData.hasAmount()) { + amountEditText.setText(uriData.getAmount()); } } else { Toast.makeText(getActivity(), getString(R.string.send_address_invalid), Toast.LENGTH_SHORT).show(); diff --git a/app/src/main/java/com/m2049r/xmrwallet/fragment/home/HomeFragment.java b/app/src/main/java/com/m2049r/xmrwallet/fragment/home/HomeFragment.java index 08f5a4a..cc322bb 100644 --- a/app/src/main/java/com/m2049r/xmrwallet/fragment/home/HomeFragment.java +++ b/app/src/main/java/com/m2049r/xmrwallet/fragment/home/HomeFragment.java @@ -1,5 +1,7 @@ package com.m2049r.xmrwallet.fragment.home; +import android.content.Intent; +import android.net.Uri; import android.os.Bundle; import android.view.LayoutInflater; import android.view.View; @@ -30,6 +32,7 @@ import com.m2049r.xmrwallet.model.WalletManager; import com.m2049r.xmrwallet.service.BalanceService; import com.m2049r.xmrwallet.service.BlockchainService; import com.m2049r.xmrwallet.service.HistoryService; +import com.m2049r.xmrwallet.util.UriData; import java.util.Collections; diff --git a/app/src/main/java/com/m2049r/xmrwallet/util/UriData.java b/app/src/main/java/com/m2049r/xmrwallet/util/UriData.java new file mode 100644 index 0000000..60fd2be --- /dev/null +++ b/app/src/main/java/com/m2049r/xmrwallet/util/UriData.java @@ -0,0 +1,54 @@ +package com.m2049r.xmrwallet.util; + +import com.m2049r.xmrwallet.model.Wallet; + +import java.util.HashMap; + +public class UriData { + private final String address; + private final HashMap params; + + public UriData(String address, HashMap params) { + this.address = address; + this.params = params; + } + + public HashMap getParams() { + return params; + } + + public String getAddress() { + return address; + } + + public String getAmount() { + return params.get(Constants.URI_ARG_AMOUNT); + } + + public boolean hasAmount() { + return params.containsKey(Constants.URI_ARG_AMOUNT); + } + + public static UriData parse(String uri) { + HashMap params = new HashMap<>(); + String[] uriParts = uri.replace(Constants.URI_PREFIX, "").split("\\?"); + String finalAddress = uriParts[0]; + String queryParams = ""; + if(uriParts.length > 1) { + queryParams = uriParts[1]; + String[] queryParts = queryParams.split("&"); + for (String param : queryParts) { + String[] paramParts = param.split("="); + String variable = paramParts[0]; + String value = paramParts[1]; + params.put(variable, value); + } + } + boolean valid = Wallet.isAddressValid(finalAddress); + if(valid) { + return new UriData(finalAddress, params); + } else { + return null; + } + } +}