diff --git a/app/build.gradle b/app/build.gradle index ae1f386..2f892cb 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -24,8 +24,8 @@ android { applicationId "it.danieleverducci.nextcloudmaps" minSdkVersion 23 targetSdkVersion 30 - versionCode 4 - versionName "0.3.2" + versionCode 5 + versionName "0.3.3" testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" } diff --git a/app/src/main/java/it/danieleverducci/nextcloudmaps/activity/detail/GeofavoriteDetailActivity.java b/app/src/main/java/it/danieleverducci/nextcloudmaps/activity/detail/GeofavoriteDetailActivity.java index f3d9bb9..6a712f2 100644 --- a/app/src/main/java/it/danieleverducci/nextcloudmaps/activity/detail/GeofavoriteDetailActivity.java +++ b/app/src/main/java/it/danieleverducci/nextcloudmaps/activity/detail/GeofavoriteDetailActivity.java @@ -167,6 +167,7 @@ public class GeofavoriteDetailActivity extends AppCompatActivity implements Loca mGeofavorite.setLng(coords[1]); } catch (IllegalArgumentException e) { Toast.makeText(this, R.string.error_unsupported_uri, Toast.LENGTH_SHORT).show(); + finish(); } } else { // Precompile location with current one diff --git a/app/src/main/java/it/danieleverducci/nextcloudmaps/activity/main/MainActivity.java b/app/src/main/java/it/danieleverducci/nextcloudmaps/activity/main/MainActivity.java index 97fa973..d53a7ab 100644 --- a/app/src/main/java/it/danieleverducci/nextcloudmaps/activity/main/MainActivity.java +++ b/app/src/main/java/it/danieleverducci/nextcloudmaps/activity/main/MainActivity.java @@ -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.SortingOrderDialogFragment.OnSortingOrderListener; import it.danieleverducci.nextcloudmaps.model.Geofavorite; +import it.danieleverducci.nextcloudmaps.utils.GeoUriParser; import it.danieleverducci.nextcloudmaps.utils.IntentGenerator; import static android.view.View.GONE; diff --git a/app/src/main/java/it/danieleverducci/nextcloudmaps/utils/GeoUriParser.java b/app/src/main/java/it/danieleverducci/nextcloudmaps/utils/GeoUriParser.java index c1d4600..b4e64d6 100644 --- a/app/src/main/java/it/danieleverducci/nextcloudmaps/utils/GeoUriParser.java +++ b/app/src/main/java/it/danieleverducci/nextcloudmaps/utils/GeoUriParser.java @@ -1,6 +1,7 @@ package it.danieleverducci.nextcloudmaps.utils; import android.net.Uri; +import android.util.Log; import java.util.regex.Matcher; import java.util.regex.Pattern; @@ -8,12 +9,21 @@ import java.util.regex.Pattern; import it.danieleverducci.nextcloudmaps.model.Geofavorite; 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 { - Matcher m = PATTERN_GEO.matcher(uri.getPath()); - if (m.find()) { - return new double[]{0, 0}; + if (uri == null) + throw new IllegalArgumentException("no uri"); + + 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 { throw new IllegalArgumentException("unable to parse uri"); }