diff options
Diffstat (limited to 'main/src/cgeo/geocaching/maps/CGeoMap.java')
| -rw-r--r-- | main/src/cgeo/geocaching/maps/CGeoMap.java | 38 |
1 files changed, 30 insertions, 8 deletions
diff --git a/main/src/cgeo/geocaching/maps/CGeoMap.java b/main/src/cgeo/geocaching/maps/CGeoMap.java index c876192..f892622 100644 --- a/main/src/cgeo/geocaching/maps/CGeoMap.java +++ b/main/src/cgeo/geocaching/maps/CGeoMap.java @@ -5,7 +5,6 @@ import cgeo.geocaching.Geocache; import cgeo.geocaching.IGeoData; import cgeo.geocaching.R; import cgeo.geocaching.SearchResult; -import cgeo.geocaching.Settings; import cgeo.geocaching.StoredList; import cgeo.geocaching.Waypoint; import cgeo.geocaching.cgData; @@ -14,9 +13,11 @@ import cgeo.geocaching.cgeocaches; import cgeo.geocaching.activity.ActivityMixin; import cgeo.geocaching.connector.ConnectorFactory; import cgeo.geocaching.connector.gc.Login; +import cgeo.geocaching.connector.gc.Tile; import cgeo.geocaching.enumerations.CacheType; import cgeo.geocaching.enumerations.LiveMapStrategy.Strategy; import cgeo.geocaching.enumerations.LoadFlags; +import cgeo.geocaching.enumerations.LoadFlags.RemoveFlag; import cgeo.geocaching.enumerations.StatusCode; import cgeo.geocaching.enumerations.WaypointType; import cgeo.geocaching.geopoint.Geopoint; @@ -30,6 +31,7 @@ import cgeo.geocaching.maps.interfaces.MapProvider; import cgeo.geocaching.maps.interfaces.MapSource; import cgeo.geocaching.maps.interfaces.MapViewImpl; import cgeo.geocaching.maps.interfaces.OnMapDragListener; +import cgeo.geocaching.settings.Settings; import cgeo.geocaching.ui.dialog.LiveMapInfoDialogBuilder; import cgeo.geocaching.utils.AngleUtils; import cgeo.geocaching.utils.CancellableHandler; @@ -70,6 +72,7 @@ import android.widget.ViewSwitcher.ViewFactory; import java.io.File; import java.util.ArrayList; import java.util.Collection; +import java.util.EnumSet; import java.util.HashSet; import java.util.List; import java.util.Set; @@ -180,7 +183,7 @@ public class CGeoMap extends AbstractMap implements OnMapDragListener, ViewFacto /** Live mode enabled for map. **/ private boolean isLiveEnabled; // other things - private boolean liveChanged = false; // previous state for loadTimer + private boolean markersInvalidated = 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; @@ -569,6 +572,13 @@ public class CGeoMap extends AbstractMap implements OnMapDragListener, ViewFacto item.setTitle(res.getString(R.string.map_live_enable)); } + item = menu.findItem(R.id.menu_mycaches_mode); // own & found caches + if (Settings.isExcludeMyCaches()) { + item.setTitle(res.getString(R.string.map_mycaches_show)); + } else { + item.setTitle(res.getString(R.string.map_mycaches_hide)); + } + final Set<String> geocodesInViewport = getGeocodesForCachesInViewport(); menu.findItem(R.id.menu_store_caches).setEnabled(!isLoading() && CollectionUtils.isNotEmpty(geocodesInViewport) && new SearchResult(geocodesInViewport).hasUnsavedCaches()); @@ -620,7 +630,7 @@ public class CGeoMap extends AbstractMap implements OnMapDragListener, ViewFacto if (mapMode == MapMode.LIVE) { Settings.setLiveMap(isLiveEnabled); } - liveChanged = true; + markersInvalidated = true; lastSearchResult = null; searchIntent = null; ActivityMixin.invalidateOptionsMenu(activity); @@ -668,6 +678,14 @@ public class CGeoMap extends AbstractMap implements OnMapDragListener, ViewFacto mapView.repaintRequired(overlayCaches); ActivityMixin.invalidateOptionsMenu(activity); return true; + case R.id.menu_mycaches_mode: + Settings.setExcludeMine(!Settings.isExcludeMyCaches()); + markersInvalidated = true; + ActivityMixin.invalidateOptionsMenu(activity); + if (!Settings.isExcludeMyCaches()) { + Tile.Cache.clear(); + } + return true; case R.id.menu_theme_mode: selectMapTheme(); return true; @@ -1016,7 +1034,7 @@ public class CGeoMap extends AbstractMap implements OnMapDragListener, ViewFacto // check if map moved or zoomed //TODO Portree Use Rectangle inside with bigger search window. That will stop reloading on every move - final boolean moved = liveChanged || (isLiveEnabled && !downloaded) || (viewport == null) || zoomNow != zoom || + final boolean moved = markersInvalidated || (isLiveEnabled && !downloaded) || (viewport == null) || zoomNow != zoom || (mapMoved(viewport, viewportNow) && (cachesCnt <= 0 || CollectionUtils.isEmpty(caches) || !viewport.includes(viewportNow))); // update title on any change @@ -1027,7 +1045,7 @@ public class CGeoMap extends AbstractMap implements OnMapDragListener, ViewFacto // save new values if (moved) { - liveChanged = false; + markersInvalidated = false; long currentTime = System.currentTimeMillis(); @@ -1082,8 +1100,7 @@ public class CGeoMap extends AbstractMap implements OnMapDragListener, ViewFacto } // live mode search result if (isLiveEnabled) { - SearchResult liveResult = new SearchResult(cgData.loadCachedInViewport(viewport, Settings.getCacheType())); - searchResult.addGeocodes(liveResult.getGeocodes()); + searchResult.addSearchResult(cgData.loadCachedInViewport(viewport, Settings.getCacheType())); } downloaded = true; @@ -1179,7 +1196,12 @@ public class CGeoMap extends AbstractMap implements OnMapDragListener, ViewFacto Set<Geocache> result = searchResult.getCachesFromSearchResult(LoadFlags.LOAD_CACHE_OR_DB); CGeoMap.filter(result); // update the caches - // new collection type needs to remove first + // first remove filtered out + final Set<String> filteredCodes = searchResult.getFilteredGeocodes(); + Log.d("Filtering out " + filteredCodes.size() + " caches: " + filteredCodes.toString()); + caches.removeAll(cgData.loadCaches(filteredCodes, LoadFlags.LOAD_CACHE_ONLY)); + cgData.removeCaches(filteredCodes, EnumSet.of(RemoveFlag.REMOVE_CACHE)); + // new collection type needs to remove first to refresh caches.removeAll(result); caches.addAll(result); lastSearchResult = searchResult; |
