put geo uri in attachment preview when shared

This commit is contained in:
Daniel Gultsch 2019-05-28 22:32:42 +02:00
parent b7781f1e0e
commit 997f922401
3 changed files with 18 additions and 7 deletions

View file

@ -1994,8 +1994,12 @@ public class ConversationFragment extends XmppFragment implements EditMessage.Ke
final boolean doNotAppend = extras.getBoolean(ConversationsActivity.EXTRA_DO_NOT_APPEND, false); final boolean doNotAppend = extras.getBoolean(ConversationsActivity.EXTRA_DO_NOT_APPEND, false);
final List<Uri> uris = extractUris(extras); final List<Uri> uris = extractUris(extras);
if (uris != null && uris.size() > 0) { if (uris != null && uris.size() > 0) {
if (uris.size() == 1 && "geo".equals(uris.get(0).getScheme())) {
mediaPreviewAdapter.addMediaPreviews(Attachment.of(getActivity(), uris.get(0), Attachment.Type.LOCATION));
} else {
final List<Uri> cleanedUris = cleanUris(new ArrayList<>(uris)); final List<Uri> cleanedUris = cleanUris(new ArrayList<>(uris));
mediaPreviewAdapter.addMediaPreviews(Attachment.of(getActivity(), cleanedUris)); mediaPreviewAdapter.addMediaPreviews(Attachment.of(getActivity(), cleanedUris));
}
toggleInputMethod(); toggleInputMethod();
return; return;
} }
@ -2015,7 +2019,11 @@ public class ConversationFragment extends XmppFragment implements EditMessage.Ke
} }
} }
} else { } 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); quoteText(text);
} else { } else {
appendText(text, doNotAppend); appendText(text, doNotAppend);

View file

@ -21,6 +21,7 @@ import eu.siacs.conversations.entities.Conversation;
import eu.siacs.conversations.services.XmppConnectionService; import eu.siacs.conversations.services.XmppConnectionService;
import eu.siacs.conversations.ui.adapter.ConversationAdapter; import eu.siacs.conversations.ui.adapter.ConversationAdapter;
import eu.siacs.conversations.ui.service.EmojiService; import eu.siacs.conversations.ui.service.EmojiService;
import eu.siacs.conversations.utils.GeoHelper;
import rocks.xmpp.addr.Jid; import rocks.xmpp.addr.Jid;
public class ShareWithActivity extends XmppActivity implements XmppConnectionService.OnConversationUpdate { 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 type = intent.getType();
final String action = intent.getAction(); final String action = intent.getAction();
final Uri data = intent.getData();
if (Intent.ACTION_SEND.equals(action)) { if (Intent.ACTION_SEND.equals(action)) {
final String text = intent.getStringExtra(Intent.EXTRA_TEXT); final String text = intent.getStringExtra(Intent.EXTRA_TEXT);
final Uri uri = intent.getParcelableExtra(Intent.EXTRA_STREAM); 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.clear();
this.share.uris.add(uri); this.share.uris.add(uri);
} else { } else {

View file

@ -1,6 +1,5 @@
package eu.siacs.conversations.utils; package eu.siacs.conversations.utils;
import android.app.Activity;
import android.content.Context; import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.content.SharedPreferences; import android.content.SharedPreferences;
@ -17,7 +16,6 @@ import java.util.regex.Pattern;
import eu.siacs.conversations.R; import eu.siacs.conversations.R;
import eu.siacs.conversations.entities.Contact; import eu.siacs.conversations.entities.Contact;
import eu.siacs.conversations.entities.Conversation;
import eu.siacs.conversations.entities.Conversational; import eu.siacs.conversations.entities.Conversational;
import eu.siacs.conversations.entities.Message; import eu.siacs.conversations.entities.Message;
import eu.siacs.conversations.ui.ShareLocationActivity; 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 SHARE_LOCATION_PACKAGE_NAME = "eu.siacs.conversations.location.request";
private static final String SHOW_LOCATION_PACKAGE_NAME = "eu.siacs.conversations.location.show"; 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) { public static boolean isLocationPluginInstalled(Context context) {
return new Intent(SHARE_LOCATION_PACKAGE_NAME).resolveActivity(context.getPackageManager()) != null; return new Intent(SHARE_LOCATION_PACKAGE_NAME).resolveActivity(context.getPackageManager()) != null;