aboutsummaryrefslogtreecommitdiffstats
path: root/main
diff options
context:
space:
mode:
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