aboutsummaryrefslogtreecommitdiffstats
path: root/src/main/java/de/pixart
diff options
context:
space:
mode:
authorChristian Schneppe <christian@pix-art.de>2016-11-11 22:56:28 +0100
committerChristian Schneppe <christian@pix-art.de>2016-11-11 22:56:28 +0100
commit945cea7ce5d7102d35c255e2f09d27ac14fb1620 (patch)
treee31b780be8be5c0035bb6dc9e067885cb60c9491 /src/main/java/de/pixart
parentacf3c1f5685b22e6ba404760b09d08de8dea5dd8 (diff)
show button on "xmpp:" uris
Diffstat (limited to 'src/main/java/de/pixart')
-rw-r--r--src/main/java/de/pixart/messenger/entities/Message.java7
-rw-r--r--src/main/java/de/pixart/messenger/ui/adapter/MessageAdapter.java24
-rw-r--r--src/main/java/de/pixart/messenger/utils/UIHelper.java6
-rw-r--r--src/main/java/de/pixart/messenger/utils/XmppUri.java5
4 files changed, 42 insertions, 0 deletions
diff --git a/src/main/java/de/pixart/messenger/entities/Message.java b/src/main/java/de/pixart/messenger/entities/Message.java
index 7bd61c5b9..e3dc68ce9 100644
--- a/src/main/java/de/pixart/messenger/entities/Message.java
+++ b/src/main/java/de/pixart/messenger/entities/Message.java
@@ -13,6 +13,7 @@ import de.pixart.messenger.utils.CryptoHelper;
import de.pixart.messenger.utils.GeoHelper;
import de.pixart.messenger.utils.MimeUtils;
import de.pixart.messenger.utils.UIHelper;
+import de.pixart.messenger.utils.XmppUri;
import de.pixart.messenger.xmpp.jid.InvalidJidException;
import de.pixart.messenger.xmpp.jid.Jid;
@@ -492,6 +493,8 @@ public class Message extends AbstractEntity {
!this.getBody().startsWith(ME_COMMAND) &&
!this.bodyIsHeart() &&
!message.bodyIsHeart() &&
+ !this.bodyIsXmpp() &&
+ !message.bodyIsXmpp() &&
this.isTrusted() == message.isTrusted()
);
}
@@ -680,6 +683,10 @@ public class Message extends AbstractEntity {
return body != null && UIHelper.HEARTS.contains(body.trim());
}
+ public boolean bodyIsXmpp() {
+ return body != null && XmppUri.isXmppUri(body.trim());
+ }
+
public FileParams getFileParams() {
FileParams params = getLegacyFileParams();
if (params != null) {
diff --git a/src/main/java/de/pixart/messenger/ui/adapter/MessageAdapter.java b/src/main/java/de/pixart/messenger/ui/adapter/MessageAdapter.java
index 1914df278..3cfc4cfa7 100644
--- a/src/main/java/de/pixart/messenger/ui/adapter/MessageAdapter.java
+++ b/src/main/java/de/pixart/messenger/ui/adapter/MessageAdapter.java
@@ -313,6 +313,28 @@ public class MessageAdapter extends ArrayAdapter<Message> implements CopyTextVie
viewHolder.messageBody.setText(span);
}
+ private void displayXmppMessage(final ViewHolder viewHolder, final String body) {
+ String contact = body.toLowerCase();
+ contact = contact.split(":")[1];
+ contact = contact.split("\\?")[0];
+ String add_contact = activity.getString(R.string.add_to_contact_list) + " (" + contact + ")";
+ viewHolder.aw_player.setVisibility(View.GONE);
+ viewHolder.download_button.setVisibility(View.VISIBLE);
+ viewHolder.download_button.setText(add_contact);
+ viewHolder.download_button.setOnClickListener(new OnClickListener() {
+
+ @Override
+ public void onClick(View v) {
+ Intent intent = new Intent(Intent.ACTION_VIEW);
+ intent.setData(Uri.parse(body));
+ activity.startActivity(intent);
+ }
+ });
+ viewHolder.image.setVisibility(View.GONE);
+ viewHolder.messageBody.setVisibility(View.GONE);
+
+ }
+
private void displayTextMessage(final ViewHolder viewHolder, final Message message, boolean darkBackground) {
if (viewHolder.download_button != null) {
viewHolder.download_button.setVisibility(View.GONE);
@@ -740,6 +762,8 @@ public class MessageAdapter extends ArrayAdapter<Message> implements CopyTextVie
displayLocationMessage(viewHolder,message);
} else if (message.bodyIsHeart()) {
displayHeartMessage(viewHolder, message.getBody().trim());
+ } else if (message.bodyIsXmpp()) {
+ displayXmppMessage(viewHolder, message.getBody().trim());
} else if (message.treatAsDownloadable() == Message.Decision.MUST ||
message.treatAsDownloadable() == Message.Decision.SHOULD) {
try {
diff --git a/src/main/java/de/pixart/messenger/utils/UIHelper.java b/src/main/java/de/pixart/messenger/utils/UIHelper.java
index fbd41fa0a..100eff4ea 100644
--- a/src/main/java/de/pixart/messenger/utils/UIHelper.java
+++ b/src/main/java/de/pixart/messenger/utils/UIHelper.java
@@ -192,6 +192,12 @@ public class UIHelper {
} else {
return new Pair<>(context.getString(R.string.location), true);
}
+ } else if (message.bodyIsXmpp()) {
+ if (message.getStatus() == Message.STATUS_RECEIVED) {
+ return new Pair<>(context.getString(R.string.received_contact), true);
+ } else {
+ return new Pair<>(context.getString(R.string.contact), true);
+ }
} else if (message.treatAsDownloadable() == Message.Decision.MUST) {
return new Pair<>(context.getString(R.string.x_file_offered_for_download,
getFileDescriptionString(context,message)),true);
diff --git a/src/main/java/de/pixart/messenger/utils/XmppUri.java b/src/main/java/de/pixart/messenger/utils/XmppUri.java
index 07f85503e..832b4018f 100644
--- a/src/main/java/de/pixart/messenger/utils/XmppUri.java
+++ b/src/main/java/de/pixart/messenger/utils/XmppUri.java
@@ -31,6 +31,11 @@ public class XmppUri {
parse(uri);
}
+ public static boolean isXmppUri(String uri) {
+ String scheme = Uri.parse(uri).getScheme();
+ return "xmpp".equalsIgnoreCase(scheme);
+ }
+
protected void parse(Uri uri) {
String scheme = uri.getScheme();
String host = uri.getHost();