aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--main/res/menu/cache_options.xml8
-rw-r--r--main/res/values/changelog_master.xml1
-rw-r--r--main/res/values/strings.xml1
-rw-r--r--main/src/cgeo/geocaching/CacheDetailActivity.java5
-rw-r--r--main/src/cgeo/geocaching/utils/CheckerUtils.java34
-rw-r--r--tests/src/cgeo/geocaching/utils/CheckerUtilsTest.java24
6 files changed, 72 insertions, 1 deletions
diff --git a/main/res/menu/cache_options.xml b/main/res/menu/cache_options.xml
index 8b40765..1032d99 100644
--- a/main/res/menu/cache_options.xml
+++ b/main/res/menu/cache_options.xml
@@ -83,5 +83,11 @@
app:actionProviderClass="android.support.v7.widget.ShareActionProvider"
app:showAsAction="ifRoom">
</item>
-
+ <item
+ android:id="@+id/menu_checker"
+ android:title="@string/cache_menu_checker"
+ android:visible="false"
+ app:showAsAction="ifRoom">
+ </item>
+
</menu> \ No newline at end of file
diff --git a/main/res/values/changelog_master.xml b/main/res/values/changelog_master.xml
index 51cf8f9..f861f3f 100644
--- a/main/res/values/changelog_master.xml
+++ b/main/res/values/changelog_master.xml
@@ -14,6 +14,7 @@
· New: Allow export of waypoints without coords to Locus\n
· New: Confirmation on backup/restore\n
· New: Links in personal notes can be clicked\n
+ · New: Menu in cache details to open geo checker\n
· Fix: Improve detection pattern for event start time\n
· Fix: Don\'t allow logs in the future\n
· Fix: Allow shortcut creation for All caches list\n
diff --git a/main/res/values/strings.xml b/main/res/values/strings.xml
index 3990ff6..be8cdf3 100644
--- a/main/res/values/strings.xml
+++ b/main/res/values/strings.xml
@@ -731,6 +731,7 @@
<string name="cache_menu_pebble">Pebble</string>
<string name="cache_menu_android_wear">Android Wear</string>
<string name="cache_menu_vote">Vote</string>
+ <string name="cache_menu_checker">Open geo checker</string>
<string name="cache_status">Status</string>
<string name="cache_status_offline_log">Saved Log</string>
<string name="cache_status_found">Found</string>
diff --git a/main/src/cgeo/geocaching/CacheDetailActivity.java b/main/src/cgeo/geocaching/CacheDetailActivity.java
index 93f2d31..14b6b81 100644
--- a/main/src/cgeo/geocaching/CacheDetailActivity.java
+++ b/main/src/cgeo/geocaching/CacheDetailActivity.java
@@ -44,6 +44,7 @@ import cgeo.geocaching.ui.OwnerActionsClickListener;
import cgeo.geocaching.ui.WeakReferenceHandler;
import cgeo.geocaching.ui.dialog.Dialogs;
import cgeo.geocaching.ui.logs.CacheLogsViewCreator;
+import cgeo.geocaching.utils.CheckerUtils;
import cgeo.geocaching.utils.CryptUtils;
import cgeo.geocaching.utils.Formatter;
import cgeo.geocaching.utils.ImageUtils;
@@ -498,6 +499,7 @@ public class CacheDetailActivity extends AbstractViewPagerActivity<CacheDetailAc
menu.findItem(R.id.menu_delete).setVisible(cache != null && cache.isOffline());
menu.findItem(R.id.menu_refresh).setVisible(cache != null && cache.isOffline());
menu.findItem(R.id.menu_gcvote).setVisible(cache != null && GCVote.isVotingPossible(cache));
+ menu.findItem(R.id.menu_checker).setVisible(cache != null && StringUtils.isNotEmpty(CheckerUtils.getCheckerUrl(cache)));
return super.onPrepareOptionsMenu(menu);
}
@@ -522,6 +524,9 @@ public class CacheDetailActivity extends AbstractViewPagerActivity<CacheDetailAc
case R.id.menu_gcvote:
showVoteDialog();
return true;
+ case R.id.menu_checker:
+ startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(CheckerUtils.getCheckerUrl(cache))));
+ return true;
default:
if (NavigationAppFactory.onMenuItemSelected(item, this, cache)) {
return true;
diff --git a/main/src/cgeo/geocaching/utils/CheckerUtils.java b/main/src/cgeo/geocaching/utils/CheckerUtils.java
new file mode 100644
index 0000000..956ebbf
--- /dev/null
+++ b/main/src/cgeo/geocaching/utils/CheckerUtils.java
@@ -0,0 +1,34 @@
+package cgeo.geocaching.utils;
+
+import cgeo.geocaching.Geocache;
+
+import org.apache.commons.lang3.StringUtils;
+import org.eclipse.jdt.annotation.NonNull;
+import org.eclipse.jdt.annotation.Nullable;
+
+import android.util.Patterns;
+
+import java.util.regex.Matcher;
+
+public final class CheckerUtils {
+ private static final String[] CHECKERS = new String[] { "geocheck.org", "geochecker.com", "certitudes.org" };
+
+ private CheckerUtils() {
+ // utility class
+ }
+
+ @Nullable
+ public static String getCheckerUrl(@NonNull final Geocache cache) {
+ final String description = cache.getDescription();
+ final Matcher matcher = Patterns.WEB_URL.matcher(description);
+ while (matcher.find()) {
+ final String url = matcher.group();
+ for (final String checker : CHECKERS) {
+ if (StringUtils.containsIgnoreCase(url, checker)) {
+ return url;
+ }
+ }
+ }
+ return null;
+ }
+}
diff --git a/tests/src/cgeo/geocaching/utils/CheckerUtilsTest.java b/tests/src/cgeo/geocaching/utils/CheckerUtilsTest.java
new file mode 100644
index 0000000..70cf888
--- /dev/null
+++ b/tests/src/cgeo/geocaching/utils/CheckerUtilsTest.java
@@ -0,0 +1,24 @@
+package cgeo.geocaching.utils;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+import cgeo.geocaching.Geocache;
+
+import junit.framework.TestCase;
+
+public class CheckerUtilsTest extends TestCase {
+
+ public static void testGetCheckerUrl() throws Exception {
+ assertUrl("<p style=\"text-align:center;\"><a href=\"http://geocheck.org/geo_inputchkcoord.php?gid=618932716cc7e68-c4bb-4f41-8bb1-3e0a3e374a1f\" target=\"_blank\"><img", "http://geocheck.org/geo_inputchkcoord.php?gid=618932716cc7e68-c4bb-4f41-8bb1-3e0a3e374a1f");
+ assertUrl("<p style=\"text-align:center;\"><a href=\"http://google.com/geo_inputchkcoord.php?gid=618932716cc7e68-c4bb-4f41-8bb1-3e0a3e374a1f\" target=\"_blank\"><img", null);
+ assertUrl("http://www.certitudes.org/certitude?wp=GC5MVX7", "http://www.certitudes.org/certitude?wp=GC5MVX7");
+ assertUrl("http://geochecker.com/index.php?code=e001928e3c2682ec2bae0f24b9d02cfb&action=check&wp=474350573454&name=47656f636865636b6572205465737420666f72204e33382030302e303030205737362030302e303030", "http://geochecker.com/index.php?code=e001928e3c2682ec2bae0f24b9d02cfb&action=check&wp=474350573454&name=47656f636865636b6572205465737420666f72204e33382030302e303030205737362030302e303030");
+ }
+
+ private static void assertUrl(final String description, final String expected) {
+ final Geocache geocache = new Geocache();
+ geocache.setDescription(description);
+ assertThat(CheckerUtils.getCheckerUrl(geocache)).isEqualTo(expected);
+ }
+
+}