diff options
Diffstat (limited to 'main/src/cgeo/geocaching/connector/gc/GCMap.java')
| -rw-r--r-- | main/src/cgeo/geocaching/connector/gc/GCMap.java | 37 |
1 files changed, 26 insertions, 11 deletions
diff --git a/main/src/cgeo/geocaching/connector/gc/GCMap.java b/main/src/cgeo/geocaching/connector/gc/GCMap.java index 681a1d7..2e1dff0 100644 --- a/main/src/cgeo/geocaching/connector/gc/GCMap.java +++ b/main/src/cgeo/geocaching/connector/gc/GCMap.java @@ -2,7 +2,8 @@ package cgeo.geocaching.connector.gc; import cgeo.geocaching.SearchResult; import cgeo.geocaching.Settings; -import cgeo.geocaching.cgCache; +import cgeo.geocaching.Geocache; +import cgeo.geocaching.cgData; import cgeo.geocaching.cgeoapplication; import cgeo.geocaching.enumerations.CacheSize; import cgeo.geocaching.enumerations.CacheType; @@ -40,10 +41,10 @@ public class GCMap { final SearchResult result = new SearchResult(); final String geocodeList = StringUtils.join(geocodes.toArray(), "|"); - final String referer = GCConstants.URL_LIVE_MAP_DETAILS; try { final Parameters params = new Parameters("i", geocodeList, "_", String.valueOf(System.currentTimeMillis())); + final String referer = GCConstants.URL_LIVE_MAP_DETAILS; final String data = StringUtils.defaultString(Tile.requestMapInfo(referer, params, referer)); // Example JSON information @@ -67,7 +68,7 @@ public class GCMap { } for (int j = 0; j < dataArray.length(); j++) { - final cgCache cache = new cgCache(); + final Geocache cache = new Geocache(); JSONObject dataObject = dataArray.getJSONObject(j); cache.setName(dataObject.getString("name")); @@ -166,6 +167,8 @@ public class GCMap { // iterate over the data and construct all caches in this tile Map<String, List<UTFGridPosition>> positions = new HashMap<String, List<UTFGridPosition>>(); // JSON id as key + Map<String, List<UTFGridPosition>> singlePositions = new HashMap<String, List<UTFGridPosition>>(); // JSON id as key + for (int i = 1; i < keys.length(); i++) { // index 0 is empty String key = keys.getString(i); if (StringUtils.isNotBlank(key)) { @@ -177,12 +180,20 @@ public class GCMap { nameCache.put(id, cacheInfo.getString("n")); List<UTFGridPosition> listOfPositions = positions.get(id); + List<UTFGridPosition> singleListOfPositions = singlePositions.get(id); + if (listOfPositions == null) { listOfPositions = new ArrayList<UTFGridPosition>(); positions.put(id, listOfPositions); + singleListOfPositions = new ArrayList<UTFGridPosition>(); + singlePositions.put(id, singleListOfPositions); } listOfPositions.add(pos); + if (dataForKey.length() == 1) { + singleListOfPositions.add(pos); + } + } } } @@ -191,27 +202,31 @@ public class GCMap { String id = entry.getKey(); List<UTFGridPosition> pos = entry.getValue(); UTFGridPosition xy = UTFGrid.getPositionInGrid(pos); - cgCache cache = new cgCache(); + Geocache cache = new Geocache(); cache.setDetailed(false); cache.setReliableLatLon(false); cache.setGeocode(id); cache.setName(nameCache.get(id)); cache.setZoomlevel(tile.getZoomlevel()); cache.setCoords(tile.getCoord(xy)); - if (strategy.flags.contains(StrategyFlag.PARSE_TILES) && positions.size() < 64 && bitmap != null) { - // don't parse if there are too many caches. The decoding would return too much wrong results - IconDecoder.parseMapPNG(cache, bitmap, 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())) { + break; // cache parsed + } + } } else { cache.setType(CacheType.UNKNOWN); } + boolean exclude = false; - if (Settings.isExcludeMyCaches() && (cache.isFound() || cache.isOwn())) { // workaround for BM + if (Settings.isExcludeMyCaches() && (cache.isFound() || cache.isOwner())) { // workaround for BM exclude = true; } if (Settings.isExcludeDisabledCaches() && cache.isDisabled()) { exclude = true; } - if (Settings.getCacheType() != CacheType.ALL && Settings.getCacheType() != cache.getType() && cache.getType() != CacheType.UNKNOWN) { // workaround for BM + if (!Settings.getCacheType().contains(cache) && cache.getType() != CacheType.UNKNOWN) { // workaround for BM exclude = true; } if (!exclude) { @@ -313,7 +328,7 @@ public class GCMap { String data = Tile.requestMapInfo(GCConstants.URL_MAP_INFO, params, GCConstants.URL_LIVE_MAP); if (StringUtils.isEmpty(data)) { - Log.e("GCBase.searchByViewport: No data from server for tile (" + tile.getX() + "/" + tile.getY() + ")"); + Log.w("GCBase.searchByViewport: No data from server for tile (" + tile.getX() + "/" + tile.getY() + ")"); } else { final SearchResult search = GCMap.parseMapJSON(data, tile, bitmap, strategy); if (search == null || CollectionUtils.isEmpty(search.getGeocodes())) { @@ -341,7 +356,7 @@ public class GCMap { if (search != null && !search.isEmpty()) { final Set<String> geocodes = search.getGeocodes(); if (Settings.isPremiumMember()) { - lastSearchViewport = cgeoapplication.getInstance().getBounds(geocodes); + lastSearchViewport = cgData.getBounds(geocodes); } else { lastSearchViewport = new Viewport(center, center); } |
