aboutsummaryrefslogtreecommitdiffstats
path: root/main/src/cgeo/geocaching
diff options
context:
space:
mode:
authorblafoo <github@blafoo.de>2012-02-29 22:36:18 +0100
committerblafoo <github@blafoo.de>2012-02-29 22:36:18 +0100
commit3fde9652fdc7c7285e4aa00a447df2ae4359b8d9 (patch)
tree4023b13efd8bb326ab2332daee9785e5e4ae36fb /main/src/cgeo/geocaching
parentd66464638a5be700b4e54d33cfed65f518031f6d (diff)
downloadcgeo-3fde9652fdc7c7285e4aa00a447df2ae4359b8d9.zip
cgeo-3fde9652fdc7c7285e4aa00a447df2ae4359b8d9.tar.gz
cgeo-3fde9652fdc7c7285e4aa00a447df2ae4359b8d9.tar.bz2
Displaying changed caches in the Live Map. Improves #1184
Diffstat (limited to 'main/src/cgeo/geocaching')
-rw-r--r--main/src/cgeo/geocaching/cgCache.java9
-rw-r--r--main/src/cgeo/geocaching/connector/gc/GCBase.java61
-rw-r--r--main/src/cgeo/geocaching/maps/CGeoMap.java25
-rw-r--r--main/src/cgeo/geocaching/maps/CachesOverlay.java1
4 files changed, 60 insertions, 36 deletions
diff --git a/main/src/cgeo/geocaching/cgCache.java b/main/src/cgeo/geocaching/cgCache.java
index f7d503e..f1f231a 100644
--- a/main/src/cgeo/geocaching/cgCache.java
+++ b/main/src/cgeo/geocaching/cgCache.java
@@ -211,8 +211,12 @@ public class cgCache implements ICache {
location = other.location;
}
if (coords == null) {
- coords = other.getCoords();
+ coords = other.coords;
+ }
+ if (zoomlevel < other.zoomlevel) {
+ coords = other.coords;
}
+
if (elevation == null) {
elevation = other.elevation;
}
@@ -269,6 +273,9 @@ public class cgCache implements ICache {
if (reliableLatLon == false) {
reliableLatLon = other.reliableLatLon;
}
+ if (zoomlevel == -1) {
+ zoomlevel = other.zoomlevel;
+ }
boolean isEqual = isEqualTo(other);
diff --git a/main/src/cgeo/geocaching/connector/gc/GCBase.java b/main/src/cgeo/geocaching/connector/gc/GCBase.java
index 5deafa2..566ef4a 100644
--- a/main/src/cgeo/geocaching/connector/gc/GCBase.java
+++ b/main/src/cgeo/geocaching/connector/gc/GCBase.java
@@ -46,7 +46,6 @@ public class GCBase {
private final static int LIGHT_GREEN = 0x80AF64; // Tradi 13
private final static int DARK_BLUE = 0x243C97; // Mystery
private final static int YELLOW = 0xFFDE19; // Multi 14,13
- private final static int ORANGE = 0xE56200; // Multi
private final static int FOUND = 0xFBEA5D; // Found
// Offset inside cache icon
@@ -59,7 +58,7 @@ public class GCBase {
private final static int POSX_FOUND = 10;
private final static int POSY_FOUND = -8;
- private static final LeastRecentlyUsedCache<String, cgCache> liveMapCache = new LeastRecentlyUsedCache<String, cgCache>(2000); // JSON id, cache
+ private static final LeastRecentlyUsedCache<String, String> geocodeCache = new LeastRecentlyUsedCache<String, String>(2000); // JSON id, geocode
/**
* @param viewport
@@ -107,6 +106,7 @@ public class GCBase {
if (tile.getZoomlevel() != 14) {
url += "&_=" + String.valueOf(System.currentTimeMillis());
}
+ // other types t.b.d
// The PNG must be request before ! Else the following request would return with 204 - No Content
Bitmap bitmap = cgBase.requestMapTile(GCConstants.URL_MAP_TILE + url, referer);
@@ -128,11 +128,9 @@ public class GCBase {
}
}
- if (Settings.isPremiumMember()) {
- SearchResult search = cgBase.searchByCoords(null, viewport.getCenter(), Settings.getCacheType(), StoredList.TEMPORARY_LIST_ID, Settings.isShowCaptcha());
- if (search != null) {
- searchResult.addGeocodes(search.getGeocodes());
- }
+ SearchResult search = cgBase.searchByCoords(null, viewport.getCenter(), Settings.getCacheType(), StoredList.TEMPORARY_LIST_ID, false);
+ if (search != null) {
+ searchResult.addGeocodes(search.getGeocodes());
}
return searchResult;
@@ -151,6 +149,8 @@ public class GCBase {
try {
+ final LeastRecentlyUsedCache<String, String> nameCache = new LeastRecentlyUsedCache<String, String>(2000); // JSON id, cache name
+
if (StringUtils.isEmpty(data)) {
throw new JSONException("No page given");
}
@@ -210,17 +210,7 @@ public class GCBase {
for (int j = 0; j < dataForKey.length(); j++) {
JSONObject cacheInfo = dataForKey.getJSONObject(j);
String id = cacheInfo.getString("i");
- cgCache cache = liveMapCache.get(id);
- if (cache == null) {
- cache = new cgCache();
- cache.setDetailed(false);
- cache.setReliableLatLon(false);
- cache.setGeocode(newidToGeocode(id));
- cache.setName(cacheInfo.getString("n"));
- cache.setZoomlevel(tile.getZoomlevel());
-
- liveMapCache.put(id, cache);
- }
+ nameCache.put(id, cacheInfo.getString("n"));
List<UTFGridPosition> listOfPositions = positions.get(id);
if (listOfPositions == null) {
@@ -238,23 +228,26 @@ public class GCBase {
}
for (String id : positions.keySet()) {
+ String geocode = geocodeCache.get(id);
+ if (geocode == null) {
+ geocode = newidToGeocode(id);
+ geocodeCache.put(id, geocode);
+ }
List<UTFGridPosition> pos = positions.get(id);
- cgCache cache = liveMapCache.get(id);
- if (cache != null) {
- // if we have "better" coords from a previous search -> reuse them
- if (cache.getZoomlevel() < tile.getZoomlevel() ||
- cache.getCoords() == null) {
- UTFGridPosition xy = getPositionInGrid(pos);
- cache.setCoords(tile.getCoord(xy));
- if (tile.getZoomlevel() >= 14) {
- parseMapPNG14(cache, bitmap, xy);
- } else {
- parseMapPNG13(cache, bitmap, xy);
- }
- // Log.d(Settings.tag, "id=" + id + " geocode=" + cache.getGeocode() + " coords=" + cache.getCoords().toString());
- }
- searchResult.addCache(cache);
+ UTFGridPosition xy = getPositionInGrid(pos);
+ cgCache cache = new cgCache();
+ cache.setDetailed(false);
+ cache.setReliableLatLon(false);
+ cache.setGeocode(geocode);
+ cache.setName(nameCache.get(id));
+ cache.setZoomlevel(tile.getZoomlevel());
+ cache.setCoords(tile.getCoord(xy));
+ if (tile.getZoomlevel() >= 14) {
+ parseMapPNG14(cache, bitmap, xy);
+ } else {
+ parseMapPNG13(cache, bitmap, xy);
}
+ searchResult.addCache(cache);
}
Log.d(Settings.tag, "Retrieved " + searchResult.getCount() + " caches for tile " + tile.toString());
@@ -360,7 +353,7 @@ public class GCBase {
protected static List<Tile> getTilesForViewport(final Viewport viewport) {
List<Tile> tiles = new ArrayList<Tile>();
if (!Settings.isPremiumMember()) {
- tiles.add(new Tile(viewport.getCenter(), 14)); // precise coords for caches nearby
+ tiles.add(new Tile(viewport.getCenter(), 14)); // precise coords for caches nearby. searchByCoords() is used for PMs
}
tiles.add(new Tile(viewport.getCenter(), 12)); // other caches around
return tiles;
diff --git a/main/src/cgeo/geocaching/maps/CGeoMap.java b/main/src/cgeo/geocaching/maps/CGeoMap.java
index 35a6f9b..fb70d13 100644
--- a/main/src/cgeo/geocaching/maps/CGeoMap.java
+++ b/main/src/cgeo/geocaching/maps/CGeoMap.java
@@ -173,6 +173,7 @@ public class CGeoMap extends AbstractMap implements OnMapDragListener, ViewFacto
private boolean liveChanged = false; // previous state for loadTimer
private boolean centered = false; // if map is already centered
private boolean alreadyCentered = false; // -""- for setting my location
+ private static Set<String> dirtyCaches = null;
// handlers
/** Updates the titles */
final private Handler displayHandler = new Handler() {
@@ -439,6 +440,18 @@ public class CGeoMap extends AbstractMap implements OnMapDragListener, ViewFacto
dirUpdate.updateDirection(dir);
}
+ if (!CollectionUtils.isEmpty(dirtyCaches)) {
+ for (String geocode : dirtyCaches) {
+ cgCache cache = app.loadCache(geocode, LoadFlags.LOAD_CACHE_OR_DB);
+ // remove to update the cache
+ caches.remove(cache);
+ caches.add(cache);
+ }
+ dirtyCaches.clear();
+ // force an update of the display. Includes a call to DownloadThread :-(
+ liveChanged = true;
+ }
+
startTimer();
}
@@ -1299,7 +1312,10 @@ public class CGeoMap extends AbstractMap implements OnMapDragListener, ViewFacto
}
if (search != null) {
- caches.addAll(search.getCachesFromSearchResult(LoadFlags.LOAD_CACHE_OR_DB));
+ Set<cgCache> result = search.getCachesFromSearchResult(LoadFlags.LOAD_CACHE_OR_DB);
+ // to update the caches they have to be removed first
+ caches.removeAll(result);
+ caches.addAll(result);
}
if (stop) {
@@ -1830,6 +1846,13 @@ public class CGeoMap extends AbstractMap implements OnMapDragListener, ViewFacto
fromActivity.startActivity(mapIntent);
}
+ public static void markCacheAsDirty(final String geocode) {
+ if (dirtyCaches == null) {
+ dirtyCaches = new HashSet<String>();
+ }
+ dirtyCaches.add(geocode);
+ }
+
/**
* Returns a OverlayItem represented by an icon
*
diff --git a/main/src/cgeo/geocaching/maps/CachesOverlay.java b/main/src/cgeo/geocaching/maps/CachesOverlay.java
index 37ac3a5..42c121a 100644
--- a/main/src/cgeo/geocaching/maps/CachesOverlay.java
+++ b/main/src/cgeo/geocaching/maps/CachesOverlay.java
@@ -207,6 +207,7 @@ public class CachesOverlay extends AbstractItemizedOverlay {
popupIntent.putExtra("geocode", coordinate.getGeocode());
+ CGeoMap.markCacheAsDirty(coordinate.getGeocode());
context.startActivity(popupIntent);
} else if (coordinate.getCoordType() != null && coordinate.getCoordType().equalsIgnoreCase("waypoint") && coordinate.getId() > 0) {
Intent popupIntent = new Intent(context, cgeowaypoint.class);