aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorrsudev <rasch@munin-soft.de>2013-07-28 12:48:32 +0200
committerrsudev <rasch@munin-soft.de>2013-07-28 13:35:22 +0200
commit77e7e33e8956fa00b6e7f43be6c51177f4b6cf5b (patch)
treeced5745ac67430f885909fcfcaa270584fa31749
parent8abfdd11cb19ddf6f3d3af5ab761e58a853cc465 (diff)
downloadcgeo-77e7e33e8956fa00b6e7f43be6c51177f4b6cf5b.zip
cgeo-77e7e33e8956fa00b6e7f43be6c51177f4b6cf5b.tar.gz
cgeo-77e7e33e8956fa00b6e7f43be6c51177f4b6cf5b.tar.bz2
Finetuning fixes for #1851 and #3000 (cache merging)
-rw-r--r--main/src/cgeo/geocaching/Geocache.java90
-rw-r--r--main/src/cgeo/geocaching/connector/gc/GCMap.java3
-rw-r--r--tests/src/cgeo/geocaching/GeocacheTest.java21
-rw-r--r--tests/src/cgeo/geocaching/cgDataTest.java6
4 files changed, 57 insertions, 63 deletions
diff --git a/main/src/cgeo/geocaching/Geocache.java b/main/src/cgeo/geocaching/Geocache.java
index 23a65c6..77efd7e 100644
--- a/main/src/cgeo/geocaching/Geocache.java
+++ b/main/src/cgeo/geocaching/Geocache.java
@@ -102,6 +102,7 @@ public class Geocache implements ICache, IWaypoint {
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;
@@ -128,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;
@@ -197,46 +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.
- if (other.premiumMembersOnly != null) {
- premiumMembersOnly = other.premiumMembersOnly;
- }
reliableLatLon = other.reliableLatLon;
- if (other.found != null) {
- found = other.found;
- }
- if (other.disabled != null) {
- disabled = other.disabled;
- }
- if (other.favorite != null) {
- favorite = other.favorite;
- }
- if (other.archived != null) {
- archived = other.archived;
- }
- if (other.onWatchlist != null) {
- onWatchlist = other.onWatchlist;
- }
- logOffline = other.logOffline;
finalDefined = other.finalDefined;
}
- /*
- * 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 (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;
+ }
if (visitedDate == 0) {
visitedDate = other.visitedDate;
}
@@ -421,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;
}
@@ -496,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 {
@@ -932,8 +923,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;
}
/**
@@ -1062,11 +1070,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() {
@@ -1490,10 +1498,6 @@ public class Geocache implements ICache, IWaypoint {
return this.zoomlevel;
}
- public void setZoomlevel(int zoomlevel) {
- this.zoomlevel = zoomlevel;
- }
-
@Override
public int getId() {
return 0;
diff --git a/main/src/cgeo/geocaching/connector/gc/GCMap.java b/main/src/cgeo/geocaching/connector/gc/GCMap.java
index d243306..6a602a7 100644
--- a/main/src/cgeo/geocaching/connector/gc/GCMap.java
+++ b/main/src/cgeo/geocaching/connector/gc/GCMap.java
@@ -209,8 +209,7 @@ public class GCMap {
cache.setReliableLatLon(false);
cache.setGeocode(id);
cache.setName(nameCache.get(id));
- cache.setZoomlevel(tile.getZoomlevel());
- cache.setCoords(tile.getCoord(xy));
+ cache.setCoords(tile.getCoord(xy), tile.getZoomlevel());
if (strategy.flags.contains(StrategyFlag.PARSE_TILES) && bitmap != null) {
for (UTFGridPosition singlePos : singlePositions.get(id)) {
if (IconDecoder.parseMapPNG(cache, bitmap, singlePos, tile.getZoomlevel())) {
diff --git a/tests/src/cgeo/geocaching/GeocacheTest.java b/tests/src/cgeo/geocaching/GeocacheTest.java
index aa0a581..4052917 100644
--- a/tests/src/cgeo/geocaching/GeocacheTest.java
+++ b/tests/src/cgeo/geocaching/GeocacheTest.java
@@ -119,8 +119,7 @@ public class GeocacheTest extends AndroidTestCase {
Geocache livemap = new Geocache();
livemap.setGeocode("GC12345");
livemap.setType(CacheType.MULTI);
- livemap.setCoords(new Geopoint(41.0, 9.0));
- livemap.setZoomlevel(12);
+ livemap.setCoords(new Geopoint(41.0, 9.0), 12);
livemap.gatherMissingFrom(stored);
@@ -137,14 +136,12 @@ public class GeocacheTest extends AndroidTestCase {
Geocache livemapFirst = new Geocache();
livemapFirst.setGeocode("GC12345");
livemapFirst.setType(CacheType.TRADITIONAL);
- livemapFirst.setCoords(new Geopoint(40.0, 8.0));
- livemapFirst.setZoomlevel(11);
+ livemapFirst.setCoords(new Geopoint(40.0, 8.0), 11);
Geocache livemapSecond = new Geocache();
livemapSecond.setGeocode("GC12345");
livemapSecond.setType(CacheType.MULTI);
- livemapSecond.setCoords(new Geopoint(41.0, 9.0));
- livemapSecond.setZoomlevel(12);
+ livemapSecond.setCoords(new Geopoint(41.0, 9.0), 12);
livemapSecond.gatherMissingFrom(livemapFirst);
@@ -159,14 +156,12 @@ public class GeocacheTest extends AndroidTestCase {
Geocache livemapFirst = new Geocache();
livemapFirst.setGeocode("GC12345");
livemapFirst.setType(CacheType.TRADITIONAL);
- livemapFirst.setCoords(new Geopoint(40.0, 8.0));
- livemapFirst.setZoomlevel(12);
+ livemapFirst.setCoords(new Geopoint(40.0, 8.0), 12);
Geocache livemapSecond = new Geocache();
livemapSecond.setGeocode("GC12345");
livemapSecond.setType(CacheType.MULTI);
- livemapSecond.setCoords(new Geopoint(41.0, 9.0));
- livemapSecond.setZoomlevel(11);
+ livemapSecond.setCoords(new Geopoint(41.0, 9.0), 11);
livemapSecond.gatherMissingFrom(livemapFirst);
@@ -180,9 +175,8 @@ public class GeocacheTest extends AndroidTestCase {
Geocache livemap = new Geocache();
livemap.setGeocode("GC12345");
- livemap.setCoords(new Geopoint(40.0, 8.0));
+ livemap.setCoords(new Geopoint(40.0, 8.0), 12);
livemap.setFound(true);
- livemap.setZoomlevel(12);
Geocache popup = new Geocache();
popup.setGeocode("GC12345");
@@ -204,8 +198,7 @@ public class GeocacheTest extends AndroidTestCase {
Geocache livemap = new Geocache();
livemap.setGeocode("GC12345");
- livemap.setCoords(new Geopoint(40.0, 8.0));
- livemap.setZoomlevel(12);
+ livemap.setCoords(new Geopoint(40.0, 8.0), 12);
livemap.gatherMissingFrom(bmsearched);
diff --git a/tests/src/cgeo/geocaching/cgDataTest.java b/tests/src/cgeo/geocaching/cgDataTest.java
index e175603..c82053e 100644
--- a/tests/src/cgeo/geocaching/cgDataTest.java
+++ b/tests/src/cgeo/geocaching/cgDataTest.java
@@ -165,8 +165,7 @@ public class cgDataTest extends CGeoTestCase {
main.setCoords(new Geopoint("N49 44.0 E8 37.0"));
final Geocache inTileLowZoom = new Geocache();
inTileLowZoom.setGeocode("GC12346");
- inTileLowZoom.setCoords(new Geopoint("N49 44.001 E8 37.001"));
- inTileLowZoom.setZoomlevel(Tile.ZOOMLEVEL_MIN_PERSONALIZED - 5);
+ inTileLowZoom.setCoords(new Geopoint("N49 44.001 E8 37.001"), Tile.ZOOMLEVEL_MIN_PERSONALIZED - 5);
final Geocache outTile = new Geocache();
outTile.setGeocode("GC12347");
outTile.setCoords(new Geopoint(tile.getViewport().getLatitudeMin() - 0.1, tile.getViewport().getLongitudeMin() - 0.1));
@@ -175,8 +174,7 @@ public class cgDataTest extends CGeoTestCase {
otherConnector.setCoords(new Geopoint("N49 44.0 E8 37.0"));
final Geocache inTileHighZoom = new Geocache();
inTileHighZoom.setGeocode("GC12348");
- inTileHighZoom.setCoords(new Geopoint("N49 44.001 E8 37.001"));
- inTileHighZoom.setZoomlevel(Tile.ZOOMLEVEL_MIN_PERSONALIZED + 1);
+ inTileHighZoom.setCoords(new Geopoint("N49 44.001 E8 37.001"), Tile.ZOOMLEVEL_MIN_PERSONALIZED + 1);
// put in cache
cgData.saveCache(main, EnumSet.of(SaveFlag.SAVE_CACHE));