If whole mesage is a known URI with an icon, make button
(cherry picked from commit ae157db4d9455610b3c9f4f8d809e8cba48e498a)
This commit is contained in:
parent
a7bbfeee75
commit
21a8ffd7d9
2 changed files with 41 additions and 1 deletions
|
@ -4,6 +4,7 @@ import android.content.ContentValues;
|
||||||
import android.database.Cursor;
|
import android.database.Cursor;
|
||||||
import android.graphics.drawable.Drawable;
|
import android.graphics.drawable.Drawable;
|
||||||
import android.graphics.Color;
|
import android.graphics.Color;
|
||||||
|
import android.net.Uri;
|
||||||
import android.os.Build;
|
import android.os.Build;
|
||||||
import android.text.Html;
|
import android.text.Html;
|
||||||
import android.text.Spannable;
|
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.CryptoHelper;
|
||||||
import eu.siacs.conversations.utils.Emoticons;
|
import eu.siacs.conversations.utils.Emoticons;
|
||||||
import eu.siacs.conversations.utils.GeoHelper;
|
import eu.siacs.conversations.utils.GeoHelper;
|
||||||
|
import eu.siacs.conversations.utils.Patterns;
|
||||||
import eu.siacs.conversations.utils.MessageUtils;
|
import eu.siacs.conversations.utils.MessageUtils;
|
||||||
import eu.siacs.conversations.utils.MimeUtils;
|
import eu.siacs.conversations.utils.MimeUtils;
|
||||||
import eu.siacs.conversations.utils.StringUtils;
|
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 Collection<Reaction> reactions = Collections.emptyList();
|
||||||
|
|
||||||
private Boolean isGeoUri = null;
|
private Boolean isGeoUri = null;
|
||||||
|
private Uri wholeIsKnownURI = null;
|
||||||
private Boolean isEmojisOnly = null;
|
private Boolean isEmojisOnly = null;
|
||||||
private Boolean treatAsDownloadable = null;
|
private Boolean treatAsDownloadable = null;
|
||||||
private FileParams fileParams = null;
|
private FileParams fileParams = null;
|
||||||
|
@ -636,6 +639,7 @@ public class Message extends AbstractEntity implements AvatarService.Avatarable
|
||||||
private synchronized void setBodyPreserveXHTML(String body) {
|
private synchronized void setBodyPreserveXHTML(String body) {
|
||||||
this.body = body;
|
this.body = body;
|
||||||
this.isGeoUri = null;
|
this.isGeoUri = null;
|
||||||
|
this.wholeIsKnownURI = null;
|
||||||
this.isEmojisOnly = null;
|
this.isEmojisOnly = null;
|
||||||
this.treatAsDownloadable = null;
|
this.treatAsDownloadable = null;
|
||||||
}
|
}
|
||||||
|
@ -656,6 +660,7 @@ public class Message extends AbstractEntity implements AvatarService.Avatarable
|
||||||
public synchronized void appendBody(String append) {
|
public synchronized void appendBody(String append) {
|
||||||
this.body += append;
|
this.body += append;
|
||||||
this.isGeoUri = null;
|
this.isGeoUri = null;
|
||||||
|
this.wholeIsKnownURI = null;
|
||||||
this.isEmojisOnly = null;
|
this.isEmojisOnly = null;
|
||||||
this.treatAsDownloadable = null;
|
this.treatAsDownloadable = null;
|
||||||
}
|
}
|
||||||
|
@ -1444,6 +1449,16 @@ public class Message extends AbstractEntity implements AvatarService.Avatarable
|
||||||
return isGeoUri;
|
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() {
|
protected List<Element> getSims() {
|
||||||
return payloads.stream().filter(el ->
|
return payloads.stream().filter(el ->
|
||||||
el.getName().equals("reference") && el.getNamespace().equals("urn:xmpp:reference:0") &&
|
el.getName().equals("reference") && el.getNamespace().equals("urn:xmpp:reference:0") &&
|
||||||
|
|
|
@ -935,6 +935,29 @@ public class MessageAdapter extends ArrayAdapter<Message> {
|
||||||
viewHolder.download_button.setOnClickListener(v -> openDownloadable(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(
|
private void displayLocationMessage(
|
||||||
ViewHolder viewHolder, final Message message, final BubbleColor bubbleColor, final int type) {
|
ViewHolder viewHolder, final Message message, final BubbleColor bubbleColor, final int type) {
|
||||||
displayTextMessage(viewHolder, message, bubbleColor, type);
|
displayTextMessage(viewHolder, message, bubbleColor, type);
|
||||||
|
@ -1537,7 +1560,9 @@ public class MessageAdapter extends ArrayAdapter<Message> {
|
||||||
displayInfoMessage(
|
displayInfoMessage(
|
||||||
viewHolder, activity.getString(R.string.omemo_decryption_failed), bubbleColor);
|
viewHolder, activity.getString(R.string.omemo_decryption_failed), bubbleColor);
|
||||||
} else {
|
} else {
|
||||||
if (message.isGeoUri()) {
|
if (message.wholeIsKnownURI() != null) {
|
||||||
|
displayURIMessage(viewHolder, message, bubbleColor, type);
|
||||||
|
} else if (message.isGeoUri()) {
|
||||||
displayLocationMessage(viewHolder, message, bubbleColor, type);
|
displayLocationMessage(viewHolder, message, bubbleColor, type);
|
||||||
} else if (message.treatAsDownloadable()) {
|
} else if (message.treatAsDownloadable()) {
|
||||||
try {
|
try {
|
||||||
|
|
Loading…
Add table
Reference in a new issue