aboutsummaryrefslogtreecommitdiffstats
path: root/main
diff options
context:
space:
mode:
authorSamuel Tardieu <sam@rfc1149.net>2015-03-17 10:22:55 +0100
committerSamuel Tardieu <sam@rfc1149.net>2015-03-17 10:22:55 +0100
commit18a87f11698e86e87720accfd743f08f092e29f7 (patch)
tree4f7dd20bbd3a4a18fa90807289999ba4cff3bfe8 /main
parentaa636ae7714ff3263a3ca4b338327519e482589c (diff)
parentec09b8c4dbc0a9cad38a1d45b30522a6f6c10933 (diff)
downloadcgeo-18a87f11698e86e87720accfd743f08f092e29f7.zip
cgeo-18a87f11698e86e87720accfd743f08f092e29f7.tar.gz
cgeo-18a87f11698e86e87720accfd743f08f092e29f7.tar.bz2
Merge branch 'issue-4746' into release
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 653eb17..0b4e27a 100644
--- a/main/src/cgeo/geocaching/TrackableActivity.java
+++ b/main/src/cgeo/geocaching/TrackableActivity.java
@@ -215,7 +215,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