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.java89
1 files changed, 64 insertions, 25 deletions
diff --git a/main/src/cgeo/geocaching/Geocache.java b/main/src/cgeo/geocaching/Geocache.java
index 836cccb..ac1c9b1 100644
--- a/main/src/cgeo/geocaching/Geocache.java
+++ b/main/src/cgeo/geocaching/Geocache.java
@@ -5,6 +5,7 @@ import cgeo.geocaching.activity.ActivityMixin;
import cgeo.geocaching.activity.IAbstractActivity;
import cgeo.geocaching.connector.ConnectorFactory;
import cgeo.geocaching.connector.IConnector;
+import cgeo.geocaching.connector.ILoggingManager;
import cgeo.geocaching.connector.capability.ISearchByCenter;
import cgeo.geocaching.connector.capability.ISearchByGeocode;
import cgeo.geocaching.connector.gc.GCConnector;
@@ -47,8 +48,8 @@ import java.util.Collections;
import java.util.Date;
import java.util.EnumSet;
import java.util.HashMap;
-import java.util.LinkedList;
import java.util.List;
+import java.util.Locale;
import java.util.Map;
import java.util.regex.Pattern;
@@ -175,7 +176,9 @@ public class Geocache implements ICache, IWaypoint {
}
/**
- * Gather missing information from another cache object.
+ * Gather missing information for new Geocache object from the stored Geocache object.
+ * This is called in the new Geocache parsed from website to set information not yet
+ * parsed.
*
* @param other
* the other version, or null if non-existent
@@ -187,6 +190,8 @@ public class Geocache implements ICache, IWaypoint {
}
updated = System.currentTimeMillis();
+ // if parsed cache is not yet detailed and stored is, the information of
+ // the parsed cache will be overwritten
if (!detailed && (other.detailed || zoomlevel < other.zoomlevel)) {
detailed = other.detailed;
detailedUpdate = other.detailedUpdate;
@@ -194,15 +199,19 @@ public class Geocache implements ICache, IWaypoint {
cacheType = other.cacheType;
zoomlevel = other.zoomlevel;
// boolean values must be enumerated here. Other types are assigned outside this if-statement
+ // TODO: check whether a search or a live map systematically returns those, in which case
+ // we want to keep the most recent one instead of getting information from the previously
+ // stored data. This is the case for "archived" for example which has been taken out of this
+ // list.
premiumMembersOnly = other.premiumMembersOnly;
reliableLatLon = other.reliableLatLon;
- archived = other.archived;
found = other.found;
disabled = other.disabled;
favorite = other.favorite;
onWatchlist = other.onWatchlist;
logOffline = other.logOffline;
finalDefined = other.finalDefined;
+ archived = other.archived;
}
/*
@@ -447,7 +456,7 @@ public class Geocache implements ICache, IWaypoint {
}
public void logVisit(final IAbstractActivity fromActivity) {
- if (StringUtils.isBlank(cacheId)) {
+ if (!getConnector().canLog(this)) {
fromActivity.showToast(((Activity) fromActivity).getResources().getString(R.string.err_cannot_log_visit));
return;
}
@@ -483,34 +492,37 @@ public class Geocache implements ICache, IWaypoint {
}
public List<LogType> getPossibleLogTypes() {
- final List<LogType> logTypes = new LinkedList<LogType>();
+ final List<LogType> logTypes = new ArrayList<LogType>();
if (isEventCache()) {
logTypes.add(LogType.WILL_ATTEND);
- logTypes.add(LogType.NOTE);
logTypes.add(LogType.ATTENDED);
- logTypes.add(LogType.NEEDS_ARCHIVE);
if (isOwner()) {
logTypes.add(LogType.ANNOUNCEMENT);
}
} else if (CacheType.WEBCAM == cacheType) {
logTypes.add(LogType.WEBCAM_PHOTO_TAKEN);
- logTypes.add(LogType.DIDNT_FIND_IT);
- logTypes.add(LogType.NOTE);
- logTypes.add(LogType.NEEDS_ARCHIVE);
- logTypes.add(LogType.NEEDS_MAINTENANCE);
} else {
logTypes.add(LogType.FOUND_IT);
+ }
+ if (!isEventCache()) {
logTypes.add(LogType.DIDNT_FIND_IT);
- logTypes.add(LogType.NOTE);
- logTypes.add(LogType.NEEDS_ARCHIVE);
+ }
+ logTypes.add(LogType.NOTE);
+ if (!isEventCache()) {
logTypes.add(LogType.NEEDS_MAINTENANCE);
}
if (isOwner()) {
logTypes.add(LogType.OWNER_MAINTENANCE);
- logTypes.add(LogType.TEMP_DISABLE_LISTING);
- logTypes.add(LogType.ENABLE_LISTING);
+ if (isDisabled()) {
+ logTypes.add(LogType.ENABLE_LISTING);
+ }
+ else {
+ logTypes.add(LogType.TEMP_DISABLE_LISTING);
+ }
logTypes.add(LogType.ARCHIVE);
- logTypes.remove(LogType.UPDATE_COORDINATES);
+ }
+ if (!isArchived() && !isOwner()) {
+ logTypes.add(LogType.NEEDS_ARCHIVE);
}
return logTypes;
}
@@ -551,6 +563,10 @@ public class Geocache implements ICache, IWaypoint {
return getConnector().supportsLogging();
}
+ public boolean supportsLogImages() {
+ return getConnector().supportsLogImages();
+ }
+
public boolean supportsOwnCoordinates() {
return getConnector().supportsOwnCoordinates();
}
@@ -559,6 +575,10 @@ public class Geocache implements ICache, IWaypoint {
return getConnector().getCacheRealm();
}
+ public ILoggingManager getLoggingManager(Activity activity) {
+ return getConnector().getLoggingManager(activity, this);
+ }
+
@Override
public float getDifficulty() {
return difficulty;
@@ -710,10 +730,7 @@ public class Geocache implements ICache, IWaypoint {
public String getPersonalNote() {
// non premium members have no personal notes, premium members have an empty string by default.
// map both to null, so other code doesn't need to differentiate
- if (StringUtils.isBlank(personalNote)) {
- return null;
- }
- return personalNote;
+ return StringUtils.defaultIfBlank(personalNote, null);
}
public boolean supportsUserActions() {
@@ -765,8 +782,8 @@ public class Geocache implements ICache, IWaypoint {
return favorite;
}
- public void setFavorite(boolean favourite) {
- this.favorite = favourite;
+ public void setFavorite(boolean favorite) {
+ this.favorite = favorite;
}
@Override
@@ -829,8 +846,7 @@ public class Geocache implements ICache, IWaypoint {
}
public boolean isVirtual() {
- return CacheType.VIRTUAL == cacheType || CacheType.WEBCAM == cacheType
- || CacheType.EARTH == cacheType;
+ return cacheType.isVirtual();
}
public boolean showSize() {
@@ -1360,6 +1376,9 @@ public class Geocache implements ICache, IWaypoint {
return null;
}
+ /**
+ * Detect coordinates in the personal note and convert them to user defined waypoints. Works by rule of thumb.
+ */
public void parseWaypointsFromNote() {
try {
if (StringUtils.isBlank(getPersonalNote())) {
@@ -1378,7 +1397,8 @@ public class Geocache implements ICache, IWaypoint {
((point.getLatitudeE6() % 1000) != 0 || (point.getLongitudeE6() % 1000) != 0) &&
!hasIdenticalWaypoint(point)) {
final String name = cgeoapplication.getInstance().getString(R.string.cache_personal_note) + " " + count;
- final Waypoint waypoint = new Waypoint(name, WaypointType.WAYPOINT, false);
+ final String potentialWaypointType = note.substring(Math.max(0, matcher.start() - 15));
+ final Waypoint waypoint = new Waypoint(name, parseWaypointType(potentialWaypointType), false);
waypoint.setCoords(point);
addOrChangeWaypoint(waypoint, false);
count++;
@@ -1395,6 +1415,25 @@ public class Geocache implements ICache, IWaypoint {
}
}
+ /**
+ * Detect waypoint types in the personal note text. It works by rule of thumb only.
+ */
+ private static WaypointType parseWaypointType(final String input) {
+ final String lowerInput = StringUtils.substring(input, 0, 20).toLowerCase(Locale.getDefault());
+ for (WaypointType wpType : WaypointType.values()) {
+ if (lowerInput.contains(wpType.getL10n().toLowerCase(Locale.getDefault()))) {
+ return wpType;
+ }
+ if (lowerInput.contains(wpType.id)) {
+ return wpType;
+ }
+ if (lowerInput.contains(wpType.name().toLowerCase(Locale.US))) {
+ return wpType;
+ }
+ }
+ return WaypointType.WAYPOINT;
+ }
+
private boolean hasIdenticalWaypoint(final Geopoint point) {
for (final Waypoint waypoint: waypoints) {
if (waypoint.getCoords().equals(point)) {