From 142a42c84c9ee1fecb1e38cf43e9064c27c667ba Mon Sep 17 00:00:00 2001 From: pokkst Date: Sat, 17 Sep 2022 18:47:23 -0500 Subject: [PATCH] Allow for domains in add node dialog --- .../java/net/mynero/wallet/data/Node.java | 53 ------------------- .../dialog/AddNodeBottomSheetDialog.java | 4 +- .../layout/add_node_bottom_sheet_dialog.xml | 2 +- 3 files changed, 3 insertions(+), 56 deletions(-) diff --git a/app/src/main/java/net/mynero/wallet/data/Node.java b/app/src/main/java/net/mynero/wallet/data/Node.java index 9564dbb..d4d0b96 100644 --- a/app/src/main/java/net/mynero/wallet/data/Node.java +++ b/app/src/main/java/net/mynero/wallet/data/Node.java @@ -21,7 +21,6 @@ import net.mynero.wallet.model.WalletManager; import net.mynero.wallet.util.OnionHelper; import java.io.UnsupportedEncodingException; -import java.net.InetAddress; import java.net.InetSocketAddress; import java.net.URLDecoder; import java.net.URLEncoder; @@ -286,56 +285,4 @@ public class Node { password = anotherNode.password; favourite = anotherNode.favourite; } - - static class Address { - final private InetAddress inet; - final private String onion; - - private Address(InetAddress address, String onion) { - this.inet = address; - this.onion = onion; - } - - static Address of(InetAddress address) { - return new Address(address, null); - } - - static Address of(String host) throws UnknownHostException { - if (OnionHelper.isOnionHost(host)) { - return new Address(null, host); - } else { - return new Address(InetAddress.getByName(host), null); - } - } - - public boolean isOnion() { - return onion != null; - } - - public String getHostName() { - if (inet != null) { - return inet.getHostName(); - } else { - return onion; - } - } - - public String getHostAddress() { - if (inet != null) { - return inet.getHostAddress(); - } else { - return onion; - } - } - - @Override - public int hashCode() { - return getHostAddress().hashCode(); - } - - @Override - public boolean equals(Object other) { - return (other instanceof Address) && (getHostAddress().equals(((Address) other).getHostAddress())); - } - } } diff --git a/app/src/main/java/net/mynero/wallet/fragment/dialog/AddNodeBottomSheetDialog.java b/app/src/main/java/net/mynero/wallet/fragment/dialog/AddNodeBottomSheetDialog.java index e874101..a132d10 100644 --- a/app/src/main/java/net/mynero/wallet/fragment/dialog/AddNodeBottomSheetDialog.java +++ b/app/src/main/java/net/mynero/wallet/fragment/dialog/AddNodeBottomSheetDialog.java @@ -53,8 +53,8 @@ public class AddNodeBottomSheetDialog extends BottomSheetDialogFragment { String address = nodeParts[0]; int port = Integer.parseInt(nodeParts[1]); String newNodeString = address + ":" + port + "/mainnet/" + name; - boolean validIp = Patterns.IP_ADDRESS.matcher(address).matches(); - if(validIp) { + boolean validAddress = Patterns.IP_ADDRESS.matcher(address).matches() || Patterns.DOMAIN_NAME.matcher(address).matches(); + if(validAddress) { String nodesArray = PrefService.getInstance().getString(Constants.PREF_CUSTOM_NODES, "[]"); JSONArray jsonArray = new JSONArray(nodesArray); boolean exists = false; diff --git a/app/src/main/res/layout/add_node_bottom_sheet_dialog.xml b/app/src/main/res/layout/add_node_bottom_sheet_dialog.xml index 5d83a3b..5078055 100644 --- a/app/src/main/res/layout/add_node_bottom_sheet_dialog.xml +++ b/app/src/main/res/layout/add_node_bottom_sheet_dialog.xml @@ -65,7 +65,7 @@ android:background="@drawable/edittext_bg" android:hint="@string/node_address_hint" android:inputType="text" - android:digits="1234567890.:" + android:digits="-QWERTYUIOPASDFGHJKLZXCVBNMqwertyuiopasdfghjklzxcvbnm1234567890.:" app:layout_constraintBottom_toTopOf="@id/add_node_button" app:layout_constraintEnd_toStartOf="@id/paste_address_imagebutton" app:layout_constraintStart_toStartOf="parent" />