diff --git a/TMessagesProj/src/main/java/org/telegram/messenger/SendMessagesHelper.java b/TMessagesProj/src/main/java/org/telegram/messenger/SendMessagesHelper.java index 9d226a8743..dc7447eb5f 100644 --- a/TMessagesProj/src/main/java/org/telegram/messenger/SendMessagesHelper.java +++ b/TMessagesProj/src/main/java/org/telegram/messenger/SendMessagesHelper.java @@ -3614,6 +3614,29 @@ public void run() { }); } + public static void prepareSendingLocation(final Location location, final long dialog_id) { + MessagesStorage.getInstance().getStorageQueue().postRunnable(new Runnable() { + @Override + public void run() { + Utilities.stageQueue.postRunnable(new Runnable() { + @Override + public void run() { + AndroidUtilities.runOnUIThread(new Runnable() { + @Override + public void run() { + TLRPC.TL_messageMediaGeo mediaGeo = new TLRPC.TL_messageMediaGeo(); + mediaGeo.geo = new TLRPC.TL_geoPoint(); + mediaGeo.geo.lat = location.getLatitude(); + mediaGeo.geo._long = location.getLongitude(); + SendMessagesHelper.getInstance().sendMessage(mediaGeo, dialog_id, null, null, null); + } + }); + } + }); + } + }); + } + public static void prepareSendingPhotos(ArrayList paths, ArrayList uris, final long dialog_id, final MessageObject reply_to_msg, final ArrayList captions, final ArrayList> masks, final InputContentInfoCompat inputContent, final boolean forceDocument, final ArrayList ttls) { if (paths == null && uris == null || paths != null && paths.isEmpty() || uris != null && uris.isEmpty()) { return; diff --git a/TMessagesProj/src/main/java/org/telegram/ui/LaunchActivity.java b/TMessagesProj/src/main/java/org/telegram/ui/LaunchActivity.java index a488f248ea..29364f8145 100644 --- a/TMessagesProj/src/main/java/org/telegram/ui/LaunchActivity.java +++ b/TMessagesProj/src/main/java/org/telegram/ui/LaunchActivity.java @@ -20,6 +20,7 @@ import android.graphics.Point; import android.graphics.Shader; import android.graphics.drawable.BitmapDrawable; +import android.location.Location; import android.net.Uri; import android.os.Build; import android.os.Bundle; @@ -90,11 +91,15 @@ import java.util.HashMap; import java.util.List; import java.util.Map; +import java.util.regex.Matcher; +import java.util.regex.Pattern; public class LaunchActivity extends Activity implements ActionBarLayout.ActionBarLayoutDelegate, NotificationCenter.NotificationCenterDelegate, DialogsActivity.DialogsActivityDelegate { private boolean finished; private String videoPath; + final private Pattern r = Pattern.compile("geo: ?(-?\\d+\\.\\d+),(-?\\d+\\.\\d+)(,|\\?z=)(-?\\d+)"); + private Location sendingLocation; private String sendingText; private ArrayList photoPathsArray; private ArrayList documentsPathsArray; @@ -806,8 +811,13 @@ private boolean handleIntent(Intent intent, boolean isNew, boolean restore, bool } } String subject = intent.getStringExtra(Intent.EXTRA_SUBJECT); - - if (text != null && text.length() != 0) { + Matcher m = r.matcher(text); + if(m.find()) { + sendingLocation = new Location(""); + sendingLocation.setLatitude(Double.parseDouble(m.group(1))); + sendingLocation.setLongitude(Double.parseDouble(m.group(2))); + } + else if (text != null && text.length() != 0) { if ((text.startsWith("http://") || text.startsWith("https://")) && subject != null && subject.length() != 0) { text = subject + "\n" + text; } @@ -859,7 +869,7 @@ private boolean handleIntent(Intent intent, boolean isNew, boolean restore, bool } } } - } else if (sendingText == null) { + } else if (sendingText == null && sendingLocation == null) { error = true; } } @@ -1206,7 +1216,7 @@ public void run() { } actionBarLayout.presentFragment(new AudioPlayerActivity(), false, true, true); pushOpened = true; - } else if (videoPath != null || photoPathsArray != null || sendingText != null || documentsPathsArray != null || contactsToSend != null || documentsUrisArray != null) { + } else if (videoPath != null || photoPathsArray != null || sendingText != null || sendingLocation != null || documentsPathsArray != null || contactsToSend != null || documentsUrisArray != null) { if (!AndroidUtilities.isTablet()) { NotificationCenter.getInstance().postNotificationName(NotificationCenter.closeChats); } @@ -1763,7 +1773,9 @@ public void didSelectDialog(DialogsActivity dialogsFragment, long dialog_id, boo if (sendingText != null) { SendMessagesHelper.prepareSendingText(sendingText, dialog_id); } - + if (sendingLocation != null) { + SendMessagesHelper.prepareSendingLocation(sendingLocation, dialog_id); + } if (documentsPathsArray != null || documentsUrisArray != null) { SendMessagesHelper.prepareSendingDocuments(documentsPathsArray, documentsOriginalPathsArray, documentsUrisArray, documentsMimeType, dialog_id, null, null); } @@ -1777,6 +1789,7 @@ public void didSelectDialog(DialogsActivity dialogsFragment, long dialog_id, boo photoPathsArray = null; videoPath = null; sendingText = null; + sendingLocation = null; documentsPathsArray = null; documentsOriginalPathsArray = null; contactsToSend = null;