diff options
author | Bananeweizen <bananeweizen@gmx.de> | 2015-02-21 11:43:42 +0100 |
---|---|---|
committer | Bananeweizen <bananeweizen@gmx.de> | 2015-02-21 11:43:42 +0100 |
commit | 0f28169faf68b19b1218bf3c6e32c52b42017909 (patch) | |
tree | 42c4aa550766d7f3066a64fe505bbf5855146ff3 /main/src/cgeo/geocaching | |
parent | 5d001f813364ef96988ab432d59e2a3c82dd60d5 (diff) | |
download | cgeo-0f28169faf68b19b1218bf3c6e32c52b42017909.zip cgeo-0f28169faf68b19b1218bf3c6e32c52b42017909.tar.gz cgeo-0f28169faf68b19b1218bf3c6e32c52b42017909.tar.bz2 |
new: menu item to open geo checker
Diffstat (limited to 'main/src/cgeo/geocaching')
-rw-r--r-- | main/src/cgeo/geocaching/CacheDetailActivity.java | 5 | ||||
-rw-r--r-- | main/src/cgeo/geocaching/utils/CheckerUtils.java | 34 |
2 files changed, 39 insertions, 0 deletions
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; + } +} |