From 4f4587fd4d6a342cd197790df266ae639fe93c75 Mon Sep 17 00:00:00 2001 From: Paul Hawke Date: Fri, 29 Dec 2017 08:32:58 -0600 Subject: [PATCH] Moved code to reduce feature envy. --- .../java/fr/free/nrw/commons/location/LatLng.java | 13 +++++++++---- .../main/java/fr/free/nrw/commons/nearby/Place.java | 12 ++++++++++++ 2 files changed, 21 insertions(+), 4 deletions(-) diff --git a/app/src/main/java/fr/free/nrw/commons/location/LatLng.java b/app/src/main/java/fr/free/nrw/commons/location/LatLng.java index 494cce077..eeea75078 100644 --- a/app/src/main/java/fr/free/nrw/commons/location/LatLng.java +++ b/app/src/main/java/fr/free/nrw/commons/location/LatLng.java @@ -1,6 +1,7 @@ package fr.free.nrw.commons.location; import android.location.Location; +import android.net.Uri; import android.support.annotation.NonNull; /** @@ -11,15 +12,15 @@ public class LatLng { private final double latitude; private final double longitude; private final float accuracy; - + /** * Accepts latitude and longitude. * North and South values are cut off at 90° - * + * * @param latitude the latitude * @param longitude the longitude * @param accuracy the accuracy - * + * * Examples: * the Statue of Liberty is located at 40.69° N, 74.04° W * The Statue of Liberty could be constructed as LatLng(40.69, -74.04, 1.0) @@ -43,7 +44,7 @@ public class LatLng { public static LatLng from(@NonNull Location location) { return new LatLng(location.getLatitude(), location.getLongitude(), location.getAccuracy()); } - + /** * creates a hash code for the longitude and longitude */ @@ -153,4 +154,8 @@ public class LatLng { public double getLatitude() { return latitude; } + + public Uri getGmmIntentUri() { + return Uri.parse("geo:0,0?q=" + latitude + "," + longitude); + } } diff --git a/app/src/main/java/fr/free/nrw/commons/nearby/Place.java b/app/src/main/java/fr/free/nrw/commons/nearby/Place.java index e8290c6e2..e18292781 100644 --- a/app/src/main/java/fr/free/nrw/commons/nearby/Place.java +++ b/app/src/main/java/fr/free/nrw/commons/nearby/Place.java @@ -46,6 +46,18 @@ public class Place { this.distance = distance; } + public boolean hasWikipediaLink() { + return !(siteLinks == null || Uri.EMPTY.equals(siteLinks.getWikipediaLink())); + } + + public boolean hasWikidataLink() { + return !(siteLinks == null || Uri.EMPTY.equals(siteLinks.getWikidataLink())); + } + + public boolean hasCommonsLink() { + return !(siteLinks == null || Uri.EMPTY.equals(siteLinks.getCommonsLink())); + } + @Override public boolean equals(Object o) { if (o instanceof Place) {