diff options
| author | Portree-Kid <keith.paterson@gmx.de> | 2012-06-01 08:37:24 +0200 |
|---|---|---|
| committer | Portree-Kid <keith.paterson@gmx.de> | 2012-06-01 22:22:26 +0200 |
| commit | bac80d7a59c0373e73ee0eca5042910c25b0f69d (patch) | |
| tree | 28a89bc8ca59a9854ada0e7fee3e31d52b666c0c /main/src | |
| parent | 3a258cdf14b10f8dc5f4f4df54d6ae8ce30eeff8 (diff) | |
| download | cgeo-bac80d7a59c0373e73ee0eca5042910c25b0f69d.zip cgeo-bac80d7a59c0373e73ee0eca5042910c25b0f69d.tar.gz cgeo-bac80d7a59c0373e73ee0eca5042910c25b0f69d.tar.bz2 | |
Small refactoring to clear possible race conditions. Load and Dowload
could overwrite each others searchResult
Diffstat (limited to 'main/src')
| -rw-r--r-- | main/src/cgeo/geocaching/maps/CGeoMap.java | 39 |
1 files changed, 22 insertions, 17 deletions
diff --git a/main/src/cgeo/geocaching/maps/CGeoMap.java b/main/src/cgeo/geocaching/maps/CGeoMap.java index 0fcdb6f..bb3d885 100644 --- a/main/src/cgeo/geocaching/maps/CGeoMap.java +++ b/main/src/cgeo/geocaching/maps/CGeoMap.java @@ -142,7 +142,8 @@ public class CGeoMap extends AbstractMap implements OnMapDragListener, ViewFacto private WaypointType waypointTypeIntent = null; private int[] mapStateIntent = null; // status data - private SearchResult search = null; + /** Last search result used for displaying header */ + private SearchResult lastSearchResult = null; private String[] tokens = null; private boolean noMapTokenShowed = false; // map status data @@ -236,8 +237,8 @@ public class CGeoMap extends AbstractMap implements OnMapDragListener, ViewFacto title.append(']'); } - if (Settings.isDebug() && search != null && StringUtils.isNotBlank(search.getUrl())) { - title.append('[').append(search.getUrl()).append(']'); + if (Settings.isDebug() && lastSearchResult != null && StringUtils.isNotBlank(lastSearchResult.getUrl())) { + title.append('[').append(lastSearchResult.getUrl()).append(']'); } ActivityMixin.setTitle(activity, title.toString()); @@ -603,7 +604,7 @@ 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(search)); + menu.findItem(MENU_STORE_CACHES).setEnabled(isLiveMode() && !isLoading() && CollectionUtils.isNotEmpty(caches) && app.hasUnsavedCaches(lastSearchResult)); item = menu.findItem(MENU_CIRCLE_MODE); // show circles if (overlayCaches != null && overlayCaches.getCircles()) { @@ -639,7 +640,7 @@ public class CGeoMap extends AbstractMap implements OnMapDragListener, ViewFacto Settings.setLiveMap(!Settings.isLiveMap()); mapMode = Settings.isLiveMap() ? MapMode.LIVE_ONLINE : MapMode.LIVE_OFFLINE; liveChanged = true; - search = null; + lastSearchResult = null; searchIntent = null; ActivityMixin.invalidateOptionsMenu(activity); return true; @@ -723,7 +724,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, lastSearchResult); return true; } case MENU_STRATEGY_FASTEST: { @@ -1079,22 +1080,23 @@ public class CGeoMap extends AbstractMap implements OnMapDragListener, ViewFacto showProgressHandler.sendEmptyMessage(SHOW_PROGRESS); loadThreadRun = System.currentTimeMillis(); + SearchResult searchResult = null; // stage 1 - pull and render from the DB only for live map if (mapMode == MapMode.LIVE_ONLINE) { - search = new SearchResult(app.getStoredInViewport(viewport, Settings.getCacheType())); + searchResult = new SearchResult(app.getStoredInViewport(viewport, Settings.getCacheType())); } else if (mapMode == MapMode.LIVE_OFFLINE) { - search = new SearchResult(app.getCachedInViewport(viewport, Settings.getCacheType())); + searchResult = new SearchResult(app.getCachedInViewport(viewport, Settings.getCacheType())); } else { // map started from another activity - search = new SearchResult(searchIntent); + searchResult = new SearchResult(searchIntent); if (geocodeIntent != null) { - search.addGeocode(geocodeIntent); + searchResult.addGeocode(geocodeIntent); } } - if (search != null) { + if (searchResult != null) { downloaded = true; - Set<cgCache> cachesFromSearchResult = search.getCachesFromSearchResult(LoadFlags.LOAD_WAYPOINTS); + Set<cgCache> cachesFromSearchResult = searchResult.getCachesFromSearchResult(LoadFlags.LOAD_WAYPOINTS); caches.addAll(cachesFromSearchResult); } @@ -1130,6 +1132,7 @@ public class CGeoMap extends AbstractMap implements OnMapDragListener, ViewFacto if (mapMode == MapMode.LIVE_ONLINE) { downloadExecutor.execute(new DownloadRunnable(viewport)); } + lastSearchResult = searchResult; } finally { showProgressHandler.sendEmptyMessage(HIDE_PROGRESS); // hide progress } @@ -1153,6 +1156,7 @@ public class CGeoMap extends AbstractMap implements OnMapDragListener, ViewFacto showProgressHandler.sendEmptyMessage(SHOW_PROGRESS); // show progress int count = 0; + SearchResult searchResult = null; do { if (tokens == null) { @@ -1162,10 +1166,10 @@ public class CGeoMap extends AbstractMap implements OnMapDragListener, ViewFacto } } - search = ConnectorFactory.searchByViewport(viewport.resize(0.8), tokens); - if (search != null) { + searchResult = ConnectorFactory.searchByViewport(viewport.resize(0.8), tokens); + if (searchResult != null) { downloaded = true; - if (search.getError() == StatusCode.NOT_LOGGED_IN) { + if (searchResult.getError() == StatusCode.NOT_LOGGED_IN) { Login.login(); tokens = null; } else { @@ -1176,11 +1180,12 @@ public class CGeoMap extends AbstractMap implements OnMapDragListener, ViewFacto } while (count < 2); - if (search != null) { - Set<cgCache> result = search.getCachesFromSearchResult(LoadFlags.LOAD_CACHE_OR_DB); + if (searchResult != null) { + Set<cgCache> result = searchResult.getCachesFromSearchResult(LoadFlags.LOAD_CACHE_OR_DB); // to update the caches they have to be removed first caches.removeAll(result); caches.addAll(result); + lastSearchResult = searchResult; } //render |
