aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--main/src/cgeo/geocaching/maps/CGeoMap.java45
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