aboutsummaryrefslogtreecommitdiffstats
path: root/main
diff options
context:
space:
mode:
authorSamuel Tardieu <sam@rfc1149.net>2015-03-17 10:17:13 +0100
committerSamuel Tardieu <sam@rfc1149.net>2015-03-17 10:17:15 +0100
commitec09b8c4dbc0a9cad38a1d45b30522a6f6c10933 (patch)
tree8b18b8a247f90ed896d58d38590dd95c4c1b28a8 /main
parentbe88c507c2097e64a9213430589231764cd8ec5e (diff)
downloadcgeo-ec09b8c4dbc0a9cad38a1d45b30522a6f6c10933.zip
cgeo-ec09b8c4dbc0a9cad38a1d45b30522a6f6c10933.tar.gz
cgeo-ec09b8c4dbc0a9cad38a1d45b30522a6f6c10933.tar.bz2
fix #4746: getUrl cannot be called on unknown trackables
Diffstat (limited to 'main')
-rw-r--r--main/src/cgeo/geocaching/Trackable.java7
-rw-r--r--main/src/cgeo/geocaching/TrackableActivity.java2
-rw-r--r--main/src/cgeo/geocaching/connector/trackable/AbstractTrackableConnector.java12
-rw-r--r--main/src/cgeo/geocaching/connector/trackable/TrackableConnector.java15
-rw-r--r--main/src/cgeo/geocaching/connector/trackable/UnknownTrackableConnector.java6
5 files changed, 37 insertions, 5 deletions
diff --git a/main/src/cgeo/geocaching/Trackable.java b/main/src/cgeo/geocaching/Trackable.java
index d7d2357..6ec8c0d 100644
--- a/main/src/cgeo/geocaching/Trackable.java
+++ b/main/src/cgeo/geocaching/Trackable.java
@@ -42,6 +42,13 @@ public class Trackable implements ILogable {
private List<LogEntry> logs = new ArrayList<>();
private String trackingcode = null;
+ /**
+ * Check whether this trackable has a corresponding URL.
+ */
+ public boolean hasUrl() {
+ return getConnector().hasTrackableUrls();
+ }
+
@NonNull
public String getUrl() {
return getConnector().getUrl(this);
diff --git a/main/src/cgeo/geocaching/TrackableActivity.java b/main/src/cgeo/geocaching/TrackableActivity.java
index e04fe9f..7d0ba3a 100644
--- a/main/src/cgeo/geocaching/TrackableActivity.java
+++ b/main/src/cgeo/geocaching/TrackableActivity.java
@@ -211,7 +211,7 @@ public class TrackableActivity extends AbstractViewPagerActivity<TrackableActivi
public boolean onPrepareOptionsMenu(final Menu menu) {
if (trackable != null) {
menu.findItem(R.id.menu_log_touch).setVisible(StringUtils.isNotBlank(geocode) && trackable.isLoggable());
- menu.findItem(R.id.menu_browser_trackable).setVisible(StringUtils.isNotBlank(trackable.getUrl()));
+ menu.findItem(R.id.menu_browser_trackable).setVisible(trackable.hasUrl());
}
return super.onPrepareOptionsMenu(menu);
}
diff --git a/main/src/cgeo/geocaching/connector/trackable/AbstractTrackableConnector.java b/main/src/cgeo/geocaching/connector/trackable/AbstractTrackableConnector.java
index c3a7437..03549d1 100644
--- a/main/src/cgeo/geocaching/connector/trackable/AbstractTrackableConnector.java
+++ b/main/src/cgeo/geocaching/connector/trackable/AbstractTrackableConnector.java
@@ -1,5 +1,6 @@
package cgeo.geocaching.connector.trackable;
+import cgeo.geocaching.Trackable;
import cgeo.geocaching.connector.AbstractConnector;
import cgeo.geocaching.connector.UserAction;
@@ -16,6 +17,11 @@ public abstract class AbstractTrackableConnector implements TrackableConnector {
}
@Override
+ public boolean hasTrackableUrls() {
+ return true;
+ }
+
+ @Override
@Nullable
public String getTrackableCodeFromUrl(@NonNull final String url) {
return null;
@@ -26,4 +32,10 @@ public abstract class AbstractTrackableConnector implements TrackableConnector {
public List<UserAction> getUserActions() {
return AbstractConnector.getDefaultUserActions();
}
+
+ @Override
+ @NonNull
+ public String getUrl(@NonNull final Trackable trackable) {
+ throw new IllegalStateException("this trackable does not have a corresponding URL");
+ }
}
diff --git a/main/src/cgeo/geocaching/connector/trackable/TrackableConnector.java b/main/src/cgeo/geocaching/connector/trackable/TrackableConnector.java
index 1281683..aea60e6 100644
--- a/main/src/cgeo/geocaching/connector/trackable/TrackableConnector.java
+++ b/main/src/cgeo/geocaching/connector/trackable/TrackableConnector.java
@@ -16,6 +16,21 @@ public interface TrackableConnector {
public boolean canHandleTrackable(final String geocode);
+ /**
+ * Check whether the connector has URLs corresponding the the trackable.
+ *
+ * @return <tt>true</tt> if the connector handles URLs, <tt>false</tt> otherwise
+ */
+ public boolean hasTrackableUrls();
+
+ /**
+ * Return the URL for a trackable. Might throw {@link IllegalStateException} if called
+ * on a connector which does not have URLs for trackables. This might be checked using
+ * {@link #hasTrackableUrls()}.
+ *
+ * @param trackable the trackable
+ * @return the URL corresponding to this trackable
+ */
@NonNull
public String getUrl(@NonNull final Trackable trackable);
diff --git a/main/src/cgeo/geocaching/connector/trackable/UnknownTrackableConnector.java b/main/src/cgeo/geocaching/connector/trackable/UnknownTrackableConnector.java
index 5fc7bf1..885df7e 100644
--- a/main/src/cgeo/geocaching/connector/trackable/UnknownTrackableConnector.java
+++ b/main/src/cgeo/geocaching/connector/trackable/UnknownTrackableConnector.java
@@ -2,7 +2,6 @@ package cgeo.geocaching.connector.trackable;
import cgeo.geocaching.Trackable;
-import org.eclipse.jdt.annotation.NonNull;
import org.eclipse.jdt.annotation.Nullable;
public class UnknownTrackableConnector extends AbstractTrackableConnector {
@@ -13,9 +12,8 @@ public class UnknownTrackableConnector extends AbstractTrackableConnector {
}
@Override
- @NonNull
- public String getUrl(@NonNull final Trackable trackable) {
- throw new IllegalStateException("getUrl cannot be called on unknown trackables");
+ public boolean hasTrackableUrls() {
+ return false;
}
@Override