Skip to content

Commit cbc7570

Browse files
committed
Add "Send location…" feature
This commit adds a new menu item in the overflow button on the friend info panel labeled "Send location…". Clicking on it will send the friend's location via a VIEW intent to an activity of your choosing.
1 parent b3540fe commit cbc7570

File tree

4 files changed

+23
-1
lines changed

4 files changed

+23
-1
lines changed

app/src/main/java/xyz/zood/george/MainFragment.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import android.graphics.Bitmap;
1010
import android.graphics.Color;
1111
import android.location.Location;
12+
import android.net.Uri;
1213
import android.os.Bundle;
1314
import android.os.Looper;
1415
import android.text.TextUtils;
@@ -63,6 +64,7 @@
6364
import com.google.firebase.messaging.FirebaseMessaging;
6465

6566
import java.util.ArrayList;
67+
import java.util.Locale;
6668
import java.util.Map;
6769

6870
import io.pijun.george.App;
@@ -1079,6 +1081,20 @@ public void run() {
10791081
dialog.show(getParentFragmentManager(), null);
10801082
}
10811083

1084+
public void onInfoPanelSendLocation(@NonNull String username, @Nullable FriendLocation location) {
1085+
if (location == null) {
1086+
// the friend isn't sharing their location with us
1087+
return;
1088+
}
1089+
1090+
Intent i = new Intent();
1091+
i.setAction(Intent.ACTION_VIEW);
1092+
i.setData(Uri.parse(String.format(Locale.ENGLISH, "geo:0,0?q=%f,%f(%s)", location.latitude, location.longitude, username)));
1093+
if (i.resolveActivity(requireContext().getPackageManager()) != null) {
1094+
startActivity(i);
1095+
}
1096+
}
1097+
10821098
@Override
10831099
public void onInfoPanelShareToggled(@NonNull FriendRecord friend, boolean shouldShare) {
10841100
App.runInBackground(new WorkerRunnable() {

app/src/main/java/xyz/zood/george/widget/InfoPanel.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,9 @@ private void onInfoOverflowClicked() {
241241
menu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
242242
@Override
243243
public boolean onMenuItemClick(MenuItem item) {
244-
if (item.getItemId() == R.id.remove_friend) {
244+
if (item.getItemId() == R.id.send_location) {
245+
listener.onInfoPanelSendLocation(friend.user.username, currLoc);
246+
} else if (item.getItemId() == R.id.remove_friend) {
245247
listener.onInfoPanelRemoveFriend(friend);
246248
} else if (item.getItemId() == R.id.view_safety_number) {
247249
listener.onInfoPanelViewSafetyNumber(friend);
@@ -501,6 +503,8 @@ public interface Listener {
501503
@UiThread
502504
void onInfoPanelRemoveFriend(@NonNull FriendRecord friend);
503505
@UiThread
506+
void onInfoPanelSendLocation(@NonNull String username, @Nullable FriendLocation friend);
507+
@UiThread
504508
void onInfoPanelShareToggled(@NonNull FriendRecord friend, boolean shouldShare);
505509
@UiThread
506510
void onInfoPanelViewSafetyNumber(@NonNull FriendRecord friend);
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<menu xmlns:android="http://schemas.android.com/apk/res/android">
3+
<item android:id="@+id/send_location" android:title="@string/send_location_ellipsis" />
34
<item android:id="@+id/view_safety_number" android:title="@string/view_safety_number" />
45
<item android:id="@+id/remove_friend" android:title="@string/remove_friend" />
56
</menu>

app/src/main/res/values/strings.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,4 +195,5 @@
195195
<string name="no_thanks">No, thanks</string>
196196
<string name="activity_recognition_permission_needed">Activity recognition permission needed</string>
197197
<string name="my_location">My location</string>
198+
<string name="send_location_ellipsis">Send location…</string>
198199
</resources>

0 commit comments

Comments
 (0)