diff options
Diffstat (limited to 'main/src/cgeo/geocaching/cgCache.java')
| -rw-r--r-- | main/src/cgeo/geocaching/cgCache.java | 260 |
1 files changed, 139 insertions, 121 deletions
diff --git a/main/src/cgeo/geocaching/cgCache.java b/main/src/cgeo/geocaching/cgCache.java index 7035d65..24bd66b 100644 --- a/main/src/cgeo/geocaching/cgCache.java +++ b/main/src/cgeo/geocaching/cgCache.java @@ -11,6 +11,7 @@ import cgeo.geocaching.connector.gc.GCConnector; import cgeo.geocaching.connector.gc.GCConstants; import cgeo.geocaching.connector.gc.Tile; import cgeo.geocaching.enumerations.CacheAttribute; +import cgeo.geocaching.enumerations.CacheRealm; import cgeo.geocaching.enumerations.CacheSize; import cgeo.geocaching.enumerations.CacheType; import cgeo.geocaching.enumerations.LoadFlags; @@ -27,6 +28,7 @@ import cgeo.geocaching.utils.LazyInitializedList; import cgeo.geocaching.utils.Log; import cgeo.geocaching.utils.LogTemplateProvider; import cgeo.geocaching.utils.LogTemplateProvider.LogContext; +import cgeo.geocaching.utils.MatcherWrapper; import org.apache.commons.collections.CollectionUtils; import org.apache.commons.lang3.StringUtils; @@ -38,7 +40,6 @@ import android.net.Uri; import android.os.Handler; import android.os.Message; import android.text.Html; -import android.text.Spannable; import java.util.ArrayList; import java.util.Calendar; @@ -48,7 +49,6 @@ import java.util.EnumSet; import java.util.HashMap; import java.util.List; import java.util.Map; -import java.util.regex.Matcher; import java.util.regex.Pattern; /** @@ -66,7 +66,6 @@ public class cgCache implements ICache, IWaypoint { private String guid = ""; private CacheType cacheType = CacheType.UNKNOWN; private String name = ""; - private Spannable nameSp = null; private String ownerDisplayName = ""; private String ownerUserId = ""; private Date hidden = null; @@ -99,23 +98,23 @@ public class cgCache implements ICache, IWaypoint { private LazyInitializedList<String> attributes = new LazyInitializedList<String>() { @Override protected List<String> loadFromDatabase() { - return cgeoapplication.getInstance().loadAttributes(geocode); + return cgData.loadAttributes(geocode); } }; - private LazyInitializedList<cgWaypoint> waypoints = new LazyInitializedList<cgWaypoint>() { + private LazyInitializedList<Waypoint> waypoints = new LazyInitializedList<Waypoint>() { @Override - protected List<cgWaypoint> loadFromDatabase() { - return cgeoapplication.getInstance().loadWaypoints(geocode); + protected List<Waypoint> loadFromDatabase() { + return cgData.loadWaypoints(geocode); } }; - private List<cgImage> spoilers = null; + private List<Image> spoilers = null; private LazyInitializedList<LogEntry> logs = new LazyInitializedList<LogEntry>() { @Override protected List<LogEntry> loadFromDatabase() { - return cgeoapplication.getInstance().loadLogs(geocode); + return cgData.loadLogs(geocode); } }; - private List<cgTrackable> inventory = null; + private List<Trackable> inventory = null; private Map<LogType, Integer> logCounts = new HashMap<LogType, Integer>(); private boolean logOffline = false; private boolean userModifiedCoords = false; @@ -147,7 +146,7 @@ public class cgCache implements ICache, IWaypoint { public cgCache(GPXParser gpxParser) { setReliableLatLon(true); setAttributes(Collections.<String> emptyList()); - setWaypoints(Collections.<cgWaypoint> emptyList(), false); + setWaypoints(Collections.<Waypoint> emptyList(), false); setLogs(Collections.<LogEntry> emptyList()); } @@ -227,9 +226,6 @@ public class cgCache implements ICache, IWaypoint { if (StringUtils.isBlank(name)) { name = other.name; } - if (StringUtils.isBlank(nameSp)) { - nameSp = other.nameSp; - } if (StringUtils.isBlank(ownerDisplayName)) { ownerDisplayName = other.ownerDisplayName; } @@ -278,6 +274,8 @@ public class cgCache implements ICache, IWaypoint { if (StringUtils.isBlank(description)) { description = other.description; } + // FIXME: this makes no sense to favor this over the other. 0 should not be a special case here as it is + // in the range of acceptable values. This is probably the case at other places (rating, votes, etc.) too. if (favoritePoints == 0) { favoritePoints = other.favoritePoints; } @@ -294,12 +292,12 @@ public class cgCache implements ICache, IWaypoint { attributes.set(other.attributes); } if (waypoints.isEmpty()) { - waypoints.set(other.waypoints); + this.setWaypoints(other.waypoints.asList(), false); } else { - ArrayList<cgWaypoint> newPoints = new ArrayList<cgWaypoint>(waypoints.asList()); - cgWaypoint.mergeWayPoints(newPoints, other.getWaypoints(), false); - waypoints.set(newPoints); + ArrayList<Waypoint> newPoints = new ArrayList<Waypoint>(waypoints.asList()); + Waypoint.mergeWayPoints(newPoints, other.waypoints.asList(), false); + this.setWaypoints(newPoints, false); } if (spoilers == null) { spoilers = other.spoilers; @@ -315,12 +313,21 @@ public class cgCache implements ICache, IWaypoint { if (logs.isEmpty()) { // keep last known logs if none logs.set(other.logs); } - if (logCounts.size() == 0) { + if (logCounts.isEmpty()) { logCounts = other.logCounts; } - if (!userModifiedCoords) { - userModifiedCoords = other.userModifiedCoords; + + // if cache has ORIGINAL type waypoint ... it is considered that it has modified coordinates, otherwise not + userModifiedCoords = false; + if (waypoints != null) { + for (Waypoint wpt : waypoints) { + if (wpt.getWaypointType() == WaypointType.ORIGINAL) { + userModifiedCoords = true; + break; + } + } } + if (!reliableLatLon) { reliableLatLon = other.reliableLatLon; } @@ -328,19 +335,14 @@ public class cgCache implements ICache, IWaypoint { zoomlevel = other.zoomlevel; } - boolean isEqual = isEqualTo(other); - - if (!isEqual) { - notifyChange(); - } - - return isEqual; + return isEqualTo(other); } /** * Compare two caches quickly. For map and list fields only the references are compared ! * - * @param other the other cache to compare this one to + * @param other + * the other cache to compare this one to * @return true if both caches have the same content */ private boolean isEqualTo(final cgCache other) { @@ -376,7 +378,6 @@ public class cgCache implements ICache, IWaypoint { (direction != null ? direction.equals(other.direction) : null == other.direction) && (distance != null ? distance.equals(other.distance) : null == other.distance) && (elevation != null ? elevation.equals(other.elevation) : null == other.elevation) && - nameSp == other.nameSp && rating == other.rating && votes == other.votes && myVote == other.myVote && @@ -441,8 +442,7 @@ public class cgCache implements ICache, IWaypoint { } Intent logVisitIntent = new Intent((Activity) fromActivity, VisitCacheActivity.class); logVisitIntent.putExtra(VisitCacheActivity.EXTRAS_ID, cacheId); - logVisitIntent.putExtra(VisitCacheActivity.EXTRAS_GEOCODE, geocode.toUpperCase()); - logVisitIntent.putExtra(VisitCacheActivity.EXTRAS_FOUND, found); + logVisitIntent.putExtra(VisitCacheActivity.EXTRAS_GEOCODE, geocode); ((Activity) fromActivity).startActivity(logVisitIntent); } @@ -457,13 +457,12 @@ public class cgCache implements ICache, IWaypoint { if (logType == LogType.UNKNOWN) { return; } - cgeoapplication app = (cgeoapplication) fromActivity.getApplication(); - final boolean status = app.saveLogOffline(geocode, date.getTime(), logType, log); + final boolean status = cgData.saveLogOffline(geocode, date.getTime(), logType, log); Resources res = fromActivity.getResources(); if (status) { ActivityMixin.showToast(fromActivity, res.getString(R.string.info_log_saved)); - app.saveVisitDate(geocode); + cgData.saveVisitDate(geocode); logOffline = true; notifyChange(); @@ -538,6 +537,14 @@ public class cgCache implements ICache, IWaypoint { return getConnector().supportsLogging(); } + public boolean supportsOwnCoordinates() { + return getConnector().supportsOwnCoordinates(); + } + + public CacheRealm getCacheRealm() { + return getConnector().getCacheRealm(); + } + @Override public float getDifficulty() { return difficulty; @@ -603,7 +610,7 @@ public class cgCache implements ICache, IWaypoint { @Override public String getDescription() { if (description == null) { - description = StringUtils.defaultString(cgeoapplication.getInstance().getCacheDescription(geocode)); + description = StringUtils.defaultString(cgData.getCacheDescription(geocode)); } return description; } @@ -661,7 +668,7 @@ public class cgCache implements ICache, IWaypoint { } StringBuilder subject = new StringBuilder("Geocache "); - subject.append(geocode.toUpperCase()); + subject.append(geocode); if (StringUtils.isNotBlank(name)) { subject.append(" - ").append(name); } @@ -700,7 +707,6 @@ public class cgCache implements ICache, IWaypoint { this.favorite = favourite; } - @Override public boolean isWatchlist() { return onWatchlist; @@ -717,19 +723,19 @@ public class cgCache implements ICache, IWaypoint { } @Override - public List<cgTrackable> getInventory() { + public List<Trackable> getInventory() { return inventory; } - public void addSpoiler(final cgImage spoiler) { + public void addSpoiler(final Image spoiler) { if (spoilers == null) { - spoilers = new ArrayList<cgImage>(); + spoilers = new ArrayList<Image>(); } spoilers.add(spoiler); } @Override - public List<cgImage> getSpoilers() { + public List<Image> getSpoilers() { if (spoilers == null) { return Collections.emptyList(); } @@ -749,7 +755,7 @@ public class cgCache implements ICache, IWaypoint { @Override public String getNameForSorting() { if (null == nameForSorting) { - final Matcher matcher = NUMBER_PATTERN.matcher(name); + final MatcherWrapper matcher = new MatcherWrapper(NUMBER_PATTERN, name); if (matcher.find()) { nameForSorting = name.replace(matcher.group(), StringUtils.leftPad(matcher.group(), 6, '0')); } @@ -809,14 +815,6 @@ public class cgCache implements ICache, IWaypoint { this.detailed = detailed; } - public Spannable getNameSp() { - return nameSp; - } - - public void setNameSp(Spannable nameSp) { - this.nameSp = nameSp; - } - public void setHidden(final Date hidden) { if (hidden == null) { this.hidden = null; @@ -935,7 +933,7 @@ public class cgCache implements ICache, IWaypoint { * * @return always non <code>null</code> */ - public List<cgWaypoint> getWaypoints() { + public List<Waypoint> getWaypoints() { return waypoints.asList(); } @@ -947,19 +945,18 @@ public class cgCache implements ICache, IWaypoint { * called while loading or building a cache * @return <code>true</code> if waypoints successfully added to waypoint database */ - public boolean setWaypoints(List<cgWaypoint> waypoints, boolean saveToDatabase) { + public boolean setWaypoints(List<Waypoint> waypoints, boolean saveToDatabase) { this.waypoints.set(waypoints); finalDefined = false; if (waypoints != null) { - for (cgWaypoint waypoint : waypoints) { + for (Waypoint waypoint : waypoints) { waypoint.setGeocode(geocode); if (waypoint.isFinalWithCoords()) { finalDefined = true; } } } - - return saveToDatabase && cgeoapplication.getInstance().saveWaypoints(this); + return saveToDatabase && cgData.saveWaypoints(this); } /** @@ -1015,7 +1012,7 @@ public class cgCache implements ICache, IWaypoint { } public void setGeocode(String geocode) { - this.geocode = geocode; + this.geocode = StringUtils.upperCase(geocode); } public void setCacheId(String cacheId) { @@ -1087,11 +1084,11 @@ public class cgCache implements ICache, IWaypoint { this.attributes.set(attributes); } - public void setSpoilers(List<cgImage> spoilers) { + public void setSpoilers(List<Image> spoilers) { this.spoilers = spoilers; } - public void setInventory(List<cgTrackable> inventory) { + public void setInventory(List<Trackable> inventory) { this.inventory = inventory; } @@ -1149,7 +1146,7 @@ public class cgCache implements ICache, IWaypoint { * called while loading or building a cache * @return <code>true</code> if waypoint successfully added to waypoint database */ - public boolean addOrChangeWaypoint(final cgWaypoint waypoint, boolean saveToDatabase) { + public boolean addOrChangeWaypoint(final Waypoint waypoint, boolean saveToDatabase) { waypoint.setGeocode(geocode); if (waypoint.getId() <= 0) { // this is a new waypoint @@ -1166,8 +1163,7 @@ public class cgCache implements ICache, IWaypoint { // when waypoint was edited, finalDefined may have changed resetFinalDefined(); } - - return saveToDatabase && cgeoapplication.getInstance().saveWaypoint(waypoint.getId(), geocode, waypoint); + return saveToDatabase && cgData.saveWaypoint(waypoint.getId(), geocode, waypoint); } public boolean hasWaypoints() { @@ -1188,7 +1184,7 @@ public class cgCache implements ICache, IWaypoint { */ private void resetFinalDefined() { finalDefined = false; - for (cgWaypoint wp : waypoints) { + for (Waypoint wp : waypoints) { if (wp.isFinalWithCoords()) { finalDefined = true; break; @@ -1201,43 +1197,47 @@ public class cgCache implements ICache, IWaypoint { } public void setUserModifiedCoords(boolean coordsChanged) { - this.userModifiedCoords = coordsChanged; + userModifiedCoords = coordsChanged; } /** * Duplicate a waypoint. * - * @param index the waypoint to duplicate + * @param original + * the waypoint to duplicate * @return <code>true</code> if the waypoint was duplicated, <code>false</code> otherwise (invalid index) */ - public boolean duplicateWaypoint(final int index) { - final cgWaypoint original = getWaypoint(index); + public boolean duplicateWaypoint(final Waypoint original) { if (original == null) { return false; } - final cgWaypoint copy = new cgWaypoint(original); + 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()); waypoints.add(index + 1, copy); - return cgeoapplication.getInstance().saveWaypoint(-1, geocode, copy); + return cgData.saveWaypoint(-1, geocode, copy); } /** * delete a user defined waypoint * - * @param index - * of the waypoint in cache's waypoint list + * @param waypoint + * to be removed from cache * @return <code>true</code>, if the waypoint was deleted */ - public boolean deleteWaypoint(final int index) { - final cgWaypoint waypoint = getWaypoint(index); + public boolean deleteWaypoint(final Waypoint waypoint) { if (waypoint == null) { return false; } + if (waypoint.getId() <= 0) { + return false; + } if (waypoint.isUserDefined()) { + final int index = getWaypointIndex(waypoint); waypoints.remove(index); - cgeoapplication.getInstance().deleteWaypoint(waypoint.getId()); - cgeoapplication.getInstance().removeCache(geocode, EnumSet.of(RemoveFlag.REMOVE_CACHE)); + cgData.deleteWaypoint(waypoint.getId()); + cgData.removeCache(geocode, EnumSet.of(RemoveFlag.REMOVE_CACHE)); // Check status if Final is defined if (waypoint.isFinalWithCoords()) { resetFinalDefined(); @@ -1248,19 +1248,17 @@ public class cgCache implements ICache, IWaypoint { } /** - * delete a user defined waypoint + * deletes any waypoint * * @param waypoint - * to be removed from cache - * @return <code>true</code>, if the waypoint was deleted */ - public boolean deleteWaypoint(final cgWaypoint waypoint) { - if (waypoint.getId() <= 0) { - return false; - } + public void deleteWaypointForce(Waypoint waypoint) { final int index = getWaypointIndex(waypoint); - return index >= 0 && deleteWaypoint(index); + waypoints.remove(index); + cgData.deleteWaypoint(waypoint.getId()); + cgData.removeCache(geocode, EnumSet.of(RemoveFlag.REMOVE_CACHE)); + resetFinalDefined(); } /** @@ -1270,7 +1268,7 @@ public class cgCache implements ICache, IWaypoint { * to find index for * @return index in <code>waypoints</code> if found, -1 otherwise */ - private int getWaypointIndex(final cgWaypoint waypoint) { + private int getWaypointIndex(final Waypoint waypoint) { final int id = waypoint.getId(); for (int index = 0; index < waypoints.size(); index++) { if (waypoints.get(index).getId() == id) { @@ -1283,21 +1281,23 @@ public class cgCache implements ICache, IWaypoint { /** * Retrieve a given waypoint. * - * @param index the index of the waypoint + * @param index + * the index of the waypoint * @return waypoint or <code>null</code> if index is out of range */ - public cgWaypoint getWaypoint(final int index) { + public Waypoint getWaypoint(final int index) { return index >= 0 && index < waypoints.size() ? waypoints.get(index) : null; } /** * Lookup a waypoint by its id. * - * @param id the id of the waypoint to look for + * @param id + * the id of the waypoint to look for * @return waypoint or <code>null</code> */ - public cgWaypoint getWaypointById(final int id) { - for (final cgWaypoint waypoint : waypoints) { + public Waypoint getWaypointById(final int id) { + for (final Waypoint waypoint : waypoints) { if (waypoint.getId() == id) { return waypoint; } @@ -1313,14 +1313,14 @@ public class cgCache implements ICache, IWaypoint { final Pattern coordPattern = Pattern.compile("\\b[nNsS]{1}\\s*\\d"); // begin of coordinates int count = 1; String note = getPersonalNote(); - Matcher matcher = coordPattern.matcher(note); + MatcherWrapper matcher = new MatcherWrapper(coordPattern, note); while (matcher.find()) { try { final Geopoint point = new Geopoint(note.substring(matcher.start())); // coords must have non zero latitude and longitude and at least one part shall have fractional degrees if (point.getLatitudeE6() != 0 && point.getLongitudeE6() != 0 && ((point.getLatitudeE6() % 1000) != 0 || (point.getLongitudeE6() % 1000) != 0)) { final String name = cgeoapplication.getInstance().getString(R.string.cache_personal_note) + " " + count; - final cgWaypoint waypoint = new cgWaypoint(name, WaypointType.WAYPOINT, false); + final Waypoint waypoint = new Waypoint(name, WaypointType.WAYPOINT, false); waypoint.setCoords(point); addOrChangeWaypoint(waypoint, false); count++; @@ -1330,10 +1330,10 @@ public class cgCache implements ICache, IWaypoint { } note = note.substring(matcher.start() + 1); - matcher = coordPattern.matcher(note); + matcher = new MatcherWrapper(coordPattern, note); } } catch (Exception e) { - Log.e("cgCache.parseWaypointsFromNote: " + e.toString()); + Log.e("cgCache.parseWaypointsFromNote", e); } } @@ -1391,8 +1391,8 @@ public class cgCache implements ICache, IWaypoint { public void drop(Handler handler) { try { - cgeoapplication.getInstance().markDropped(Collections.singletonList(this)); - cgeoapplication.getInstance().removeCache(getGeocode(), EnumSet.of(RemoveFlag.REMOVE_CACHE)); + cgData.markDropped(Collections.singletonList(this)); + cgData.removeCache(getGeocode(), EnumSet.of(RemoveFlag.REMOVE_CACHE)); handler.sendMessage(Message.obtain()); } catch (Exception e) { @@ -1402,48 +1402,48 @@ public class cgCache implements ICache, IWaypoint { public void checkFields() { if (StringUtils.isBlank(getGeocode())) { - Log.e("geo code not parsed correctly"); + Log.w("geo code not parsed correctly for " + geocode); } if (StringUtils.isBlank(getName())) { - Log.e("name not parsed correctly"); + Log.w("name not parsed correctly for " + geocode); } if (StringUtils.isBlank(getGuid())) { - Log.e("guid not parsed correctly"); + Log.w("guid not parsed correctly for " + geocode); } if (getTerrain() == 0.0) { - Log.e("terrain not parsed correctly"); + Log.w("terrain not parsed correctly for " + geocode); } if (getDifficulty() == 0.0) { - Log.e("difficulty not parsed correctly"); + Log.w("difficulty not parsed correctly for " + geocode); } if (StringUtils.isBlank(getOwnerDisplayName())) { - Log.e("owner display name not parsed correctly"); + Log.w("owner display name not parsed correctly for " + geocode); } if (StringUtils.isBlank(getOwnerUserId())) { - Log.e("owner user id real not parsed correctly"); + Log.w("owner user id real not parsed correctly for " + geocode); } if (getHiddenDate() == null) { - Log.e("hidden not parsed correctly"); + Log.w("hidden not parsed correctly for " + geocode); } if (getFavoritePoints() < 0) { - Log.e("favoriteCount not parsed correctly"); + Log.w("favoriteCount not parsed correctly for " + geocode); } if (getSize() == null) { - Log.e("size not parsed correctly"); + Log.w("size not parsed correctly for " + geocode); } if (getType() == null || getType() == CacheType.UNKNOWN) { - Log.e("type not parsed correctly"); + Log.w("type not parsed correctly for " + geocode); } if (getCoords() == null) { - Log.e("coordinates not parsed correctly"); + Log.w("coordinates not parsed correctly for " + geocode); } if (StringUtils.isBlank(getLocation())) { - Log.e("location not parsed correctly"); + Log.w("location not parsed correctly for " + geocode); } } public void refresh(int newListId, CancellableHandler handler) { - cgeoapplication.getInstance().removeCache(geocode, EnumSet.of(RemoveFlag.REMOVE_CACHE)); + cgData.removeCache(geocode, EnumSet.of(RemoveFlag.REMOVE_CACHE)); storeCache(null, geocode, newListId, true, handler); } @@ -1491,7 +1491,7 @@ public class cgCache implements ICache, IWaypoint { // store spoilers if (CollectionUtils.isNotEmpty(cache.getSpoilers())) { - for (cgImage oneSpoiler : cache.getSpoilers()) { + for (Image oneSpoiler : cache.getSpoilers()) { imgGetter.getDrawable(oneSpoiler.getUrl()); } } @@ -1504,7 +1504,7 @@ public class cgCache implements ICache, IWaypoint { if (Settings.isStoreLogImages()) { for (LogEntry log : cache.getLogs()) { if (log.hasLogImages()) { - for (cgImage oneLogImg : log.getLogImages()) { + for (Image oneLogImg : log.getLogImages()) { imgGetter.getDrawable(oneLogImg.getUrl()); } } @@ -1516,7 +1516,7 @@ public class cgCache implements ICache, IWaypoint { } cache.setListId(listId); - cgeoapplication.getInstance().saveCache(cache, EnumSet.of(SaveFlag.SAVE_DB)); + cgData.saveCache(cache, EnumSet.of(SaveFlag.SAVE_DB)); if (CancellableHandler.isCancelled(handler)) { return; @@ -1538,10 +1538,9 @@ public class cgCache implements ICache, IWaypoint { return null; } - final cgeoapplication app = cgeoapplication.getInstance(); - if (!forceReload && listId == StoredList.TEMPORARY_LIST_ID && (app.isOffline(geocode, guid) || app.isThere(geocode, guid, true, true))) { + if (!forceReload && listId == StoredList.TEMPORARY_LIST_ID && (cgData.isOffline(geocode, guid) || cgData.isThere(geocode, guid, true, true))) { final SearchResult search = new SearchResult(); - final String realGeocode = StringUtils.isNotBlank(geocode) ? geocode : app.getGeocode(guid); + final String realGeocode = StringUtils.isNotBlank(geocode) ? geocode : cgData.getGeocodeForGuid(guid); search.addGeocode(realGeocode); return search; } @@ -1573,7 +1572,7 @@ public class cgCache implements ICache, IWaypoint { } // 12:34 final Pattern time = Pattern.compile("\\b(\\d{1,2})\\:(\\d\\d)\\b"); - final Matcher matcher = time.matcher(getDescription()); + final MatcherWrapper matcher = new MatcherWrapper(time, getDescription()); while (matcher.find()) { try { final int hours = Integer.valueOf(matcher.group(1)); @@ -1589,7 +1588,7 @@ public class cgCache implements ICache, IWaypoint { final String hourLocalized = cgeoapplication.getInstance().getString(R.string.cache_time_full_hours); if (StringUtils.isNotBlank(hourLocalized)) { final Pattern fullHours = Pattern.compile("\\b(\\d{1,2})\\s+" + Pattern.quote(hourLocalized), Pattern.CASE_INSENSITIVE); - final Matcher matcherHours = fullHours.matcher(getDescription()); + final MatcherWrapper matcherHours = new MatcherWrapper(fullHours, getDescription()); if (matcherHours.find()) { try { final int hours = Integer.valueOf(matcherHours.group(1)); @@ -1613,8 +1612,7 @@ public class cgCache implements ICache, IWaypoint { * @return */ public boolean hasAttribute(CacheAttribute attribute, boolean yes) { - // lazy loading of attributes - cgCache fullCache = cgeoapplication.getInstance().loadCache(getGeocode(), EnumSet.of(LoadFlag.LOAD_ATTRIBUTES)); + cgCache fullCache = cgData.loadCache(getGeocode(), EnumSet.of(LoadFlag.LOAD_ATTRIBUTES)); if (fullCache == null) { fullCache = this; } @@ -1625,12 +1623,32 @@ public class cgCache implements ICache, IWaypoint { return StaticMapsProvider.hasStaticMap(this); } - public List<cgImage> getImages() { - List<cgImage> result = new ArrayList<cgImage>(); + public List<Image> getImages() { + List<Image> result = new ArrayList<Image>(); result.addAll(getSpoilers()); for (LogEntry log : getLogs()) { result.addAll(log.getLogImages()); } return result; } + + public void setDetailedUpdatedNow() { + final long now = System.currentTimeMillis(); + setUpdated(now); + setDetailedUpdate(now); + setDetailed(true); + } + + /** + * Gets whether the user has logged the specific log type for this cache. Only checks the currently stored logs of + * the cache, so the result might be wrong. + */ + public boolean hasOwnLog(LogType logType) { + for (LogEntry logEntry : getLogs()) { + if (logEntry.type == logType && logEntry.isOwn()) { + return true; + } + } + return false; + } } |
