add context menu entries for geo uris

This commit is contained in:
iNPUTmice 2015-03-11 15:48:43 +01:00
parent db6a63bcf6
commit 4ee4eeb5e7

View File

@ -8,6 +8,7 @@ import android.content.DialogInterface;
import android.content.Intent; import android.content.Intent;
import android.content.IntentSender; import android.content.IntentSender;
import android.content.IntentSender.SendIntentException; import android.content.IntentSender.SendIntentException;
import android.net.Uri;
import android.os.Bundle; import android.os.Bundle;
import android.text.InputType; import android.text.InputType;
import android.view.ContextMenu; import android.view.ContextMenu;
@ -58,6 +59,7 @@ import eu.siacs.conversations.ui.XmppActivity.OnValueEdited;
import eu.siacs.conversations.ui.adapter.MessageAdapter; import eu.siacs.conversations.ui.adapter.MessageAdapter;
import eu.siacs.conversations.ui.adapter.MessageAdapter.OnContactPictureClicked; import eu.siacs.conversations.ui.adapter.MessageAdapter.OnContactPictureClicked;
import eu.siacs.conversations.ui.adapter.MessageAdapter.OnContactPictureLongClicked; import eu.siacs.conversations.ui.adapter.MessageAdapter.OnContactPictureLongClicked;
import eu.siacs.conversations.utils.GeoHelper;
import eu.siacs.conversations.xmpp.chatstate.ChatState; import eu.siacs.conversations.xmpp.chatstate.ChatState;
import eu.siacs.conversations.xmpp.jid.Jid; import eu.siacs.conversations.xmpp.jid.Jid;
@ -410,19 +412,20 @@ public class ConversationFragment extends Fragment implements EditMessage.Keyboa
MenuItem downloadImage = menu.findItem(R.id.download_image); MenuItem downloadImage = menu.findItem(R.id.download_image);
MenuItem cancelTransmission = menu.findItem(R.id.cancel_transmission); MenuItem cancelTransmission = menu.findItem(R.id.cancel_transmission);
if ((m.getType() != Message.TYPE_TEXT && m.getType() != Message.TYPE_PRIVATE) if ((m.getType() != Message.TYPE_TEXT && m.getType() != Message.TYPE_PRIVATE)
|| m.getDownloadable() != null) { || m.getDownloadable() != null || GeoHelper.isGeoUri(m.getBody())) {
copyText.setVisible(false); copyText.setVisible(false);
} }
if (m.getType() == Message.TYPE_TEXT if ((m.getType() == Message.TYPE_TEXT
|| m.getType() == Message.TYPE_PRIVATE || m.getType() == Message.TYPE_PRIVATE
|| m.getDownloadable() != null) { || m.getDownloadable() != null)
&& (!GeoHelper.isGeoUri(m.getBody()))) {
shareWith.setVisible(false); shareWith.setVisible(false);
} }
if (m.getStatus() != Message.STATUS_SEND_FAILED) { if (m.getStatus() != Message.STATUS_SEND_FAILED) {
sendAgain.setVisible(false); sendAgain.setVisible(false);
} }
if ((m.getType() != Message.TYPE_IMAGE && m.getDownloadable() == null) if (((m.getType() != Message.TYPE_IMAGE && m.getDownloadable() == null)
|| m.getImageParams().url == null) { || m.getImageParams().url == null) && !GeoHelper.isGeoUri(m.getBody())) {
copyUrl.setVisible(false); copyUrl.setVisible(false);
} }
if (m.getType() != Message.TYPE_TEXT if (m.getType() != Message.TYPE_TEXT
@ -467,6 +470,10 @@ public class ConversationFragment extends Fragment implements EditMessage.Keyboa
private void shareWith(Message message) { private void shareWith(Message message) {
Intent shareIntent = new Intent(); Intent shareIntent = new Intent();
shareIntent.setAction(Intent.ACTION_SEND); shareIntent.setAction(Intent.ACTION_SEND);
if (GeoHelper.isGeoUri(message.getBody())) {
shareIntent.putExtra(Intent.EXTRA_TEXT, message.getBody());
shareIntent.setType("text/plain");
} else {
shareIntent.putExtra(Intent.EXTRA_STREAM, shareIntent.putExtra(Intent.EXTRA_STREAM,
activity.xmppConnectionService.getFileBackend() activity.xmppConnectionService.getFileBackend()
.getJingleFileUri(message)); .getJingleFileUri(message));
@ -477,6 +484,7 @@ public class ConversationFragment extends Fragment implements EditMessage.Keyboa
mime = "image/webp"; mime = "image/webp";
} }
shareIntent.setType(mime); shareIntent.setType(mime);
}
activity.startActivity(Intent.createChooser(shareIntent,getText(R.string.share_with))); activity.startActivity(Intent.createChooser(shareIntent,getText(R.string.share_with)));
} }
@ -501,8 +509,16 @@ public class ConversationFragment extends Fragment implements EditMessage.Keyboa
} }
private void copyUrl(Message message) { private void copyUrl(Message message) {
if (activity.copyTextToClipboard( final String url;
message.getImageParams().url.toString(), R.string.image_url)) { final int resId;
if (GeoHelper.isGeoUri(message.getBody())) {
resId = R.string.location;
url = message.getBody();
} else {
resId = R.string.image_url;
url = message.getImageParams().url.toString();
}
if (activity.copyTextToClipboard(url, resId)) {
Toast.makeText(activity, R.string.url_copied_to_clipboard, Toast.makeText(activity, R.string.url_copied_to_clipboard,
Toast.LENGTH_SHORT).show(); Toast.LENGTH_SHORT).show();
} }