Check for map before opening link

gtask_related_email
Alex Baker 6 years ago
parent 51749159a4
commit deec9c45a2

@ -1,10 +1,19 @@
package org.tasks.data;
import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.content.pm.ResolveInfo;
import android.net.Uri;
import android.os.Parcel;
import android.os.Parcelable;
import android.widget.Toast;
import androidx.annotation.Nullable;
import androidx.room.Embedded;
import androidx.room.Ignore;
import java.io.Serializable;
import java.util.List;
import org.tasks.R;
public class Location implements Serializable, Parcelable {
@ -130,8 +139,19 @@ public class Location implements Serializable, Parcelable {
return place.getDisplayAddress();
}
public String getGeoUri() {
return place.getGeoUri();
public void open(@Nullable Context context) {
if (context == null) {
return;
}
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setData(Uri.parse(place.getGeoUri()));
PackageManager pm = context.getPackageManager();
List<ResolveInfo> resolveInfos = pm.queryIntentActivities(intent, 0);
if (resolveInfos.isEmpty()) {
Toast.makeText(context, R.string.no_application_found_link, Toast.LENGTH_SHORT).show();
} else {
context.startActivity(intent);
}
}
@Override

@ -281,9 +281,7 @@ public class ViewHolder extends RecyclerView.ViewHolder {
if (tag instanceof Filter) {
callback.onClick((Filter) tag);
} else if (tag instanceof Location) {
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setData(Uri.parse(((Location) tag).getGeoUri()));
context.startActivity(intent);
((Location) tag).open(context);
} else if (tag instanceof TaskContainer) {
TaskContainer task = (TaskContainer) tag;
callback.toggleSubtasks(task, !task.isCollapsed());

@ -148,7 +148,7 @@ public class LocationControlSet extends TaskEditControlFragment {
chooseLocation();
} else {
List<Pair<Integer, Runnable>> options = new ArrayList<>();
options.add(Pair.create(R.string.open_map, this::openMap));
options.add(Pair.create(R.string.open_map, () -> location.open(getActivity())));
if (!Strings.isNullOrEmpty(location.getPhone())) {
options.add(Pair.create(R.string.action_call, this::call));
}
@ -220,12 +220,6 @@ public class LocationControlSet extends TaskEditControlFragment {
return TAG;
}
private void openMap() {
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setData(Uri.parse(location.getGeoUri()));
startActivity(intent);
}
private void openWebsite() {
startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(location.getUrl())));
}

@ -364,6 +364,7 @@ File %1$s contained %2$s.\n\n
<string name="show_completed">Show completed</string>
<string name="reverse">Reverse</string>
<string name="no_application_found">No application found to open attachment</string>
<string name="no_application_found_link">No application found to handle link</string>
<string name="add_attachment">Add attachment</string>
<string name="take_a_picture">Take a picture</string>
<string name="pick_from_gallery">Pick from gallery</string>

Loading…
Cancel
Save