aboutsummaryrefslogtreecommitdiffstats
path: root/main/src/cgeo/geocaching/Geocache.java
diff options
context:
space:
mode:
Diffstat (limited to 'main/src/cgeo/geocaching/Geocache.java')
-rw-r--r--main/src/cgeo/geocaching/Geocache.java34
1 files changed, 32 insertions, 2 deletions
diff --git a/main/src/cgeo/geocaching/Geocache.java b/main/src/cgeo/geocaching/Geocache.java
index 18a315c..9a8325d 100644
--- a/main/src/cgeo/geocaching/Geocache.java
+++ b/main/src/cgeo/geocaching/Geocache.java
@@ -516,13 +516,17 @@ public class Geocache implements ICache, IWaypoint {
}
public void openInBrowser(Activity fromActivity) {
- fromActivity.startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(getCacheUrl())));
+ fromActivity.startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(getBrowserCacheUrl())));
}
private String getCacheUrl() {
return getConnector().getCacheUrl(this);
}
+ private String getBrowserCacheUrl() {
+ return getConnector().getLongCacheUrl(this);
+ }
+
private IConnector getConnector() {
return ConnectorFactory.getConnector(this);
}
@@ -618,15 +622,27 @@ public class Geocache implements ICache, IWaypoint {
@Override
public String getHint() {
initializeCacheTexts();
+ assertTextNotNull(hint, "Hint");
return hint;
}
/**
+ * After lazy loading the lazily loaded field must be non {@code null}.
+ *
+ */
+ private static void assertTextNotNull(final String field, final String name) throws InternalError {
+ if (field == null) {
+ throw new InternalError(name + " field is not allowed to be null here");
+ }
+ }
+
+ /**
* Attention, calling this method may trigger a database access for the cache!
*/
@Override
public String getDescription() {
initializeCacheTexts();
+ assertTextNotNull(description, "Description");
return description;
}
@@ -635,7 +651,19 @@ public class Geocache implements ICache, IWaypoint {
*/
private void initializeCacheTexts() {
if (description == null || shortdesc == null || hint == null || location == null) {
- cgData.loadCacheTexts(this);
+ Geocache partial = cgData.loadCacheTexts(this.getGeocode());
+ if (description == null) {
+ setDescription(partial.getDescription());
+ }
+ if (shortdesc == null) {
+ setShortDescription(partial.getShortDescription());
+ }
+ if (hint == null) {
+ setHint(partial.getHint());
+ }
+ if (location == null) {
+ setLocation(partial.getLocation());
+ }
}
}
@@ -645,6 +673,7 @@ public class Geocache implements ICache, IWaypoint {
@Override
public String getShortDescription() {
initializeCacheTexts();
+ assertTextNotNull(shortdesc, "Short description");
return shortdesc;
}
@@ -673,6 +702,7 @@ public class Geocache implements ICache, IWaypoint {
@Override
public String getLocation() {
initializeCacheTexts();
+ assertTextNotNull(location, "Location");
return location;
}