[TF][MAPS] support geo: intents

This patch adds the ability for Telegram to parse locations from send
intents containing a geo:<lat>,<lon>,<zoom> string.

This is done by various map applications, including the popular OSMAnd
and Orux maps. This patch enables the user to share the position of a
POI or destination with Telegram and have it send as a location.

(cherry picked from commit 7805e28e3ea6e402cb404f79e4f463a7cf5faf71)
This commit is contained in:
thermatk 2020-01-12 10:34:25 +01:00 committed by 世界
parent 6a3c15a231
commit d1676d641c
No known key found for this signature in database
GPG Key ID: CD109927C34A63C4
2 changed files with 57 additions and 3 deletions

View File

@ -5268,6 +5268,29 @@ public class SendMessagesHelper extends BaseController implements NotificationCe
}).start();
}
@UiThread
public static void prepareSendingLocation(AccountInstance accountInstance, final Location location, final long dialog_id) {
accountInstance.getMessagesStorage().getStorageQueue().postRunnable(() -> Utilities.stageQueue.postRunnable(() -> AndroidUtilities.runOnUIThread(() -> {
CharSequence venueTitle = location.getExtras().getCharSequence("venueTitle");
CharSequence venueAddress = location.getExtras().getCharSequence("venueAddress");
TLRPC.MessageMedia sendingMedia;
if(venueTitle != null || venueAddress != null) {
sendingMedia = new TLRPC.TL_messageMediaVenue();
sendingMedia.address = venueAddress == null ? "" : venueAddress.toString();
sendingMedia.title = venueTitle == null ? "" : venueTitle.toString();
sendingMedia.provider = "";
sendingMedia.venue_id = "";
}
else {
sendingMedia = new TLRPC.TL_messageMediaGeo();
}
sendingMedia.geo = new TLRPC.TL_geoPoint();
sendingMedia.geo.lat = location.getLatitude();
sendingMedia.geo._long = location.getLongitude();
accountInstance.getSendMessagesHelper().sendMessage(sendingMedia, dialog_id, null, null, null, true, 0);
})));
}
@UiThread
public static void prepareSendingPhoto(AccountInstance accountInstance, String imageFilePath, Uri imageUri, long dialog_id, MessageObject reply_to_msg, CharSequence caption, ArrayList<TLRPC.MessageEntity> entities, ArrayList<TLRPC.InputDocument> stickers, InputContentInfoCompat inputContent, int ttl, MessageObject editingMessageObject, boolean notify, int scheduleDate) {
SendingMediaInfo info = new SendingMediaInfo();

View File

@ -110,6 +110,8 @@ import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import androidx.recyclerview.widget.ItemTouchHelper;
import androidx.recyclerview.widget.LinearLayoutManager;
@ -120,6 +122,8 @@ import tw.nekomimi.nekogram.settings.NekoSettingsActivity;
public class LaunchActivity extends Activity implements ActionBarLayout.ActionBarLayoutDelegate, NotificationCenter.NotificationCenterDelegate, DialogsActivity.DialogsActivityDelegate {
private boolean finished;
final private Pattern locationRegex = Pattern.compile("geo: ?(-?\\d+\\.\\d+),(-?\\d+\\.\\d+)(,|\\?z=)(-?\\d+)");
private Location sendingLocation;
private String videoPath;
private String sendingText;
private ArrayList<SendMessagesHelper.SendingMediaInfo> photoPathsArray;
@ -1067,6 +1071,7 @@ public class LaunchActivity extends Activity implements ActionBarLayout.ActionBa
photoPathsArray = null;
videoPath = null;
sendingText = null;
sendingLocation = null;
documentsPathsArray = null;
documentsOriginalPathsArray = null;
documentsMimeType = null;
@ -1110,7 +1115,28 @@ public class LaunchActivity extends Activity implements ActionBarLayout.ActionBa
String subject = intent.getStringExtra(Intent.EXTRA_SUBJECT);
if (!TextUtils.isEmpty(text)) {
if ((text.startsWith("http://") || text.startsWith("https://")) && !TextUtils.isEmpty(subject)) {
Matcher m = locationRegex.matcher(text);
if (m.find()) {
String lines[] = text.split("\\n");
String venueTitle = null;
String venueAddress = null;
if (lines[0].equals("My Position")){
// Use normal GeoPoint message (user position)
}
else if(!lines[0].contains("geo:")){
venueTitle = lines[0];
if(!lines[1].contains("geo:")){
venueAddress = lines[1];
}
}
sendingLocation = new Location("");
sendingLocation.setLatitude(Double.parseDouble(m.group(1)));
sendingLocation.setLongitude(Double.parseDouble(m.group(2)));
Bundle bundle = new Bundle();
bundle.putCharSequence("venueTitle", venueTitle);
bundle.putCharSequence("venueAddress", venueAddress);
sendingLocation.setExtras(bundle);
} else if ((text.startsWith("http://") || text.startsWith("https://")) && !TextUtils.isEmpty(subject)) {
text = subject + "\n" + text;
}
sendingText = text;
@ -1163,7 +1189,7 @@ public class LaunchActivity extends Activity implements ActionBarLayout.ActionBa
}
}
}
} else if (sendingText == null) {
} else if (sendingText == null && sendingLocation == null) {
error = true;
}
}
@ -1763,7 +1789,7 @@ public class LaunchActivity extends Activity implements ActionBarLayout.ActionBa
}));
}
pushOpened = false;
} 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(intentAccount[0]).postNotificationName(NotificationCenter.closeChats);
}
@ -2713,6 +2739,10 @@ public class LaunchActivity extends Activity implements ActionBarLayout.ActionBa
}
SendMessagesHelper.prepareSendingDocuments(accountInstance, documentsPathsArray, documentsOriginalPathsArray, documentsUrisArray, caption, documentsMimeType, did, null, null, null, true, 0);
}
if (sendingLocation != null) {
SendMessagesHelper.prepareSendingLocation(accountInstance, sendingLocation, did);
sendingText = null;
}
if (sendingText != null) {
SendMessagesHelper.prepareSendingText(accountInstance, sendingText, did, true, 0);
}
@ -2734,6 +2764,7 @@ public class LaunchActivity extends Activity implements ActionBarLayout.ActionBa
photoPathsArray = null;
videoPath = null;
sendingText = null;
sendingLocation = null;
documentsPathsArray = null;
documentsOriginalPathsArray = null;
contactsToSend = null;