diff options
author | Samuel Tardieu <sam@rfc1149.net> | 2012-06-18 11:02:25 +0200 |
---|---|---|
committer | Samuel Tardieu <sam@rfc1149.net> | 2012-06-18 11:02:25 +0200 |
commit | 5f059eee970010dd88a28593344a658a4c2e9980 (patch) | |
tree | fdf136558cf90576a4ced1a68c7f039653eda450 /main/src/cgeo | |
parent | 774a1dfae2134a5f4a9f1b77f4aa5d902032e4e7 (diff) | |
parent | 58a749623d9f4f7ef55aa56c09803afbd332ae83 (diff) | |
download | cgeo-5f059eee970010dd88a28593344a658a4c2e9980.zip cgeo-5f059eee970010dd88a28593344a658a4c2e9980.tar.gz cgeo-5f059eee970010dd88a28593344a658a4c2e9980.tar.bz2 |
Merge remote-tracking branch 'upstream/fix1757and1758' into release
Diffstat (limited to 'main/src/cgeo')
-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 8b5fe18..7534573 100644 --- a/main/src/cgeo/geocaching/maps/CGeoMap.java +++ b/main/src/cgeo/geocaching/maps/CGeoMap.java @@ -587,7 +587,8 @@ public class CGeoMap extends AbstractMap implements OnMapDragListener, ViewFacto item.setTitle(res.getString(R.string.map_live_enable)); } - menu.findItem(MENU_STORE_CACHES).setEnabled(live && !isLoading() && CollectionUtils.isNotEmpty(caches) && app.hasUnsavedCaches(search)); + final Set<String> geocodesInViewport = getGeocodesForCachesInViewport(); + menu.findItem(MENU_STORE_CACHES).setEnabled(live && !isLoading() && CollectionUtils.isNotEmpty(geocodesInViewport) && app.hasUnsavedCaches(new SearchResult(geocodesInViewport))); item = menu.findItem(MENU_CIRCLE_MODE); // show circles if (overlayCaches != null && overlayCaches.getCircles()) { @@ -597,7 +598,7 @@ public class CGeoMap extends AbstractMap implements OnMapDragListener, ViewFacto } item = menu.findItem(MENU_AS_LIST); - item.setEnabled(live && CollectionUtils.isNotEmpty(caches)); + item.setEnabled(live && !isLoading()); menu.findItem(SUBMENU_STRATEGY).setEnabled(live); } catch (Exception e) { @@ -623,25 +624,14 @@ public class CGeoMap extends AbstractMap implements OnMapDragListener, ViewFacto ActivityMixin.invalidateOptionsMenu(activity); return true; case MENU_STORE_CACHES: - if (live && !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(); @@ -702,7 +692,7 @@ public class CGeoMap extends AbstractMap implements OnMapDragListener, ViewFacto ActivityMixin.invalidateOptionsMenu(activity); return true; case MENU_AS_LIST: { - cgeocaches.startActivityMap(activity, search); + cgeocaches.startActivityMap(activity, new SearchResult(getGeocodesForCachesInViewport())); return true; } case MENU_STRATEGY_FASTEST: { @@ -739,6 +729,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 |