From 997f9224011e7979e3873be61305820950f7f8e2 Mon Sep 17 00:00:00 2001 From: Daniel Gultsch Date: Tue, 28 May 2019 22:32:42 +0200 Subject: [PATCH] put geo uri in attachment preview when shared --- .../conversations/ui/ConversationFragment.java | 14 +++++++++++--- .../siacs/conversations/ui/ShareWithActivity.java | 7 ++++++- .../eu/siacs/conversations/utils/GeoHelper.java | 4 +--- 3 files changed, 18 insertions(+), 7 deletions(-) diff --git a/src/main/java/eu/siacs/conversations/ui/ConversationFragment.java b/src/main/java/eu/siacs/conversations/ui/ConversationFragment.java index feefbd105..7a25a9d4d 100644 --- a/src/main/java/eu/siacs/conversations/ui/ConversationFragment.java +++ b/src/main/java/eu/siacs/conversations/ui/ConversationFragment.java @@ -1994,8 +1994,12 @@ public class ConversationFragment extends XmppFragment implements EditMessage.Ke final boolean doNotAppend = extras.getBoolean(ConversationsActivity.EXTRA_DO_NOT_APPEND, false); final List uris = extractUris(extras); if (uris != null && uris.size() > 0) { - final List cleanedUris = cleanUris(new ArrayList<>(uris)); - mediaPreviewAdapter.addMediaPreviews(Attachment.of(getActivity(), cleanedUris)); + if (uris.size() == 1 && "geo".equals(uris.get(0).getScheme())) { + mediaPreviewAdapter.addMediaPreviews(Attachment.of(getActivity(), uris.get(0), Attachment.Type.LOCATION)); + } else { + final List cleanedUris = cleanUris(new ArrayList<>(uris)); + mediaPreviewAdapter.addMediaPreviews(Attachment.of(getActivity(), cleanedUris)); + } toggleInputMethod(); return; } @@ -2015,7 +2019,11 @@ public class ConversationFragment extends XmppFragment implements EditMessage.Ke } } } else { - if (text != null && asQuote) { + if (text != null && GeoHelper.GEO_URI.matcher(text).matches()) { + mediaPreviewAdapter.addMediaPreviews(Attachment.of(getActivity(), Uri.parse(text), Attachment.Type.LOCATION)); + toggleInputMethod(); + return; + } else if (text != null && asQuote) { quoteText(text); } else { appendText(text, doNotAppend); diff --git a/src/main/java/eu/siacs/conversations/ui/ShareWithActivity.java b/src/main/java/eu/siacs/conversations/ui/ShareWithActivity.java index 40ac1599c..9d6385db8 100644 --- a/src/main/java/eu/siacs/conversations/ui/ShareWithActivity.java +++ b/src/main/java/eu/siacs/conversations/ui/ShareWithActivity.java @@ -21,6 +21,7 @@ import eu.siacs.conversations.entities.Conversation; import eu.siacs.conversations.services.XmppConnectionService; import eu.siacs.conversations.ui.adapter.ConversationAdapter; import eu.siacs.conversations.ui.service.EmojiService; +import eu.siacs.conversations.utils.GeoHelper; import rocks.xmpp.addr.Jid; public class ShareWithActivity extends XmppActivity implements XmppConnectionService.OnConversationUpdate { @@ -126,10 +127,14 @@ public class ShareWithActivity extends XmppActivity implements XmppConnectionSer } final String type = intent.getType(); final String action = intent.getAction(); + final Uri data = intent.getData(); if (Intent.ACTION_SEND.equals(action)) { final String text = intent.getStringExtra(Intent.EXTRA_TEXT); final Uri uri = intent.getParcelableExtra(Intent.EXTRA_STREAM); - if (type != null && uri != null && (text == null || !type.equals("text/plain"))) { + if (data != null && "geo".equals(data.getScheme())) { + this.share.uris.clear(); + this.share.uris.add(data); + } else if (type != null && uri != null && (text == null || !type.equals("text/plain"))) { this.share.uris.clear(); this.share.uris.add(uri); } else { diff --git a/src/main/java/eu/siacs/conversations/utils/GeoHelper.java b/src/main/java/eu/siacs/conversations/utils/GeoHelper.java index e71b1bfa6..79600075a 100644 --- a/src/main/java/eu/siacs/conversations/utils/GeoHelper.java +++ b/src/main/java/eu/siacs/conversations/utils/GeoHelper.java @@ -1,6 +1,5 @@ package eu.siacs.conversations.utils; -import android.app.Activity; import android.content.Context; import android.content.Intent; import android.content.SharedPreferences; @@ -17,7 +16,6 @@ import java.util.regex.Pattern; import eu.siacs.conversations.R; import eu.siacs.conversations.entities.Contact; -import eu.siacs.conversations.entities.Conversation; import eu.siacs.conversations.entities.Conversational; import eu.siacs.conversations.entities.Message; import eu.siacs.conversations.ui.ShareLocationActivity; @@ -28,7 +26,7 @@ public class GeoHelper { private static final String SHARE_LOCATION_PACKAGE_NAME = "eu.siacs.conversations.location.request"; private static final String SHOW_LOCATION_PACKAGE_NAME = "eu.siacs.conversations.location.show"; - public static Pattern GEO_URI = Pattern.compile("geo:(-?\\d+(?:\\.\\d+)?),(-?\\d+(?:\\.\\d+)?)(?:,-?\\d+(?:\\.\\d+)?)?(?:;crs=[\\w-]+)?(?:;u=\\d+(?:\\.\\d+)?)?(?:;[\\w-]+=(?:[\\w-_.!~*'()]|%[\\da-f][\\da-f])+)*", Pattern.CASE_INSENSITIVE); + public static Pattern GEO_URI = Pattern.compile("geo:(-?\\d+(?:\\.\\d+)?),(-?\\d+(?:\\.\\d+)?)(?:,-?\\d+(?:\\.\\d+)?)?(?:;crs=[\\w-]+)?(?:;u=\\d+(?:\\.\\d+)?)?(?:;[\\w-]+=(?:[\\w-_.!~*'()]|%[\\da-f][\\da-f])+)*(\\?z=\\d+)?", Pattern.CASE_INSENSITIVE); public static boolean isLocationPluginInstalled(Context context) { return new Intent(SHARE_LOCATION_PACKAGE_NAME).resolveActivity(context.getPackageManager()) != null;