aboutsummaryrefslogtreecommitdiffstats
path: root/main/src/cgeo/geocaching/maps/CGeoMap.java
diff options
context:
space:
mode:
Diffstat (limited to 'main/src/cgeo/geocaching/maps/CGeoMap.java')
-rw-r--r--main/src/cgeo/geocaching/maps/CGeoMap.java68
1 files changed, 23 insertions, 45 deletions
diff --git a/main/src/cgeo/geocaching/maps/CGeoMap.java b/main/src/cgeo/geocaching/maps/CGeoMap.java
index 0817170..0c62e65 100644
--- a/main/src/cgeo/geocaching/maps/CGeoMap.java
+++ b/main/src/cgeo/geocaching/maps/CGeoMap.java
@@ -1,15 +1,14 @@
package cgeo.geocaching.maps;
+import cgeo.geocaching.CacheListActivity;
+import cgeo.geocaching.CgeoApplication;
+import cgeo.geocaching.DataStore;
import cgeo.geocaching.DirectionProvider;
import cgeo.geocaching.Geocache;
import cgeo.geocaching.IGeoData;
import cgeo.geocaching.R;
import cgeo.geocaching.SearchResult;
-import cgeo.geocaching.StoredList;
import cgeo.geocaching.Waypoint;
-import cgeo.geocaching.cgData;
-import cgeo.geocaching.cgeoapplication;
-import cgeo.geocaching.cgeocaches;
import cgeo.geocaching.activity.ActivityMixin;
import cgeo.geocaching.connector.ConnectorFactory;
import cgeo.geocaching.connector.gc.Login;
@@ -22,6 +21,7 @@ import cgeo.geocaching.enumerations.StatusCode;
import cgeo.geocaching.enumerations.WaypointType;
import cgeo.geocaching.geopoint.Geopoint;
import cgeo.geocaching.geopoint.Viewport;
+import cgeo.geocaching.list.StoredList;
import cgeo.geocaching.maps.interfaces.CachesOverlayItemImpl;
import cgeo.geocaching.maps.interfaces.GeoPointImpl;
import cgeo.geocaching.maps.interfaces.MapActivityImpl;
@@ -40,7 +40,7 @@ import cgeo.geocaching.utils.LeastRecentlyUsedSet;
import cgeo.geocaching.utils.Log;
import cgeo.geocaching.utils.RunnableWithArgument;
-import org.apache.commons.collections.CollectionUtils;
+import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.builder.HashCodeBuilder;
@@ -128,7 +128,7 @@ public class CGeoMap extends AbstractMap implements OnMapDragListener, ViewFacto
private MapItemFactory mapItemFactory = null;
private Activity activity = null;
private MapViewImpl mapView = null;
- private cgeoapplication app = null;
+ private CgeoApplication app = null;
final private GeoDirHandler geoDirUpdate = new UpdateLoc();
private SearchResult searchIntent = null;
private String geocodeIntent = null;
@@ -359,9 +359,9 @@ public class CGeoMap extends AbstractMap implements OnMapDragListener, ViewFacto
// class init
res = this.getResources();
activity = this.getActivity();
- app = (cgeoapplication) activity.getApplication();
+ app = (CgeoApplication) activity.getApplication();
- int countBubbleCnt = cgData.getAllCachesCount();
+ int countBubbleCnt = DataStore.getAllCachesCount();
caches = new LeastRecentlyUsedSet<Geocache>(MAX_CACHES + countBubbleCnt);
final MapProvider mapProvider = Settings.getMapProvider();
@@ -491,7 +491,7 @@ public class CGeoMap extends AbstractMap implements OnMapDragListener, ViewFacto
if (!CollectionUtils.isEmpty(dirtyCaches)) {
for (String geocode : dirtyCaches) {
- Geocache cache = cgData.loadCache(geocode, LoadFlags.LOAD_WAYPOINTS);
+ Geocache cache = DataStore.loadCache(geocode, LoadFlags.LOAD_WAYPOINTS);
if (cache != null) {
// new collection type needs to remove first
caches.remove(cache);
@@ -609,7 +609,7 @@ public class CGeoMap extends AbstractMap implements OnMapDragListener, ViewFacto
default: // DETAILED
menu.findItem(R.id.menu_strategy_detailed).setChecked(true);
}
- } catch (Exception e) {
+ } catch (RuntimeException e) {
Log.e("CGeoMap.onPrepareOptionsMenu", e);
}
@@ -641,7 +641,7 @@ public class CGeoMap extends AbstractMap implements OnMapDragListener, ViewFacto
final List<String> geocodes = new ArrayList<String>();
for (final String geocode : geocodesInViewport) {
- if (!cgData.isOffline(geocode, null)) {
+ if (!DataStore.isOffline(geocode, null)) {
geocodes.add(geocode);
}
}
@@ -690,7 +690,7 @@ public class CGeoMap extends AbstractMap implements OnMapDragListener, ViewFacto
selectMapTheme();
return true;
case R.id.menu_as_list: {
- cgeocaches.startActivityMap(activity, new SearchResult(getGeocodesForCachesInViewport()));
+ CacheListActivity.startActivityMap(activity, new SearchResult(getGeocodesForCachesInViewport()));
return true;
}
case R.id.menu_strategy_fastest: {
@@ -948,7 +948,7 @@ public class CGeoMap extends AbstractMap implements OnMapDragListener, ViewFacto
mapView.repaintRequired(overlayPosition);
}
}
- } catch (Exception e) {
+ } catch (RuntimeException e) {
Log.w("Failed to update location.");
}
}
@@ -1090,7 +1090,7 @@ public class CGeoMap extends AbstractMap implements OnMapDragListener, ViewFacto
SearchResult searchResult;
if (mapMode == MapMode.LIVE) {
- searchResult = isLiveEnabled ? new SearchResult() : new SearchResult(cgData.loadStoredInViewport(viewport, Settings.getCacheType()));
+ searchResult = isLiveEnabled ? new SearchResult() : new SearchResult(DataStore.loadStoredInViewport(viewport, Settings.getCacheType()));
} else {
// map started from another activity
searchResult = searchIntent != null ? new SearchResult(searchIntent) : new SearchResult();
@@ -1100,7 +1100,7 @@ public class CGeoMap extends AbstractMap implements OnMapDragListener, ViewFacto
}
// live mode search result
if (isLiveEnabled) {
- searchResult.addSearchResult(cgData.loadCachedInViewport(viewport, Settings.getCacheType()));
+ searchResult.addSearchResult(DataStore.loadCachedInViewport(viewport, Settings.getCacheType()));
}
downloaded = true;
@@ -1123,7 +1123,7 @@ public class CGeoMap extends AbstractMap implements OnMapDragListener, ViewFacto
|| mapMode == MapMode.COORDS) {
//All visible waypoints
CacheType type = Settings.getCacheType();
- Set<Waypoint> waypointsInViewport = cgData.loadWaypoints(viewport, excludeMine, excludeDisabled, type);
+ Set<Waypoint> waypointsInViewport = DataStore.loadWaypoints(viewport, excludeMine, excludeDisabled, type);
waypoints.addAll(waypointsInViewport);
}
else {
@@ -1196,8 +1196,8 @@ public class CGeoMap extends AbstractMap implements OnMapDragListener, ViewFacto
// 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));
+ caches.removeAll(DataStore.loadCaches(filteredCodes, LoadFlags.LOAD_CACHE_ONLY));
+ DataStore.removeCaches(filteredCodes, EnumSet.of(RemoveFlag.REMOVE_CACHE));
// new collection type needs to remove first to refresh
caches.removeAll(result);
caches.addAll(result);
@@ -1383,7 +1383,6 @@ public class CGeoMap extends AbstractMap implements OnMapDragListener, ViewFacto
final private CancellableHandler handler;
final private List<String> geocodes;
final private int listId;
- private long last = 0L;
public LoadDetails(final CancellableHandler handler, final List<String> geocodes, final int listId) {
this.handler = handler;
@@ -1409,26 +1408,7 @@ public class CGeoMap extends AbstractMap implements OnMapDragListener, ViewFacto
break;
}
- if (!cgData.isOffline(geocode, null)) {
- if ((System.currentTimeMillis() - last) < 1500) {
- try {
- int delay = 1000 + (int) (Math.random() * 1000.0) - (int) (System.currentTimeMillis() - last);
- if (delay < 0) {
- delay = 500;
- }
-
- sleep(delay);
- } catch (Exception e) {
- // nothing
- }
- }
-
- if (handler.isCancelled()) {
- Log.i("Stopped storing process.");
-
- break;
- }
-
+ if (!DataStore.isOffline(geocode, null)) {
Geocache.storeCache(null, geocode, listId, false, handler);
}
} catch (Exception e) {
@@ -1441,8 +1421,6 @@ public class CGeoMap extends AbstractMap implements OnMapDragListener, ViewFacto
// FIXME: what does this yield() do here?
yield();
-
- last = System.currentTimeMillis();
}
// we're done
@@ -1501,7 +1479,7 @@ public class CGeoMap extends AbstractMap implements OnMapDragListener, ViewFacto
try {
mapController.setCenter(mapItemFactory.getGeoPointBase(new Geopoint(mapState[0] / 1.0e6, mapState[1] / 1.0e6)));
mapController.setZoom(mapState[2]);
- } catch (Exception e) {
+ } catch (RuntimeException e) {
// nothing at all
}
@@ -1512,9 +1490,9 @@ public class CGeoMap extends AbstractMap implements OnMapDragListener, ViewFacto
Viewport viewport = null;
if (geocodeCenter != null) {
- viewport = cgData.getBounds(geocodeCenter);
+ viewport = DataStore.getBounds(geocodeCenter);
} else if (searchCenter != null) {
- viewport = cgData.getBounds(searchCenter.getGeocodes());
+ viewport = DataStore.getBounds(searchCenter.getGeocodes());
}
if (viewport == null) {
@@ -1525,7 +1503,7 @@ public class CGeoMap extends AbstractMap implements OnMapDragListener, ViewFacto
if (viewport.getLatitudeSpan() != 0 && viewport.getLongitudeSpan() != 0) {
mapController.zoomToSpan((int) (viewport.getLatitudeSpan() * 1e6), (int) (viewport.getLongitudeSpan() * 1e6));
}
- } catch (Exception e) {
+ } catch (RuntimeException e) {
// nothing at all
}