fix location view

This commit is contained in:
Christian Schneppe 2017-12-23 21:44:41 +01:00
parent bbd9150b88
commit 11a4291585
4 changed files with 7 additions and 14 deletions

View file

@ -563,7 +563,7 @@ public class NotificationService {
}
private PendingIntent createShowLocationIntent(final Message message) {
Iterable<Intent> intents = GeoHelper.createGeoIntentsFromMessage(message);
Iterable<Intent> intents = GeoHelper.createGeoIntentsFromMessage(message, this.mXmppConnectionService.getApplicationContext());
for (Intent intent : intents) {
if (intent.resolveActivity(mXmppConnectionService.getPackageManager()) != null) {
return PendingIntent.getActivity(mXmppConnectionService, 18, intent, PendingIntent.FLAG_UPDATE_CURRENT);

View file

@ -976,12 +976,6 @@ public class ConversationActivity extends XmppActivity
}
PopupMenu attachFilePopup = new PopupMenu(this, menuAttachFile);
attachFilePopup.inflate(R.menu.attachment_choices);
if (new Intent(MediaStore.Audio.Media.RECORD_SOUND_ACTION).resolveActivity(getPackageManager()) == null) {
attachFilePopup.getMenu().findItem(R.id.attach_record_voice).setVisible(false);
}
if (new Intent("de.pixart.messenger.location.request").resolveActivity(getPackageManager()) == null) {
attachFilePopup.getMenu().findItem(R.id.attach_location).setVisible(false);
}
attachFilePopup.setOnMenuItemClickListener(new OnMenuItemClickListener() {
@Override

View file

@ -1140,7 +1140,7 @@ public class MessageAdapter extends ArrayAdapter<Message> implements CopyTextVie
}
public void showLocation(Message message) {
for (Intent intent : GeoHelper.createGeoIntentsFromMessage(message)) {
for (Intent intent : GeoHelper.createGeoIntentsFromMessage(message, this.getContext())) {
if (intent.resolveActivity(getContext().getPackageManager()) != null) {
getContext().startActivity(intent);
return;

View file

@ -1,5 +1,6 @@
package de.pixart.messenger.utils;
import android.content.Context;
import android.content.Intent;
import android.net.Uri;
@ -13,8 +14,10 @@ import de.pixart.messenger.Config;
import de.pixart.messenger.entities.Contact;
import de.pixart.messenger.entities.Conversation;
import de.pixart.messenger.entities.Message;
import de.pixart.messenger.ui.ShowLocationActivity;
public class GeoHelper {
public static Pattern GEO_URI = Pattern.compile("geo:([\\-0-9.]+),([\\-0-9.]+)(?:,([\\-0-9.]+))?(?:\\?(.*))?", Pattern.CASE_INSENSITIVE);
public static String MapPreviewUri(Message message) {
@ -39,7 +42,7 @@ public class GeoHelper {
return "https://xmpp.pix-art.de/staticmap/staticmap.php?center=" + latitude + "," + longitude + "&size=500x500&markers=" + latitude + "," + longitude + "&zoom= " + Config.DEFAULT_ZOOM;
}
public static ArrayList<Intent> createGeoIntentsFromMessage(Message message) {
public static ArrayList<Intent> createGeoIntentsFromMessage(Message message, Context context) {
final ArrayList<Intent> intents = new ArrayList<>();
Matcher matcher = GEO_URI.matcher(message.getBody());
if (!matcher.matches()) {
@ -71,7 +74,7 @@ public class GeoHelper {
label = "";
}
Intent locationPluginIntent = new Intent("de.pixart.messenger.location.show");
Intent locationPluginIntent = new Intent(context, ShowLocationActivity.class);
locationPluginIntent.putExtra("latitude", latitude);
locationPluginIntent.putExtra("longitude", longitude);
if (message.getStatus() != Message.STATUS_RECEIVED) {
@ -91,10 +94,6 @@ public class GeoHelper {
Intent geoIntent = new Intent(Intent.ACTION_VIEW);
geoIntent.setData(Uri.parse("geo:" + String.valueOf(latitude) + "," + String.valueOf(longitude) + "?q=" + String.valueOf(latitude) + "," + String.valueOf(longitude) + label));
intents.add(geoIntent);
Intent httpIntent = new Intent(Intent.ACTION_VIEW);
httpIntent.setData(Uri.parse("https://maps.google.com/maps?q=loc:" + String.valueOf(latitude) + "," + String.valueOf(longitude) + label));
intents.add(httpIntent);
return intents;
}
}