Support for geobookmark creation from external geo uris

This commit is contained in:
Daniele 2021-10-05 09:29:47 +02:00
parent 065ef2bea6
commit fd14eea4b9
4 changed files with 18 additions and 6 deletions

View File

@ -24,8 +24,8 @@ android {
applicationId "it.danieleverducci.nextcloudmaps" applicationId "it.danieleverducci.nextcloudmaps"
minSdkVersion 23 minSdkVersion 23
targetSdkVersion 30 targetSdkVersion 30
versionCode 4 versionCode 5
versionName "0.3.2" versionName "0.3.3"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
} }

View File

@ -167,6 +167,7 @@ public class GeofavoriteDetailActivity extends AppCompatActivity implements Loca
mGeofavorite.setLng(coords[1]); mGeofavorite.setLng(coords[1]);
} catch (IllegalArgumentException e) { } catch (IllegalArgumentException e) {
Toast.makeText(this, R.string.error_unsupported_uri, Toast.LENGTH_SHORT).show(); Toast.makeText(this, R.string.error_unsupported_uri, Toast.LENGTH_SHORT).show();
finish();
} }
} else { } else {
// Precompile location with current one // Precompile location with current one

View File

@ -56,6 +56,7 @@ import it.danieleverducci.nextcloudmaps.activity.login.LoginActivity;
import it.danieleverducci.nextcloudmaps.activity.main.NavigationAdapter.NavigationItem; import it.danieleverducci.nextcloudmaps.activity.main.NavigationAdapter.NavigationItem;
import it.danieleverducci.nextcloudmaps.activity.main.SortingOrderDialogFragment.OnSortingOrderListener; import it.danieleverducci.nextcloudmaps.activity.main.SortingOrderDialogFragment.OnSortingOrderListener;
import it.danieleverducci.nextcloudmaps.model.Geofavorite; import it.danieleverducci.nextcloudmaps.model.Geofavorite;
import it.danieleverducci.nextcloudmaps.utils.GeoUriParser;
import it.danieleverducci.nextcloudmaps.utils.IntentGenerator; import it.danieleverducci.nextcloudmaps.utils.IntentGenerator;
import static android.view.View.GONE; import static android.view.View.GONE;

View File

@ -1,6 +1,7 @@
package it.danieleverducci.nextcloudmaps.utils; package it.danieleverducci.nextcloudmaps.utils;
import android.net.Uri; import android.net.Uri;
import android.util.Log;
import java.util.regex.Matcher; import java.util.regex.Matcher;
import java.util.regex.Pattern; import java.util.regex.Pattern;
@ -8,12 +9,21 @@ import java.util.regex.Pattern;
import it.danieleverducci.nextcloudmaps.model.Geofavorite; import it.danieleverducci.nextcloudmaps.model.Geofavorite;
public class GeoUriParser { public class GeoUriParser {
private static final Pattern PATTERN_GEO = Pattern.compile("geo:[\\d.]+,[\\d.]+"); private static final Pattern PATTERN_GEO = Pattern.compile("geo:(-?[\\d.]+),(-?[\\d.]+)");
public static double[] parseUri(Uri uri) throws IllegalArgumentException { public static double[] parseUri(Uri uri) throws IllegalArgumentException {
Matcher m = PATTERN_GEO.matcher(uri.getPath()); if (uri == null)
if (m.find()) { throw new IllegalArgumentException("no uri");
return new double[]{0, 0};
Matcher m = PATTERN_GEO.matcher(uri.toString());
if (m.find() && m.groupCount() == 2) {
String sLat = m.group(1);
String sLon = m.group(2);
try {
return new double[]{Double.parseDouble(sLat), Double.parseDouble(sLon)};
} catch (NumberFormatException e) {
throw new IllegalArgumentException("unable to parse uri");
}
} else { } else {
throw new IllegalArgumentException("unable to parse uri"); throw new IllegalArgumentException("unable to parse uri");
} }