diff options
Diffstat (limited to 'main/src')
| -rw-r--r-- | main/src/cgeo/geocaching/Geocache.java | 57 | ||||
| -rw-r--r-- | main/src/cgeo/geocaching/cgData.java | 2 | ||||
| -rw-r--r-- | main/src/cgeo/geocaching/connector/gc/GCMap.java | 2 | ||||
| -rw-r--r-- | main/src/cgeo/geocaching/connector/gc/IconDecoder.java | 24 | ||||
| -rw-r--r-- | main/src/cgeo/geocaching/utils/UncertainProperty.java | 39 |
5 files changed, 82 insertions, 42 deletions
diff --git a/main/src/cgeo/geocaching/Geocache.java b/main/src/cgeo/geocaching/Geocache.java index f229af8..3becad0 100644 --- a/main/src/cgeo/geocaching/Geocache.java +++ b/main/src/cgeo/geocaching/Geocache.java @@ -30,6 +30,7 @@ import cgeo.geocaching.utils.Log; import cgeo.geocaching.utils.LogTemplateProvider; 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.lang3.ObjectUtils; @@ -67,7 +68,7 @@ public class Geocache implements ICache, IWaypoint { private String geocode = ""; private String cacheId = ""; private String guid = ""; - private CacheType cacheType = CacheType.UNKNOWN; + private UncertainProperty<CacheType> cacheType = new UncertainProperty<CacheType>(CacheType.UNKNOWN, Tile.ZOOMLEVEL_MIN - 1); private String name = ""; private String ownerDisplayName = ""; private String ownerUserId = ""; @@ -85,7 +86,7 @@ public class Geocache implements ICache, IWaypoint { * lazy initialized */ private String location = null; - private Geopoint coords = null; + private UncertainProperty<Geopoint> coords = new UncertainProperty<Geopoint>(null); private boolean reliableLatLon = false; private String personalNote = null; /** @@ -137,7 +138,7 @@ public class Geocache implements ICache, IWaypoint { private final EnumSet<StorageLocation> storageLocation = EnumSet.of(StorageLocation.HEAP); private boolean finalDefined = false; private boolean logPasswordRequired = false; - private int zoomlevel = Tile.ZOOMLEVEL_MIN - 1; + // private int zoomlevel = Tile.ZOOMLEVEL_MIN - 1; private static final Pattern NUMBER_PATTERN = Pattern.compile("\\d+"); @@ -193,15 +194,9 @@ 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)) { + if (!detailed && other.detailed) { detailed = other.detailed; detailedUpdate = other.detailedUpdate; - coords = other.coords; - // merge cache type only if really available from other - if (null != other.cacheType && CacheType.UNKNOWN != other.cacheType) { - cacheType = other.cacheType; - } - zoomlevel = other.zoomlevel; // boolean values must be enumerated here. Other types are assigned outside this if-statement reliableLatLon = other.reliableLatLon; finalDefined = other.finalDefined; @@ -243,8 +238,10 @@ public class Geocache implements ICache, IWaypoint { if (StringUtils.isBlank(guid)) { guid = other.guid; } - if (null == cacheType || CacheType.UNKNOWN == cacheType) { + if (null == cacheType) { cacheType = other.cacheType; + } else { + cacheType = cacheType.getMergedProperty(other.cacheType); } if (StringUtils.isBlank(name)) { name = other.name; @@ -281,6 +278,8 @@ public class Geocache implements ICache, IWaypoint { } if (coords == null) { coords = other.coords; + } else { + coords = coords.getMergedProperty(other.coords); } // don't use StringUtils.isBlank here. Otherwise we cannot recognize a note which was deleted on GC if (personalNote == null) { @@ -358,9 +357,6 @@ public class Geocache implements ICache, IWaypoint { if (!reliableLatLon) { reliableLatLon = other.reliableLatLon; } - if (zoomlevel == -1) { - zoomlevel = other.zoomlevel; - } return isEqualTo(other); } @@ -456,7 +452,7 @@ public class Geocache implements ICache, IWaypoint { } public boolean isEventCache() { - return cacheType.isEvent(); + return cacheType.getValue().isEvent(); } public void logVisit(final IAbstractActivity fromActivity) { @@ -508,7 +504,7 @@ public class Geocache implements ICache, IWaypoint { if (isOwner()) { logTypes.add(LogType.ANNOUNCEMENT); } - } else if (CacheType.WEBCAM == cacheType) { + } else if (CacheType.WEBCAM == cacheType.getValue()) { logTypes.add(LogType.WEBCAM_PHOTO_TAKEN); } else { logTypes.add(LogType.FOUND_IT); @@ -849,7 +845,7 @@ public class Geocache implements ICache, IWaypoint { } public boolean isVirtual() { - return cacheType.isVirtual(); + return cacheType.getValue().isVirtual(); } public boolean showSize() { @@ -923,7 +919,11 @@ public class Geocache implements ICache, IWaypoint { @Override public Geopoint getCoords() { - return coords; + return coords.getValue(); + } + + public int getCoordZoomLevel() { + return coords.getCertaintyLevel(); } /** @@ -932,8 +932,7 @@ public class Geocache implements ICache, IWaypoint { * @param coords */ public void setCoords(Geopoint coords) { - this.coords = coords; - this.zoomlevel = Tile.ZOOMLEVEL_MAX + 1; + this.coords = new UncertainProperty<Geopoint>(coords); } /** @@ -943,8 +942,7 @@ public class Geocache implements ICache, IWaypoint { * @param zoomlevel */ public void setCoords(Geopoint coords, int zoomlevel) { - this.coords = coords; - this.zoomlevel = zoomlevel; + this.coords = new UncertainProperty<Geopoint>(coords, zoomlevel); } /** @@ -1189,14 +1187,21 @@ public class Geocache implements ICache, IWaypoint { */ @Override public CacheType getType() { - return cacheType; + return cacheType.getValue(); } public void setType(CacheType cacheType) { if (cacheType == null || CacheType.ALL == cacheType) { throw new IllegalArgumentException("Illegal cache type"); } - this.cacheType = cacheType; + this.cacheType = new UncertainProperty<CacheType>(cacheType); + } + + public void setType(CacheType cacheType, final int zoomlevel) { + if (cacheType == null || CacheType.ALL == cacheType) { + throw new IllegalArgumentException("Illegal cache type"); + } + this.cacheType = new UncertainProperty<CacheType>(cacheType, zoomlevel); } public boolean hasDifficulty() { @@ -1497,10 +1502,6 @@ public class Geocache implements ICache, IWaypoint { storeCache(this, null, newListId, false, handler); } - public int getZoomLevel() { - return this.zoomlevel; - } - @Override public int getId() { return 0; diff --git a/main/src/cgeo/geocaching/cgData.java b/main/src/cgeo/geocaching/cgData.java index 785af20..62e6664 100644 --- a/main/src/cgeo/geocaching/cgData.java +++ b/main/src/cgeo/geocaching/cgData.java @@ -2995,7 +2995,7 @@ public class cgData { for (String geocode : cachedGeocodes) { if (connector.canHandle(geocode)) { Geocache geocache = cacheCache.getCacheFromCache(geocode); - if (geocache.getZoomLevel() <= maxZoom) { + if (geocache.getCoordZoomLevel() <= maxZoom) { boolean found = false; for (Tile tile : tiles) { if (tile.containsPoint(geocache)) { diff --git a/main/src/cgeo/geocaching/connector/gc/GCMap.java b/main/src/cgeo/geocaching/connector/gc/GCMap.java index a213742..85873af 100644 --- a/main/src/cgeo/geocaching/connector/gc/GCMap.java +++ b/main/src/cgeo/geocaching/connector/gc/GCMap.java @@ -217,7 +217,7 @@ public class GCMap { } } } else { - cache.setType(CacheType.UNKNOWN); + cache.setType(CacheType.UNKNOWN, tile.getZoomLevel()); } boolean exclude = false; diff --git a/main/src/cgeo/geocaching/connector/gc/IconDecoder.java b/main/src/cgeo/geocaching/connector/gc/IconDecoder.java index ed44392..c7b470a 100644 --- a/main/src/cgeo/geocaching/connector/gc/IconDecoder.java +++ b/main/src/cgeo/geocaching/connector/gc/IconDecoder.java @@ -1,8 +1,8 @@ package cgeo.geocaching.connector.gc; import cgeo.geocaching.Geocache; -import cgeo.geocaching.settings.Settings; import cgeo.geocaching.enumerations.CacheType; +import cgeo.geocaching.settings.Settings; import android.graphics.Bitmap; @@ -87,19 +87,19 @@ public abstract class IconDecoder { if (count > 1) { // 2 pixels need to detect same type and we say good to go switch (type) { case CT_TRADITIONAL: - cache.setType(CacheType.TRADITIONAL); + cache.setType(CacheType.TRADITIONAL, zoomlevel); return true; case CT_MULTI: - cache.setType(CacheType.MULTI); + cache.setType(CacheType.MULTI, zoomlevel); return true; case CT_MYSTERY: - cache.setType(CacheType.MYSTERY); + cache.setType(CacheType.MYSTERY, zoomlevel); return true; case CT_EVENT: - cache.setType(CacheType.EVENT); + cache.setType(CacheType.EVENT, zoomlevel); return true; case CT_EARTH: - cache.setType(CacheType.EARTH); + cache.setType(CacheType.EARTH, zoomlevel); return true; case CT_FOUND: cache.setFound(true); @@ -108,22 +108,22 @@ public abstract class IconDecoder { cache.setOwnerUserId(Settings.getUsername()); return true; case CT_MEGAEVENT: - cache.setType(CacheType.MEGA_EVENT); + cache.setType(CacheType.MEGA_EVENT, zoomlevel); return true; case CT_CITO: - cache.setType(CacheType.CITO); + cache.setType(CacheType.CITO, zoomlevel); return true; case CT_WEBCAM: - cache.setType(CacheType.WEBCAM); + cache.setType(CacheType.WEBCAM, zoomlevel); return true; case CT_WHERIGO: - cache.setType(CacheType.WHERIGO); + cache.setType(CacheType.WHERIGO, zoomlevel); return true; case CT_VIRTUAL: - cache.setType(CacheType.VIRTUAL); + cache.setType(CacheType.VIRTUAL, zoomlevel); return true; case CT_LETTERBOX: - cache.setType(CacheType.LETTERBOX); + cache.setType(CacheType.LETTERBOX, zoomlevel); return true; } } diff --git a/main/src/cgeo/geocaching/utils/UncertainProperty.java b/main/src/cgeo/geocaching/utils/UncertainProperty.java new file mode 100644 index 0000000..2187558 --- /dev/null +++ b/main/src/cgeo/geocaching/utils/UncertainProperty.java @@ -0,0 +1,39 @@ +package cgeo.geocaching.utils; + +import cgeo.geocaching.connector.gc.Tile; + +public class UncertainProperty<T> { + + private final T value; + private final int certaintyLevel; + + public UncertainProperty(T value) { + this.value = value; + this.certaintyLevel = Tile.ZOOMLEVEL_MAX + 1; + } + + public UncertainProperty(T value, int certaintyLevel) { + this.value = value; + this.certaintyLevel = certaintyLevel; + } + + public T getValue() { + return value; + } + + public int getCertaintyLevel() { + return certaintyLevel; + } + + public UncertainProperty<T> getMergedProperty(final UncertainProperty<T> other) { + if (other == null) { + return this; + } + if (other.certaintyLevel > certaintyLevel) { + return other; + } + + return this; + } + +} |
