diff options
author | Samuel Tardieu <sam@rfc1149.net> | 2012-06-10 22:16:54 +0200 |
---|---|---|
committer | Samuel Tardieu <sam@rfc1149.net> | 2012-06-10 22:16:54 +0200 |
commit | 4e64657dc74e9a10d8264b5f26f1e21c0101a85f (patch) | |
tree | 2424015b24f9b27a126f30ae094156af66834609 /main/src | |
parent | 85210b2af048fae8bb04b7bebc9cd9d831735d9a (diff) | |
parent | 58a749623d9f4f7ef55aa56c09803afbd332ae83 (diff) | |
download | cgeo-4e64657dc74e9a10d8264b5f26f1e21c0101a85f.zip cgeo-4e64657dc74e9a10d8264b5f26f1e21c0101a85f.tar.gz cgeo-4e64657dc74e9a10d8264b5f26f1e21c0101a85f.tar.bz2 |
Merge remote-tracking branch 'campbeb/fix1757and1758' into upstream
Conflicts:
main/src/cgeo/geocaching/maps/CGeoMap.java
Diffstat (limited to 'main/src')
-rw-r--r-- | main/src/cgeo/geocaching/maps/CGeoMap.java | 45 |
1 files changed, 26 insertions, 19 deletions
diff --git a/main/src/cgeo/geocaching/maps/CGeoMap.java b/main/src/cgeo/geocaching/maps/CGeoMap.java index 5d0aa60..81fd510 100644 --- a/main/src/cgeo/geocaching/maps/CGeoMap.java +++ b/main/src/cgeo/geocaching/maps/CGeoMap.java @@ -605,7 +605,8 @@ public class CGeoMap extends AbstractMap implements OnMapDragListener, ViewFacto item.setTitle(res.getString(R.string.map_live_enable)); } - menu.findItem(MENU_STORE_CACHES).setEnabled(isLiveMode() && !isLoading() && CollectionUtils.isNotEmpty(caches) && app.hasUnsavedCaches(lastSearchResult)); + final Set<String> geocodesInViewport = getGeocodesForCachesInViewport(); + menu.findItem(MENU_STORE_CACHES).setEnabled(isLiveMode() && !isLoading() && CollectionUtils.isNotEmpty(geocodesInViewport) && app.hasUnsavedCaches(new SearchResult(geocodesInViewport))); item = menu.findItem(MENU_CIRCLE_MODE); // show circles if (overlayCaches != null && overlayCaches.getCircles()) { @@ -615,7 +616,7 @@ public class CGeoMap extends AbstractMap implements OnMapDragListener, ViewFacto } item = menu.findItem(MENU_AS_LIST); - item.setEnabled(isLiveMode() && CollectionUtils.isNotEmpty(caches)); + item.setEnabled(isLiveMode() && !isLoading()); menu.findItem(SUBMENU_STRATEGY).setEnabled(isLiveMode()); } catch (Exception e) { @@ -646,25 +647,14 @@ public class CGeoMap extends AbstractMap implements OnMapDragListener, ViewFacto ActivityMixin.invalidateOptionsMenu(activity); return true; case MENU_STORE_CACHES: - if (isLiveMode() && !isLoading() && CollectionUtils.isNotEmpty(caches)) { + if (!isLoading()) { + final Set<String> geocodesInViewport = getGeocodesForCachesInViewport(); final List<String> geocodes = new ArrayList<String>(); - final List<cgCache> cachesProtected = caches.getAsList(); - - try { - if (cachesProtected.size() > 0) { - final Viewport viewport = mapView.getViewport(); - - for (final cgCache cache : cachesProtected) { - if (cache != null && cache.getCoords() != null) { - if (viewport.contains(cache) && !app.isOffline(cache.getGeocode(), null)) { - geocodes.add(cache.getGeocode()); - } - } - } + for (final String geocode : geocodesInViewport) { + if (!app.isOffline(geocode, null)) { + geocodes.add(geocode); } - } catch (Exception e) { - Log.e("cgeomap.onOptionsItemSelected.#4: " + e.toString()); } detailTotal = geocodes.size(); @@ -725,7 +715,7 @@ public class CGeoMap extends AbstractMap implements OnMapDragListener, ViewFacto ActivityMixin.invalidateOptionsMenu(activity); return true; case MENU_AS_LIST: { - cgeocaches.startActivityMap(activity, lastSearchResult); + cgeocaches.startActivityMap(activity, new SearchResult(getGeocodesForCachesInViewport())); return true; } case MENU_STRATEGY_FASTEST: { @@ -762,6 +752,23 @@ public class CGeoMap extends AbstractMap implements OnMapDragListener, ViewFacto } /** + * @return a Set of geocodes corresponding to the caches that are shown on screen. + */ + private Set<String> getGeocodesForCachesInViewport() { + final Set<String> geocodes = new HashSet<String>(); + final List<cgCache> cachesProtected = caches.getAsList(); + + final Viewport viewport = mapView.getViewport(); + + for (final cgCache cache : cachesProtected) { + if (viewport.contains(cache)) { + geocodes.add(cache.getGeocode()); + } + } + return geocodes; + } + + /** * Restart the current activity if the map provider has changed, or change the map source if needed. * * @param mapSource |