diff options
| -rw-r--r-- | main/src/cgeo/geocaching/CacheCache.java | 28 | ||||
| -rw-r--r-- | main/src/cgeo/geocaching/cgeocaches.java | 33 |
2 files changed, 39 insertions, 22 deletions
diff --git a/main/src/cgeo/geocaching/CacheCache.java b/main/src/cgeo/geocaching/CacheCache.java index e8280e2..e027a8a 100644 --- a/main/src/cgeo/geocaching/CacheCache.java +++ b/main/src/cgeo/geocaching/CacheCache.java @@ -27,7 +27,7 @@ public class CacheCache { cachesCache.setRemoveHandler(new CacheRemoveHandler()); } - public void removeAllFromCache() { + public synchronized void removeAllFromCache() { cachesCache.clear(); } @@ -39,7 +39,9 @@ public class CacheCache { if (StringUtils.isBlank(geocode)) { throw new IllegalArgumentException("geocode must not be empty"); } - cachesCache.remove(geocode); + synchronized(this) { + cachesCache.remove(geocode); + } } /** @@ -56,8 +58,10 @@ public class CacheCache { if (StringUtils.isBlank(cache.getGeocode())) { throw new IllegalArgumentException("geocode must not be empty"); } - cache.addStorageLocation(StorageLocation.CACHE); - cachesCache.put(cache.getGeocode(), cache); + synchronized(this) { + cache.addStorageLocation(StorageLocation.CACHE); + cachesCache.put(cache.getGeocode(), cache); + } } /** @@ -69,10 +73,12 @@ public class CacheCache { if (StringUtils.isBlank(geocode)) { throw new IllegalArgumentException("geocode must not be empty"); } - return cachesCache.get(geocode); + synchronized(this) { + return cachesCache.get(geocode); + } } - public Set<String> getInViewport(final Viewport viewport, final CacheType cacheType) { + public synchronized Set<String> getInViewport(final Viewport viewport, final CacheType cacheType) { final Set<String> geocodes = new HashSet<String>(); for (final cgCache cache : cachesCache.values()) { if (cache.getCoords() == null) { @@ -89,15 +95,19 @@ public class CacheCache { } @Override - public String toString() { + public synchronized String toString() { return StringUtils.join(cachesCache.keySet(), ' '); } private static class CacheRemoveHandler implements RemoveHandler<cgCache> { @Override - public void onRemove(cgCache removed) { - Tile.Cache.removeFromTileCache(removed); + public void onRemove(final cgCache removed) { + // FIXME: as above, we sometimes get caches with null coordinates, that may then provoke + // a NullPointerException down the invocation chain. + if (removed.getCoords() != null) { + Tile.Cache.removeFromTileCache(removed); + } } } diff --git a/main/src/cgeo/geocaching/cgeocaches.java b/main/src/cgeo/geocaching/cgeocaches.java index 81c29e0..bced835 100644 --- a/main/src/cgeo/geocaching/cgeocaches.java +++ b/main/src/cgeo/geocaching/cgeocaches.java @@ -119,7 +119,7 @@ public class cgeocaches extends AbstractListActivity { private long detailProgressTime = 0L; private LoadDetailsThread threadDetails = null; private LoadFromWebThread threadWeb = null; - private int listId = StoredList.TEMPORARY_LIST_ID; + private int listId = StoredList.TEMPORARY_LIST_ID; // Only meaningful for the OFFLINE type private final GeoDirHandler geoDirHandler = new GeoDirHandler() { @Override @@ -578,6 +578,11 @@ public class cgeocaches extends AbstractListActivity { } } + private boolean isConcreteList() { + return type == CacheListType.OFFLINE && + (listId == StoredList.STANDARD_LIST_ID || listId >= cgData.customListIdOffset); + } + private boolean isInvokedFromAttachment() { return Intent.ACTION_VIEW.equals(getIntent().getAction()); } @@ -666,16 +671,18 @@ public class cgeocaches extends AbstractListActivity { if (type == CacheListType.OFFLINE) { SubMenu subMenu = menu.addSubMenu(0, SUBMENU_MANAGE_OFFLINE, 0, res.getString(R.string.caches_manage)).setIcon(R.drawable.ic_menu_save); subMenu.add(0, MENU_DROP_CACHES, 0, res.getString(R.string.caches_drop_all)); // delete saved caches - subMenu.add(0, MENU_DROP_CACHES_AND_LIST, 0, res.getString(R.string.caches_drop_all_and_list)); - if (listId != StoredList.ALL_LIST_ID) { + if (isConcreteList()) { + subMenu.add(0, MENU_DROP_CACHES_AND_LIST, 0, res.getString(R.string.caches_drop_all_and_list)); subMenu.add(0, MENU_REFRESH_STORED, 0, res.getString(R.string.cache_offline_refresh)); // download details for all caches } subMenu.add(0, MENU_MOVE_TO_LIST, 0, res.getString(R.string.cache_menu_move_list)); //TODO: add submenu/AlertDialog and use R.string.gpx_import_title - subMenu.add(0, MENU_IMPORT_GPX, 0, res.getString(R.string.gpx_import_title)); - if (Settings.getWebDeviceCode() != null) { - subMenu.add(0, MENU_IMPORT_WEB, 0, res.getString(R.string.web_import_title)); + if (isConcreteList()) { + subMenu.add(0, MENU_IMPORT_GPX, 0, res.getString(R.string.gpx_import_title)); + if (Settings.getWebDeviceCode() != null) { + subMenu.add(0, MENU_IMPORT_WEB, 0, res.getString(R.string.web_import_title)); + } } subMenu.add(0, MENU_EXPORT, 0, res.getString(R.string.export)); // export caches @@ -685,9 +692,7 @@ public class cgeocaches extends AbstractListActivity { subMenu.add(0, MENU_REMOVE_FROM_HISTORY, 0, res.getString(R.string.cache_clear_history)); // remove from history subMenu.add(0, MENU_EXPORT, 0, res.getString(R.string.export)); // export caches } - if (listId != StoredList.ALL_LIST_ID) { - menu.add(0, MENU_REFRESH_STORED, 0, res.getString(R.string.caches_store_offline)).setIcon(R.drawable.ic_menu_set_as); // download details for all caches - } + menu.add(0, MENU_REFRESH_STORED, 0, res.getString(R.string.caches_store_offline)).setIcon(R.drawable.ic_menu_set_as); // download details for all caches } navigationMenu = CacheListAppFactory.addMenuItems(menu, this, res); @@ -695,8 +700,10 @@ public class cgeocaches extends AbstractListActivity { if (type == CacheListType.OFFLINE) { SubMenu subMenu = menu.addSubMenu(0, SUBMENU_MANAGE_LISTS, 0, res.getString(R.string.list_menu)).setIcon(R.drawable.ic_menu_more); subMenu.add(0, MENU_CREATE_LIST, 0, res.getString(R.string.list_menu_create)); - subMenu.add(0, MENU_DROP_LIST, 0, res.getString(R.string.list_menu_drop)); - subMenu.add(0, MENU_RENAME_LIST, 0, res.getString(R.string.list_menu_rename)); + if (isConcreteList()) { + subMenu.add(0, MENU_DROP_LIST, 0, res.getString(R.string.list_menu_drop)); + subMenu.add(0, MENU_RENAME_LIST, 0, res.getString(R.string.list_menu_rename)); + } subMenu.add(0, MENU_SWITCH_LIST, 0, res.getString(R.string.list_menu_change)); } @@ -750,11 +757,11 @@ public class cgeocaches extends AbstractListActivity { if (type == CacheListType.OFFLINE) { // only offline list setMenuItemLabel(menu, MENU_DROP_CACHES, R.string.caches_drop_selected, R.string.caches_drop_all); menu.findItem(MENU_DROP_CACHES_AND_LIST).setVisible(!hasSelection && isNonDefaultList && !adapter.isFiltered()); - if (listId != StoredList.ALL_LIST_ID) { + if (isConcreteList()) { setMenuItemLabel(menu, MENU_REFRESH_STORED, R.string.caches_refresh_selected, R.string.caches_refresh_all); } setMenuItemLabel(menu, MENU_MOVE_TO_LIST, R.string.caches_move_selected, R.string.caches_move_all); - } else if (listId != StoredList.ALL_LIST_ID) { // search and history list (all other than offline) + } else { // search and history list (all other than offline) setMenuItemLabel(menu, MENU_REFRESH_STORED, R.string.caches_store_selected, R.string.caches_store_offline); } |
