1
0
Fork 1

If whole mesage is a known URI with an icon, make button

(cherry picked from commit ae157db4d9455610b3c9f4f8d809e8cba48e498a)
This commit is contained in:
Stephen Paul Weber 2024-11-09 22:25:01 +01:00 committed by Arne
parent a7bbfeee75
commit 21a8ffd7d9
2 changed files with 41 additions and 1 deletions

View file

@ -4,6 +4,7 @@ import android.content.ContentValues;
import android.database.Cursor;
import android.graphics.drawable.Drawable;
import android.graphics.Color;
import android.net.Uri;
import android.os.Build;
import android.text.Html;
import android.text.Spannable;
@ -63,6 +64,7 @@ import eu.siacs.conversations.ui.util.QuoteHelper;
import eu.siacs.conversations.utils.CryptoHelper;
import eu.siacs.conversations.utils.Emoticons;
import eu.siacs.conversations.utils.GeoHelper;
import eu.siacs.conversations.utils.Patterns;
import eu.siacs.conversations.utils.MessageUtils;
import eu.siacs.conversations.utils.MimeUtils;
import eu.siacs.conversations.utils.StringUtils;
@ -168,6 +170,7 @@ public class Message extends AbstractEntity implements AvatarService.Avatarable
private Collection<Reaction> reactions = Collections.emptyList();
private Boolean isGeoUri = null;
private Uri wholeIsKnownURI = null;
private Boolean isEmojisOnly = null;
private Boolean treatAsDownloadable = null;
private FileParams fileParams = null;
@ -636,6 +639,7 @@ public class Message extends AbstractEntity implements AvatarService.Avatarable
private synchronized void setBodyPreserveXHTML(String body) {
this.body = body;
this.isGeoUri = null;
this.wholeIsKnownURI = null;
this.isEmojisOnly = null;
this.treatAsDownloadable = null;
}
@ -656,6 +660,7 @@ public class Message extends AbstractEntity implements AvatarService.Avatarable
public synchronized void appendBody(String append) {
this.body += append;
this.isGeoUri = null;
this.wholeIsKnownURI = null;
this.isEmojisOnly = null;
this.treatAsDownloadable = null;
}
@ -1444,6 +1449,16 @@ public class Message extends AbstractEntity implements AvatarService.Avatarable
return isGeoUri;
}
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()) {
wholeIsKnownURI = Uri.parse(body.replace(":", "://")); // hack to make query parser work
}
return wholeIsKnownURI;
}
protected List<Element> getSims() {
return payloads.stream().filter(el ->
el.getName().equals("reference") && el.getNamespace().equals("urn:xmpp:reference:0") &&

View file

@ -935,6 +935,29 @@ public class MessageAdapter extends ArrayAdapter<Message> {
viewHolder.download_button.setOnClickListener(v -> openDownloadable(message));
}
private void displayURIMessage(
ViewHolder viewHolder, final Message message, final BubbleColor bubbleColor, final int type) {
displayTextMessage(viewHolder, message, bubbleColor, type);
viewHolder.messageBody.setVisibility(View.GONE);
viewHolder.image.setVisibility(View.GONE);
viewHolder.audioPlayer.setVisibility(View.GONE);
viewHolder.download_button.setVisibility(View.VISIBLE);
final var uri = message.wholeIsKnownURI();
final var amount = uri.getQueryParameter("amount");
final var formattedAmount = amount == null || amount.equals("") ? "" : amount + " ";
if ("bitcoin".equals(uri.getScheme())) {
viewHolder.download_button.setIconResource(R.drawable.bitcoin_24dp);
viewHolder.download_button.setText("Send " + formattedAmount + "Bitcoin");
} else if ("bitcoincash".equals(uri.getScheme())) {
viewHolder.download_button.setIconResource(R.drawable.bitcoin_cash_24dp);
viewHolder.download_button.setText("Send " + formattedAmount + "Bitcoin Cash");
} else if ("monero".equals(uri.getScheme())) {
viewHolder.download_button.setIconResource(R.drawable.monero_24dp);
viewHolder.download_button.setText("Send " + formattedAmount + "Monero");
}
viewHolder.download_button.setOnClickListener(v -> new FixedURLSpan(message.getRawBody()).onClick(v));
}
private void displayLocationMessage(
ViewHolder viewHolder, final Message message, final BubbleColor bubbleColor, final int type) {
displayTextMessage(viewHolder, message, bubbleColor, type);
@ -1537,7 +1560,9 @@ public class MessageAdapter extends ArrayAdapter<Message> {
displayInfoMessage(
viewHolder, activity.getString(R.string.omemo_decryption_failed), bubbleColor);
} else {
if (message.isGeoUri()) {
if (message.wholeIsKnownURI() != null) {
displayURIMessage(viewHolder, message, bubbleColor, type);
} else if (message.isGeoUri()) {
displayLocationMessage(viewHolder, message, bubbleColor, type);
} else if (message.treatAsDownloadable()) {
try {