From 7897b2d1caf6667d8a067a93b340244dade3e21d Mon Sep 17 00:00:00 2001 From: Stephen Paul Weber Date: Fri, 15 Nov 2024 06:02:03 +0100 Subject: [PATCH] Ethereum URI support (cherry picked from commit 60710234bcaabb95d5de265e65cba1b0b4292d8d) --- .../siacs/conversations/entities/Message.java | 2 +- .../ui/ContactDetailsActivity.java | 4 ++++ .../ui/adapter/MessageAdapter.java | 5 +++++ .../conversations/ui/util/MyLinkify.java | 1 + .../siacs/conversations/utils/Patterns.java | 9 ++++++++ src/monocleschat/res/drawable/eth_24dp.xml | 22 +++++++++++++++++++ 6 files changed, 42 insertions(+), 1 deletion(-) create mode 100644 src/monocleschat/res/drawable/eth_24dp.xml diff --git a/src/main/java/eu/siacs/conversations/entities/Message.java b/src/main/java/eu/siacs/conversations/entities/Message.java index 7cc99bf59..7f619b7bb 100644 --- a/src/main/java/eu/siacs/conversations/entities/Message.java +++ b/src/main/java/eu/siacs/conversations/entities/Message.java @@ -1452,7 +1452,7 @@ public class Message extends AbstractEntity implements AvatarService.Avatarable public synchronized Uri wholeIsKnownURI() { if (wholeIsKnownURI != null) return wholeIsKnownURI; - if (Patterns.BITCOIN_URI.matcher(body).matches() ||Patterns.BITCOINCASH_URI.matcher(body).matches() || Patterns.MONERO_URI.matcher(body).matches() || Patterns.WOWNERO_URI.matcher(body).matches()) { + if (Patterns.BITCOIN_URI.matcher(body).matches() ||Patterns.BITCOINCASH_URI.matcher(body).matches() || Patterns.ETHEREUM_URI.matcher(body).matches() || Patterns.MONERO_URI.matcher(body).matches() || Patterns.WOWNERO_URI.matcher(body).matches()) { wholeIsKnownURI = Uri.parse(body.replace(":", "://")); // hack to make query parser work } diff --git a/src/main/java/eu/siacs/conversations/ui/ContactDetailsActivity.java b/src/main/java/eu/siacs/conversations/ui/ContactDetailsActivity.java index 08497ae30..1f56f705e 100644 --- a/src/main/java/eu/siacs/conversations/ui/ContactDetailsActivity.java +++ b/src/main/java/eu/siacs/conversations/ui/ContactDetailsActivity.java @@ -858,6 +858,10 @@ public class ContactDetailsActivity extends OmemoActivity implements OnAccountUp binding.command.setText(uri.getSchemeSpecificPart()); binding.command.setCompoundDrawablesRelativeWithIntrinsicBounds(getDrawable(R.drawable.bitcoin_cash_24dp), null, null, null); binding.command.setCompoundDrawablePadding(20); + } else if (uri.getScheme().equals("ethereum")) { + binding.command.setText(uri.getSchemeSpecificPart()); + binding.command.setCompoundDrawablesRelativeWithIntrinsicBounds(getDrawable(R.drawable.eth_24dp), null, null, null); + binding.command.setCompoundDrawablePadding(20); } else if (uri.getScheme().equals("monero")) { binding.command.setText(uri.getSchemeSpecificPart()); binding.command.setCompoundDrawablesRelativeWithIntrinsicBounds(getDrawable(R.drawable.monero_24dp), null, null, null); diff --git a/src/main/java/eu/siacs/conversations/ui/adapter/MessageAdapter.java b/src/main/java/eu/siacs/conversations/ui/adapter/MessageAdapter.java index eb57fa798..b0fb71295 100644 --- a/src/main/java/eu/siacs/conversations/ui/adapter/MessageAdapter.java +++ b/src/main/java/eu/siacs/conversations/ui/adapter/MessageAdapter.java @@ -953,6 +953,11 @@ public class MessageAdapter extends ArrayAdapter { final var formattedAmount = amount == null || amount.equals("") ? "" : amount + " "; viewHolder.download_button.setIconResource(R.drawable.bitcoin_cash_24dp); viewHolder.download_button.setText("Send " + formattedAmount + "Bitcoin Cash"); + } else if ("ethereum".equals(uri.getScheme())) { + final var amount = uri.getQueryParameter("value"); + final var formattedAmount = amount == null || amount.equals("") ? "" : amount + " "; + viewHolder.download_button.setIconResource(R.drawable.eth_24dp); + viewHolder.download_button.setText("Send " + formattedAmount + "via Ethereum"); } else if ("monero".equals(uri.getScheme())) { final var amount = uri.getQueryParameter("tx_amount"); final var formattedAmount = amount == null || amount.equals("") ? "" : amount + " "; diff --git a/src/main/java/eu/siacs/conversations/ui/util/MyLinkify.java b/src/main/java/eu/siacs/conversations/ui/util/MyLinkify.java index 27868abe6..3acce8489 100644 --- a/src/main/java/eu/siacs/conversations/ui/util/MyLinkify.java +++ b/src/main/java/eu/siacs/conversations/ui/util/MyLinkify.java @@ -134,6 +134,7 @@ public class MyLinkify { Linkify.addLinks(body, Patterns.SMS_URI, "sms"); Linkify.addLinks(body, Patterns.BITCOIN_URI, "bitcoin"); Linkify.addLinks(body, Patterns.BITCOINCASH_URI, "bitcoincash"); + Linkify.addLinks(body, Patterns.ETHEREUM_URI, "ethereum"); Linkify.addLinks(body, Patterns.MONERO_URI, "monero"); Linkify.addLinks(body, Patterns.WOWNERO_URI, "wownero"); Linkify.addLinks(body, Patterns.AUTOLINK_WEB_URL, "http", WEBURL_MATCH_FILTER, WEBURL_TRANSFORM_FILTER); diff --git a/src/main/java/eu/siacs/conversations/utils/Patterns.java b/src/main/java/eu/siacs/conversations/utils/Patterns.java index ad6f34c17..9b4695b64 100644 --- a/src/main/java/eu/siacs/conversations/utils/Patterns.java +++ b/src/main/java/eu/siacs/conversations/utils/Patterns.java @@ -45,6 +45,15 @@ public class Patterns { + "\\;\\/\\?\\@\\&\\=\\#\\~\\-\\.\\+\\!\\*\\'\\(\\)\\,\\_])" + "|(?:\\%[a-fA-F0-9]{2}))+)?"); + public static final Pattern ETHEREUM_URI = Pattern + .compile("ethereum\\:(?:pay\\-)?(0x[0-9a-f]{40})(?:@[0-9]+)?(?:/(?:(?:[" + + Patterns.GOOD_IRI_CHAR + + "\\;\\/\\?\\@\\&\\=\\#\\~\\-\\.\\+\\!\\*\\'\\(\\)\\,\\_])" + + "|(?:\\%[a-fA-F0-9]{2}))+)?(?:\\?(?:(?:[" + + Patterns.GOOD_IRI_CHAR + + "\\;\\/\\?\\@\\&\\=\\#\\~\\-\\.\\+\\!\\*\\'\\(\\)\\,\\_])" + + "|(?:\\%[a-fA-F0-9]{2}))+)?"); + public static final Pattern MONERO_URI = Pattern .compile("monero\\:(?:[48][0-9AB][1-9A-HJ-NP-Za-km-z]{93})(?:\\?(?:(?:[" + Patterns.GOOD_IRI_CHAR diff --git a/src/monocleschat/res/drawable/eth_24dp.xml b/src/monocleschat/res/drawable/eth_24dp.xml new file mode 100644 index 000000000..d9b622aa1 --- /dev/null +++ b/src/monocleschat/res/drawable/eth_24dp.xml @@ -0,0 +1,22 @@ + + + + + + + +