diff options
Diffstat (limited to 'main/src/cgeo/geocaching/Geocache.java')
| -rw-r--r-- | main/src/cgeo/geocaching/Geocache.java | 138 |
1 files changed, 79 insertions, 59 deletions
diff --git a/main/src/cgeo/geocaching/Geocache.java b/main/src/cgeo/geocaching/Geocache.java index 3c69197..f229af8 100644 --- a/main/src/cgeo/geocaching/Geocache.java +++ b/main/src/cgeo/geocaching/Geocache.java @@ -32,6 +32,7 @@ import cgeo.geocaching.utils.LogTemplateProvider.LogContext; import cgeo.geocaching.utils.MatcherWrapper; import org.apache.commons.collections.CollectionUtils; +import org.apache.commons.lang3.ObjectUtils; import org.apache.commons.lang3.StringUtils; import android.app.Activity; @@ -95,17 +96,18 @@ public class Geocache implements ICache, IWaypoint { * lazy initialized */ private String description = null; - private boolean disabled = false; - private boolean archived = false; - private boolean premiumMembersOnly = false; - private boolean found = false; - private boolean favorite = false; + private Boolean disabled = null; + private Boolean archived = null; + private Boolean premiumMembersOnly = null; + private Boolean found = null; + private Boolean favorite = null; + private Boolean onWatchlist = null; + private Boolean logOffline = null; private int favoritePoints = 0; private float rating = 0; // valid ratings are larger than zero private int votes = 0; private float myVote = 0; // valid ratings are larger than zero private int inventoryItems = 0; - private boolean onWatchlist = false; private final List<String> attributes = new LazyInitializedList<String>() { @Override public List<String> call() { @@ -127,7 +129,6 @@ public class Geocache implements ICache, IWaypoint { }; private List<Trackable> inventory = null; private Map<LogType, Integer> logCounts = new HashMap<LogType, Integer>(); - private boolean logOffline = false; private boolean userModifiedCoords = false; // temporary values private boolean statusChecked = false; @@ -136,7 +137,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_MAX + 1; + private int zoomlevel = Tile.ZOOMLEVEL_MIN - 1; private static final Pattern NUMBER_PATTERN = Pattern.compile("\\d+"); @@ -196,34 +197,37 @@ public class Geocache implements ICache, IWaypoint { detailed = other.detailed; detailedUpdate = other.detailedUpdate; coords = other.coords; - cacheType = other.cacheType; + // 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 - // 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; + finalDefined = other.finalDefined; + } + + if (premiumMembersOnly == null) { + premiumMembersOnly = other.premiumMembersOnly; + } + if (found == null) { found = other.found; + } + if (disabled == null) { disabled = other.disabled; + } + if (favorite == null) { favorite = other.favorite; + } + if (archived == null) { + archived = other.archived; + } + if (onWatchlist == null) { onWatchlist = other.onWatchlist; + } + if (logOffline == null) { logOffline = other.logOffline; - finalDefined = other.finalDefined; - archived = other.archived; } - - /* - * No gathering for boolean members if other cache is not-detailed - * and does not have information with higher reliability (denoted by zoomlevel) - * - found - * - own - * - disabled - * - favorite - * - onWatchlist - * - logOffline - */ if (visitedDate == 0) { visitedDate = other.visitedDate; } @@ -374,14 +378,14 @@ public class Geocache implements ICache, IWaypoint { StringUtils.equalsIgnoreCase(name, other.name) && cacheType == other.cacheType && size == other.size && - found == other.found && - premiumMembersOnly == other.premiumMembersOnly && + ObjectUtils.equals(found, other.found) && + ObjectUtils.equals(premiumMembersOnly, other.premiumMembersOnly) && difficulty == other.difficulty && terrain == other.terrain && (coords != null ? coords.equals(other.coords) : null == other.coords) && reliableLatLon == other.reliableLatLon && - disabled == other.disabled && - archived == other.archived && + ObjectUtils.equals(disabled, other.disabled) && + ObjectUtils.equals(archived, other.archived) && listId == other.listId && StringUtils.equalsIgnoreCase(ownerDisplayName, other.ownerDisplayName) && StringUtils.equalsIgnoreCase(ownerUserId, other.ownerUserId) && @@ -389,9 +393,9 @@ public class Geocache implements ICache, IWaypoint { StringUtils.equalsIgnoreCase(personalNote, other.personalNote) && StringUtils.equalsIgnoreCase(getShortDescription(), other.getShortDescription()) && StringUtils.equalsIgnoreCase(getLocation(), other.getLocation()) && - favorite == other.favorite && + ObjectUtils.equals(favorite, other.favorite) && favoritePoints == other.favoritePoints && - onWatchlist == other.onWatchlist && + ObjectUtils.equals(onWatchlist, other.onWatchlist) && (hidden != null ? hidden.equals(other.hidden) : null == other.hidden) && StringUtils.equalsIgnoreCase(guid, other.guid) && StringUtils.equalsIgnoreCase(getHint(), other.getHint()) && @@ -408,7 +412,7 @@ public class Geocache implements ICache, IWaypoint { logs == other.logs && inventory == other.inventory && logCounts == other.logCounts && - logOffline == other.logOffline && + ObjectUtils.equals(logOffline, other.logOffline) && finalDefined == other.finalDefined; } @@ -483,7 +487,7 @@ public class Geocache implements ICache, IWaypoint { if (status) { ActivityMixin.showToast(fromActivity, res.getString(R.string.info_log_saved)); cgData.saveVisitDate(geocode); - logOffline = true; + logOffline = Boolean.TRUE; notifyChange(); } else { @@ -610,21 +614,21 @@ public class Geocache implements ICache, IWaypoint { @Override public boolean isArchived() { - return archived; + return (archived != null && archived.booleanValue()); } @Override public boolean isDisabled() { - return disabled; + return (disabled != null && disabled.booleanValue()); } @Override public boolean isPremiumMembersOnly() { - return premiumMembersOnly; + return (premiumMembersOnly != null && premiumMembersOnly.booleanValue()); } public void setPremiumMembersOnly(boolean members) { - this.premiumMembersOnly = members; + this.premiumMembersOnly = Boolean.valueOf(members); } @Override @@ -775,16 +779,16 @@ public class Geocache implements ICache, IWaypoint { @Override public boolean isFound() { - return found; + return (found != null && found.booleanValue()); } @Override public boolean isFavorite() { - return favorite; + return (favorite != null && favorite.booleanValue()); } public void setFavorite(boolean favorite) { - this.favorite = favorite; + this.favorite = Boolean.valueOf(favorite); } @Override @@ -830,12 +834,15 @@ public class Geocache implements ICache, IWaypoint { @Override public String getNameForSorting() { if (null == nameForSorting) { - final MatcherWrapper matcher = new MatcherWrapper(NUMBER_PATTERN, name); - if (matcher.find()) { - nameForSorting = name.replace(matcher.group(), StringUtils.leftPad(matcher.group(), 6, '0')); - } - else { - nameForSorting = name; + nameForSorting = name; + // pad each number part to a fixed size of 6 digits, so that numerical sorting becomes equivalent to string sorting + MatcherWrapper matcher = new MatcherWrapper(NUMBER_PATTERN, nameForSorting); + int start = 0; + while (matcher.find(start)) { + final String number = matcher.group(); + nameForSorting = StringUtils.substring(nameForSorting, 0, matcher.start()) + StringUtils.leftPad(number, 6, '0') + StringUtils.substring(nameForSorting, matcher.start() + number.length()); + start = matcher.start() + Math.max(6, number.length()); + matcher = new MatcherWrapper(NUMBER_PATTERN, nameForSorting); } } return nameForSorting; @@ -919,8 +926,25 @@ public class Geocache implements ICache, IWaypoint { return coords; } + /** + * Set reliable coordinates + * + * @param coords + */ public void setCoords(Geopoint coords) { this.coords = coords; + this.zoomlevel = Tile.ZOOMLEVEL_MAX + 1; + } + + /** + * Set unreliable coordinates from a certain map zoom level + * + * @param coords + * @param zoomlevel + */ + public void setCoords(Geopoint coords, int zoomlevel) { + this.coords = coords; + this.zoomlevel = zoomlevel; } /** @@ -976,11 +1000,11 @@ public class Geocache implements ICache, IWaypoint { @Override public boolean isOnWatchlist() { - return onWatchlist; + return (onWatchlist != null && onWatchlist.booleanValue()); } public void setOnWatchlist(boolean onWatchlist) { - this.onWatchlist = onWatchlist; + this.onWatchlist = Boolean.valueOf(onWatchlist); } /** @@ -1049,11 +1073,11 @@ public class Geocache implements ICache, IWaypoint { } public boolean isLogOffline() { - return logOffline; + return (logOffline != null && logOffline.booleanValue()); } public void setLogOffline(boolean logOffline) { - this.logOffline = logOffline; + this.logOffline = Boolean.valueOf(logOffline); } public boolean isStatusChecked() { @@ -1126,15 +1150,15 @@ public class Geocache implements ICache, IWaypoint { } public void setDisabled(boolean disabled) { - this.disabled = disabled; + this.disabled = Boolean.valueOf(disabled); } public void setArchived(boolean archived) { - this.archived = archived; + this.archived = Boolean.valueOf(archived); } public void setFound(boolean found) { - this.found = found; + this.found = Boolean.valueOf(found); } public void setAttributes(List<String> attributes) { @@ -1477,10 +1501,6 @@ public class Geocache implements ICache, IWaypoint { return this.zoomlevel; } - public void setZoomlevel(int zoomlevel) { - this.zoomlevel = zoomlevel; - } - @Override public int getId() { return 0; |
