aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--main/src/cgeo/geocaching/apps/cache/WhereYouGoApp.java22
-rw-r--r--tests/src/cgeo/geocaching/apps/cache/WhereYouGoAppTest.java15
2 files changed, 36 insertions, 1 deletions
diff --git a/main/src/cgeo/geocaching/apps/cache/WhereYouGoApp.java b/main/src/cgeo/geocaching/apps/cache/WhereYouGoApp.java
index 79a5975..b2a2cad 100644
--- a/main/src/cgeo/geocaching/apps/cache/WhereYouGoApp.java
+++ b/main/src/cgeo/geocaching/apps/cache/WhereYouGoApp.java
@@ -3,14 +3,34 @@ package cgeo.geocaching.apps.cache;
import cgeo.geocaching.Geocache;
import cgeo.geocaching.R;
import cgeo.geocaching.enumerations.CacheType;
+import cgeo.geocaching.utils.TextUtils;
+
+import org.apache.commons.lang3.StringUtils;
+
+import android.app.Activity;
+import android.content.Intent;
+import android.net.Uri;
+
+import java.util.regex.Pattern;
public class WhereYouGoApp extends AbstractGeneralApp {
+ private static final Pattern PATTERN_CARTRIDGE = Pattern.compile("(" + Pattern.quote("http://www.wherigo.com/cartridge/details.aspx?") + ".*?)" + Pattern.quote("\""));
+
public WhereYouGoApp() {
super(getString(R.string.cache_menu_whereyougo), R.id.cache_app_whereyougo, "menion.android.whereyougo");
}
@Override
public boolean isEnabled(Geocache cache) {
- return cache.getType() == CacheType.WHERIGO;
+ return cache.getType() == CacheType.WHERIGO && StringUtils.isNotEmpty(getWhereIGoUrl(cache));
+ }
+
+ @Override
+ public void navigate(Activity activity, Geocache cache) {
+ activity.startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(getWhereIGoUrl(cache))));
+ }
+
+ protected static String getWhereIGoUrl(Geocache cache) {
+ return TextUtils.getMatch(cache.getDescription(), PATTERN_CARTRIDGE, null);
}
}
diff --git a/tests/src/cgeo/geocaching/apps/cache/WhereYouGoAppTest.java b/tests/src/cgeo/geocaching/apps/cache/WhereYouGoAppTest.java
new file mode 100644
index 0000000..5290c35
--- /dev/null
+++ b/tests/src/cgeo/geocaching/apps/cache/WhereYouGoAppTest.java
@@ -0,0 +1,15 @@
+package cgeo.geocaching.apps.cache;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+import cgeo.geocaching.Geocache;
+
+import junit.framework.TestCase;
+
+public class WhereYouGoAppTest extends TestCase {
+ public static void testGetWhereIGoUrl() throws Exception {
+ Geocache cache = new Geocache();
+ cache.setDescription("<p style=\"max-width:670px;\"><a href=\"http://www.wherigo.com/cartridge/details.aspx?CGUID=c4577c31-09e9-44f0-ae48-83737e57adbd\"><img class=\"InsideTable\"");
+ assertThat(WhereYouGoApp.getWhereIGoUrl(cache)).isEqualTo("http://www.wherigo.com/cartridge/details.aspx?CGUID=c4577c31-09e9-44f0-ae48-83737e57adbd");
+ }
+}