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.java145
1 files changed, 64 insertions, 81 deletions
diff --git a/main/src/cgeo/geocaching/Geocache.java b/main/src/cgeo/geocaching/Geocache.java
index 7aceed4..35d6c17 100644
--- a/main/src/cgeo/geocaching/Geocache.java
+++ b/main/src/cgeo/geocaching/Geocache.java
@@ -1,6 +1,6 @@
package cgeo.geocaching;
-import cgeo.geocaching.cgData.StorageLocation;
+import cgeo.geocaching.DataStore.StorageLocation;
import cgeo.geocaching.activity.ActivityMixin;
import cgeo.geocaching.connector.ConnectorFactory;
import cgeo.geocaching.connector.IConnector;
@@ -21,6 +21,7 @@ import cgeo.geocaching.enumerations.LogType;
import cgeo.geocaching.enumerations.WaypointType;
import cgeo.geocaching.files.GPXParser;
import cgeo.geocaching.geopoint.Geopoint;
+import cgeo.geocaching.list.StoredList;
import cgeo.geocaching.network.HtmlImage;
import cgeo.geocaching.settings.Settings;
import cgeo.geocaching.utils.CancellableHandler;
@@ -31,7 +32,8 @@ import cgeo.geocaching.utils.LogTemplateProvider.LogContext;
import cgeo.geocaching.utils.MatcherWrapper;
import cgeo.geocaching.utils.UncertainProperty;
-import org.apache.commons.collections.CollectionUtils;
+import org.apache.commons.collections4.CollectionUtils;
+import org.apache.commons.collections4.Predicate;
import org.apache.commons.lang3.BooleanUtils;
import org.apache.commons.lang3.ObjectUtils;
import org.apache.commons.lang3.StringUtils;
@@ -112,20 +114,20 @@ public class Geocache implements ICache, IWaypoint {
private final List<String> attributes = new LazyInitializedList<String>() {
@Override
public List<String> call() {
- return cgData.loadAttributes(geocode);
+ return DataStore.loadAttributes(geocode);
}
};
private final List<Waypoint> waypoints = new LazyInitializedList<Waypoint>() {
@Override
public List<Waypoint> call() {
- return cgData.loadWaypoints(geocode);
+ return DataStore.loadWaypoints(geocode);
}
};
private List<Image> spoilers = null;
private final List<LogEntry> logs = new LazyInitializedList<LogEntry>() {
@Override
public List<LogEntry> call() {
- return cgData.loadLogs(geocode);
+ return DataStore.loadLogs(geocode);
}
};
private List<Trackable> inventory = null;
@@ -461,7 +463,7 @@ public class Geocache implements ICache, IWaypoint {
public void logOffline(final Activity fromActivity, final LogType logType) {
final boolean mustIncludeSignature = StringUtils.isNotBlank(Settings.getSignature()) && Settings.isAutoInsertSignature();
- final String initial = mustIncludeSignature ? LogTemplateProvider.applyTemplates(Settings.getSignature(), new LogContext(this, true)) : "";
+ final String initial = mustIncludeSignature ? LogTemplateProvider.applyTemplates(Settings.getSignature(), new LogContext(this, null, true)) : "";
logOffline(fromActivity, initial, Calendar.getInstance(), logType);
}
@@ -469,12 +471,12 @@ public class Geocache implements ICache, IWaypoint {
if (logType == LogType.UNKNOWN) {
return;
}
- final boolean status = cgData.saveLogOffline(geocode, date.getTime(), logType, log);
+ final boolean status = DataStore.saveLogOffline(geocode, date.getTime(), logType, log);
final Resources res = fromActivity.getResources();
if (status) {
ActivityMixin.showToast(fromActivity, res.getString(R.string.info_log_saved));
- cgData.saveVisitDate(geocode);
+ DataStore.saveVisitDate(geocode);
logOffline = Boolean.TRUE;
notifyChange();
@@ -484,44 +486,12 @@ public class Geocache implements ICache, IWaypoint {
}
public void clearOfflineLog() {
- cgData.clearLogOffline(geocode);
+ DataStore.clearLogOffline(geocode);
notifyChange();
}
public List<LogType> getPossibleLogTypes() {
- final List<LogType> logTypes = new ArrayList<LogType>();
- if (isEventCache()) {
- logTypes.add(LogType.WILL_ATTEND);
- logTypes.add(LogType.ATTENDED);
- if (isOwner()) {
- logTypes.add(LogType.ANNOUNCEMENT);
- }
- } else if (CacheType.WEBCAM == cacheType.getValue()) {
- logTypes.add(LogType.WEBCAM_PHOTO_TAKEN);
- } else {
- logTypes.add(LogType.FOUND_IT);
- }
- if (!isEventCache()) {
- logTypes.add(LogType.DIDNT_FIND_IT);
- }
- logTypes.add(LogType.NOTE);
- if (!isEventCache()) {
- logTypes.add(LogType.NEEDS_MAINTENANCE);
- }
- if (isOwner()) {
- logTypes.add(LogType.OWNER_MAINTENANCE);
- if (isDisabled()) {
- logTypes.add(LogType.ENABLE_LISTING);
- }
- else {
- logTypes.add(LogType.TEMP_DISABLE_LISTING);
- }
- logTypes.add(LogType.ARCHIVE);
- }
- if (!isArchived() && !isOwner()) {
- logTypes.add(LogType.NEEDS_ARCHIVE);
- }
- return logTypes;
+ return getConnector().getPossibleLogTypes(this);
}
public void openInBrowser(Activity fromActivity) {
@@ -664,7 +634,7 @@ public class Geocache implements ICache, IWaypoint {
*/
private void initializeCacheTexts() {
if (description == null || shortdesc == null || hint == null || location == null) {
- final Geocache partial = cgData.loadCacheTexts(this.getGeocode());
+ final Geocache partial = DataStore.loadCacheTexts(this.getGeocode());
if (description == null) {
setDescription(partial.getDescription());
}
@@ -841,7 +811,13 @@ public class Geocache implements ICache, IWaypoint {
}
public boolean showSize() {
- return !((isEventCache() || isVirtual()) && size == CacheSize.NOT_CHOSEN);
+ if (size == CacheSize.NOT_CHOSEN) {
+ return false;
+ }
+ if (isEventCache() || isVirtual()) {
+ return false;
+ }
+ return true;
}
public long getUpdated() {
@@ -1028,7 +1004,7 @@ public class Geocache implements ICache, IWaypoint {
}
}
}
- return saveToDatabase && cgData.saveWaypoints(this);
+ return saveToDatabase && DataStore.saveWaypoints(this);
}
/**
@@ -1244,7 +1220,7 @@ public class Geocache implements ICache, IWaypoint {
// when waypoint was edited, finalDefined may have changed
resetFinalDefined();
}
- return saveToDatabase && cgData.saveWaypoint(waypoint.getId(), geocode, waypoint);
+ return saveToDatabase && DataStore.saveWaypoint(waypoint.getId(), geocode, waypoint);
}
public boolean hasWaypoints() {
@@ -1295,9 +1271,9 @@ public class Geocache implements ICache, IWaypoint {
final int index = getWaypointIndex(original);
final Waypoint copy = new Waypoint(original);
copy.setUserDefined();
- copy.setName(cgeoapplication.getInstance().getString(R.string.waypoint_copy_of) + " " + copy.getName());
+ copy.setName(CgeoApplication.getInstance().getString(R.string.waypoint_copy_of) + " " + copy.getName());
waypoints.add(index + 1, copy);
- return cgData.saveWaypoint(-1, geocode, copy);
+ return DataStore.saveWaypoint(-1, geocode, copy);
}
/**
@@ -1317,8 +1293,8 @@ public class Geocache implements ICache, IWaypoint {
if (waypoint.isUserDefined()) {
final int index = getWaypointIndex(waypoint);
waypoints.remove(index);
- cgData.deleteWaypoint(waypoint.getId());
- cgData.removeCache(geocode, EnumSet.of(RemoveFlag.REMOVE_CACHE));
+ DataStore.deleteWaypoint(waypoint.getId());
+ DataStore.removeCache(geocode, EnumSet.of(RemoveFlag.REMOVE_CACHE));
// Check status if Final is defined
if (waypoint.isFinalWithCoords()) {
resetFinalDefined();
@@ -1337,8 +1313,8 @@ public class Geocache implements ICache, IWaypoint {
public void deleteWaypointForce(Waypoint waypoint) {
final int index = getWaypointIndex(waypoint);
waypoints.remove(index);
- cgData.deleteWaypoint(waypoint.getId());
- cgData.removeCache(geocode, EnumSet.of(RemoveFlag.REMOVE_CACHE));
+ DataStore.deleteWaypoint(waypoint.getId());
+ DataStore.removeCache(geocode, EnumSet.of(RemoveFlag.REMOVE_CACHE));
resetFinalDefined();
}
@@ -1406,7 +1382,7 @@ public class Geocache implements ICache, IWaypoint {
if (point.getLatitudeE6() != 0 && point.getLongitudeE6() != 0 &&
((point.getLatitudeE6() % 1000) != 0 || (point.getLongitudeE6() % 1000) != 0) &&
!hasIdenticalWaypoint(point)) {
- final String name = cgeoapplication.getInstance().getString(R.string.cache_personal_note) + " " + count;
+ final String name = CgeoApplication.getInstance().getString(R.string.cache_personal_note) + " " + count;
final String potentialWaypointType = note.substring(Math.max(0, matcher.start() - 15));
final Waypoint waypoint = new Waypoint(name, parseWaypointType(potentialWaypointType), false);
waypoint.setCoords(point);
@@ -1511,8 +1487,8 @@ public class Geocache implements ICache, IWaypoint {
public void drop(Handler handler) {
try {
- cgData.markDropped(Collections.singletonList(this));
- cgData.removeCache(getGeocode(), EnumSet.of(RemoveFlag.REMOVE_CACHE));
+ DataStore.markDropped(Collections.singletonList(this));
+ DataStore.removeCache(getGeocode(), EnumSet.of(RemoveFlag.REMOVE_CACHE));
handler.sendMessage(Message.obtain());
} catch (final Exception e) {
@@ -1563,7 +1539,7 @@ public class Geocache implements ICache, IWaypoint {
}
public void refresh(int newListId, CancellableHandler handler) {
- cgData.removeCache(geocode, EnumSet.of(RemoveFlag.REMOVE_CACHE));
+ DataStore.removeCache(geocode, EnumSet.of(RemoveFlag.REMOVE_CACHE));
storeCache(null, geocode, newListId, true, handler);
}
@@ -1639,7 +1615,7 @@ public class Geocache implements ICache, IWaypoint {
}
cache.setListId(listId);
- cgData.saveCache(cache, EnumSet.of(SaveFlag.SAVE_DB));
+ DataStore.saveCache(cache, EnumSet.of(SaveFlag.SAVE_DB));
if (CancellableHandler.isCancelled(handler)) {
return;
@@ -1661,9 +1637,9 @@ public class Geocache implements ICache, IWaypoint {
return null;
}
- if (!forceReload && listId == StoredList.TEMPORARY_LIST_ID && (cgData.isOffline(geocode, guid) || cgData.isThere(geocode, guid, true, true))) {
+ if (!forceReload && listId == StoredList.TEMPORARY_LIST_ID && (DataStore.isOffline(geocode, guid) || DataStore.isThere(geocode, guid, true, true))) {
final SearchResult search = new SearchResult();
- final String realGeocode = StringUtils.isNotBlank(geocode) ? geocode : cgData.getGeocodeForGuid(guid);
+ final String realGeocode = StringUtils.isNotBlank(geocode) ? geocode : DataStore.getGeocodeForGuid(guid);
search.addGeocode(realGeocode);
return search;
}
@@ -1693,30 +1669,30 @@ public class Geocache implements ICache, IWaypoint {
if (!isEventCache()) {
return null;
}
+
+ final String hourLocalized = CgeoApplication.getInstance().getString(R.string.cache_time_full_hours);
+ ArrayList<Pattern> patterns = new ArrayList<Pattern>();
+
// 12:34
- final Pattern time = Pattern.compile("\\b(\\d{1,2})\\:(\\d\\d)\\b");
- final MatcherWrapper matcher = new MatcherWrapper(time, getDescription());
- while (matcher.find()) {
- try {
- final int hours = Integer.valueOf(matcher.group(1));
- final int minutes = Integer.valueOf(matcher.group(2));
- if (hours >= 0 && hours < 24 && minutes >= 0 && minutes < 60) {
- return String.valueOf(hours * 60 + minutes);
- }
- } catch (final NumberFormatException e) {
- // cannot happen, but static code analysis doesn't know
- }
- }
- // 12 o'clock
- final String hourLocalized = cgeoapplication.getInstance().getString(R.string.cache_time_full_hours);
+ patterns.add(Pattern.compile("\\b(\\d{1,2})\\:(\\d\\d)\\b"));
if (StringUtils.isNotBlank(hourLocalized)) {
- final Pattern fullHours = Pattern.compile("\\b(\\d{1,2})\\s+" + Pattern.quote(hourLocalized), Pattern.CASE_INSENSITIVE);
- final MatcherWrapper matcherHours = new MatcherWrapper(fullHours, getDescription());
- if (matcherHours.find()) {
+ // 17 - 20 o'clock
+ patterns.add(Pattern.compile("\\b(\\d{1,2})(?:\\.00)?" + "\\s*-\\s*" + "(?:\\d{1,2})(?:\\.00)?" + "\\s+" + Pattern.quote(hourLocalized), Pattern.CASE_INSENSITIVE));
+ // 12 o'clock, 12.00 o'clock
+ patterns.add(Pattern.compile("\\b(\\d{1,2})(?:\\.00)?\\s+" + Pattern.quote(hourLocalized), Pattern.CASE_INSENSITIVE));
+ }
+
+ for (Pattern pattern : patterns) {
+ final MatcherWrapper matcher = new MatcherWrapper(pattern, getDescription());
+ while (matcher.find()) {
try {
- final int hours = Integer.valueOf(matcherHours.group(1));
- if (hours >= 0 && hours < 24) {
- return String.valueOf(hours * 60);
+ final int hours = Integer.valueOf(matcher.group(1));
+ int minutes = 0;
+ if (matcher.groupCount() >= 2) {
+ minutes = Integer.valueOf(matcher.group(2));
+ }
+ if (hours >= 0 && hours < 24 && minutes >= 0 && minutes < 60) {
+ return String.valueOf(hours * 60 + minutes);
}
} catch (final NumberFormatException e) {
// cannot happen, but static code analysis doesn't know
@@ -1735,7 +1711,7 @@ public class Geocache implements ICache, IWaypoint {
* @return
*/
public boolean hasAttribute(CacheAttribute attribute, boolean yes) {
- Geocache fullCache = cgData.loadCache(getGeocode(), EnumSet.of(LoadFlag.LOAD_ATTRIBUTES));
+ Geocache fullCache = DataStore.loadCache(getGeocode(), EnumSet.of(LoadFlag.LOAD_ATTRIBUTES));
if (fullCache == null) {
fullCache = this;
}
@@ -1746,6 +1722,13 @@ public class Geocache implements ICache, IWaypoint {
return StaticMapsProvider.hasStaticMap(this);
}
+ public static final Predicate<Geocache> hasStaticMap = new Predicate<Geocache>() {
+ @Override
+ public boolean evaluate(final Geocache cache) {
+ return cache.hasStaticMap();
+ }
+ };
+
public List<Image> getImages() {
final List<Image> result = new ArrayList<Image>();
result.addAll(getSpoilers());