diff options
author | blafoo <github@blafoo.de> | 2011-11-18 17:50:16 +0100 |
---|---|---|
committer | blafoo <github@blafoo.de> | 2011-11-18 20:21:28 +0100 |
commit | 4226ec4247f122a875539c55fcb147a81bce5780 (patch) | |
tree | caa0fab902e3ef981a32697f4fdfa721fcc4dd95 /main | |
parent | e4fb6c596ba35e3ed6c7d2341ffb5e006417ec4e (diff) | |
download | cgeo-4226ec4247f122a875539c55fcb147a81bce5780.zip cgeo-4226ec4247f122a875539c55fcb147a81bce5780.tar.gz cgeo-4226ec4247f122a875539c55fcb147a81bce5780.tar.bz2 |
Use of CacheType instead of String
Diffstat (limited to 'main')
29 files changed, 243 insertions, 292 deletions
diff --git a/main/src/cgeo/geocaching/IBasicCache.java b/main/src/cgeo/geocaching/IBasicCache.java index 88b78ca..f087bfb 100644 --- a/main/src/cgeo/geocaching/IBasicCache.java +++ b/main/src/cgeo/geocaching/IBasicCache.java @@ -18,7 +18,7 @@ public interface IBasicCache extends ILogable { /** * @return Tradi, multi etc. */ - public abstract CacheType getCacheType(); + public abstract CacheType getType(); /** * @return Micro, small etc. diff --git a/main/src/cgeo/geocaching/Settings.java b/main/src/cgeo/geocaching/Settings.java index 822bd04..bed8d8e 100644 --- a/main/src/cgeo/geocaching/Settings.java +++ b/main/src/cgeo/geocaching/Settings.java @@ -249,7 +249,11 @@ public final class Settings { return sharedPrefs.getString(KEY_COOKIE_STORE, null); } - public static CacheType setCacheType(final CacheType cacheType) { + /** + * @param cacheType + * The cache type used for future filtering + */ + public static void setCacheType(final CacheType cacheType) { editSharedSettings(new PrefRunnable() { @Override public void edit(Editor edit) { @@ -260,7 +264,6 @@ public final class Settings { } } }); - return cacheType; } public static void setLiveMap(final boolean live) { @@ -779,12 +782,11 @@ public final class Settings { return sharedPrefs.getString(KEY_WEBDEVICE_NAME, null); } + /** + * @return The cache type used for filtering or ALL if no filter is active. Returns never null + */ public static CacheType getCacheType() { - String cacheFilterType = sharedPrefs.getString(KEY_CACHE_TYPE, null); - if (cacheFilterType == null) { - return null; - } - return CacheType.getById(cacheFilterType); + return CacheType.getById(sharedPrefs.getString(KEY_CACHE_TYPE, CacheType.ALL.id)); } public static int getWayPointsThreshold() { diff --git a/main/src/cgeo/geocaching/StaticMapsProvider.java b/main/src/cgeo/geocaching/StaticMapsProvider.java index 7f4587d..9834681 100644 --- a/main/src/cgeo/geocaching/StaticMapsProvider.java +++ b/main/src/cgeo/geocaching/StaticMapsProvider.java @@ -102,7 +102,7 @@ public class StaticMapsProvider { } private static String getMarkerUrl(final cgCache cache) { - String type = cache.getCacheType().id; + String type = cache.getType().id; if (cache.isFound()) { type += "_found"; } else if (cache.isDisabled()) { diff --git a/main/src/cgeo/geocaching/apps/AbstractLocusApp.java b/main/src/cgeo/geocaching/apps/AbstractLocusApp.java index d1dda2a..13d7f3f 100644 --- a/main/src/cgeo/geocaching/apps/AbstractLocusApp.java +++ b/main/src/cgeo/geocaching/apps/AbstractLocusApp.java @@ -123,7 +123,7 @@ public abstract class AbstractLocusApp extends AbstractApp { if (cache.getHidden() != null) { pg.hidden = ISO8601DATE.format(cache.getHidden().getTime()); } - int locusId = toLocusId(cache.getCacheType()); + int locusId = toLocusId(cache.getType()); if (locusId != NO_LOCUS_ID) { pg.type = locusId; } diff --git a/main/src/cgeo/geocaching/apps/cache/WhereYouGoApp.java b/main/src/cgeo/geocaching/apps/cache/WhereYouGoApp.java index b452029..ec6079c 100644 --- a/main/src/cgeo/geocaching/apps/cache/WhereYouGoApp.java +++ b/main/src/cgeo/geocaching/apps/cache/WhereYouGoApp.java @@ -13,6 +13,6 @@ class WhereYouGoApp extends AbstractGeneralApp { @Override public boolean isEnabled(cgCache cache) { - return cache != null && cache.getCacheType() == CacheType.WHERIGO; + return cache != null && cache.getType() == CacheType.WHERIGO; } } diff --git a/main/src/cgeo/geocaching/cgBase.java b/main/src/cgeo/geocaching/cgBase.java index 4ede03f..af8ada5 100644 --- a/main/src/cgeo/geocaching/cgBase.java +++ b/main/src/cgeo/geocaching/cgBase.java @@ -97,15 +97,6 @@ public class cgBase { private static final String passMatch = "(?<=[\\?&])[Pp]ass(w(or)?d)?=[^&#$]+"; - public final static Map<String, String> cacheIDs = new HashMap<String, String>(); - static { - for (CacheType ct : CacheType.values()) { - cacheIDs.put(ct.id, ct.guid); - } - } - public final static Map<CacheType, String> cacheTypesInv = new HashMap<CacheType, String>(); - public final static Map<String, String> cacheIDsChoices = new HashMap<String, String>(); - public final static Map<CacheSize, String> cacheSizesInv = new HashMap<CacheSize, String>(); public final static Map<WaypointType, String> waypointTypes = new HashMap<WaypointType, String>(); public final static Map<String, Integer> logTypes = new HashMap<String, Integer>(); public final static Map<String, Integer> logTypes0 = new HashMap<String, Integer>(); @@ -244,21 +235,6 @@ public class cgBase { context = app.getBaseContext(); res = app.getBaseContext().getResources(); - // setup cache type mappings - - - cacheIDsChoices.put(res.getString(R.string.all), CacheType.ALL_GUID); - - for (CacheType ct : CacheType.values()) { - String l10n = res.getString(ct.stringId); - cacheTypesInv.put(ct, l10n); - cacheIDsChoices.put(l10n, ct.guid); - } - - for (CacheSize cs : CacheSize.values()) { - cacheSizesInv.put(cs, res.getString(cs.stringId)); - } - // waypoint types for (WaypointType wt : WaypointType.values()) { if (wt != WaypointType.OWN) { @@ -659,7 +635,7 @@ public class cgBase { cache.setGeocode(BaseUtils.getMatch(row, GCConstants.PATTERN_SEARCH_GEOCODE, true, 1, cache.getGeocode(), true).toUpperCase()); // cache type - cache.setCacheType(CacheType.getByPattern(BaseUtils.getMatch(row, GCConstants.PATTERN_SEARCH_TYPE, true, 1, null, true))); + cache.setType(CacheType.getByPattern(BaseUtils.getMatch(row, GCConstants.PATTERN_SEARCH_TYPE, true, 1, null, true))); // cache direction - image if (Settings.getLoadDirImg()) { @@ -872,31 +848,31 @@ public class cgBase { cacheToAdd.setDisabled(!oneCache.getBoolean("ia")); int ctid = oneCache.getInt("ctid"); if (ctid == 2) { - cacheToAdd.setCacheType(CacheType.TRADITIONAL); + cacheToAdd.setType(CacheType.TRADITIONAL); } else if (ctid == 3) { - cacheToAdd.setCacheType(CacheType.MULTI); + cacheToAdd.setType(CacheType.MULTI); } else if (ctid == 4) { - cacheToAdd.setCacheType(CacheType.VIRTUAL); + cacheToAdd.setType(CacheType.VIRTUAL); } else if (ctid == 5) { - cacheToAdd.setCacheType(CacheType.LETTERBOX); + cacheToAdd.setType(CacheType.LETTERBOX); } else if (ctid == 6) { - cacheToAdd.setCacheType(CacheType.EVENT); + cacheToAdd.setType(CacheType.EVENT); } else if (ctid == 8) { - cacheToAdd.setCacheType(CacheType.MYSTERY); + cacheToAdd.setType(CacheType.MYSTERY); } else if (ctid == 11) { - cacheToAdd.setCacheType(CacheType.WEBCAM); + cacheToAdd.setType(CacheType.WEBCAM); } else if (ctid == 13) { - cacheToAdd.setCacheType(CacheType.CITO); + cacheToAdd.setType(CacheType.CITO); } else if (ctid == 137) { - cacheToAdd.setCacheType(CacheType.EARTH); + cacheToAdd.setType(CacheType.EARTH); } else if (ctid == 453) { - cacheToAdd.setCacheType(CacheType.MEGA_EVENT); + cacheToAdd.setType(CacheType.MEGA_EVENT); } else if (ctid == 1858) { - cacheToAdd.setCacheType(CacheType.WHERIGO); + cacheToAdd.setType(CacheType.WHERIGO); } else if (ctid == 3653) { - cacheToAdd.setCacheType(CacheType.LOSTANDFOUND); + cacheToAdd.setType(CacheType.LOSTANDFOUND); } else { - cacheToAdd.setCacheType(CacheType.UNKNOWN); + cacheToAdd.setType(CacheType.UNKNOWN); } caches.cacheList.add(cacheToAdd); @@ -1041,14 +1017,14 @@ public class cgBase { cache.setFavouriteCnt(Integer.parseInt(BaseUtils.getMatch(tableInside, GCConstants.PATTERN_FAVORITECOUNT, true, "0"))); // cache size - cache.setSize(CacheSize.FIND_BY_ID.get(BaseUtils.getMatch(tableInside, GCConstants.PATTERN_SIZE, true, CacheSize.NOT_CHOSEN.id).toLowerCase())); + cache.setSize(CacheSize.getById(BaseUtils.getMatch(tableInside, GCConstants.PATTERN_SIZE, true, CacheSize.NOT_CHOSEN.id).toLowerCase())); } // cache found cache.setFound(BaseUtils.matches(page, GCConstants.PATTERN_FOUND) || BaseUtils.matches(page, GCConstants.PATTERN_FOUND_ALTERNATIVE)); // cache type - cache.setCacheType(CacheType.getByPattern(BaseUtils.getMatch(page, GCConstants.PATTERN_TYPE, true, cache.getCacheType().id))); + cache.setType(CacheType.getByPattern(BaseUtils.getMatch(page, GCConstants.PATTERN_TYPE, true, cache.getType().id))); // on watchlist cache.setOnWatchlist(BaseUtils.matches(page, GCConstants.PATTERN_WATCHLIST)); @@ -1447,7 +1423,7 @@ public class cgBase { if (cache.getSize() == null) { Log.e(Settings.tag, "size not parsed correctly"); } - if (cache.getCacheType() == null || cache.getCacheType() == CacheType.UNKNOWN) { + if (cache.getType() == null || cache.getType() == CacheType.UNKNOWN) { Log.e(Settings.tag, "type not parsed correctly"); } if (cache.getCoords() == null) { @@ -1833,7 +1809,7 @@ public class cgBase { * the type of cache, or null to include everything */ static private void insertCacheType(final Parameters params, final CacheType cacheType) { - params.put("tx", cacheType != null ? cacheType.guid : CacheType.ALL_GUID); + params.put("tx", cacheType.guid); } public cgSearch searchByNextPage(cgSearchThread thread, final cgSearch search, int reason, boolean showCaptcha) { @@ -1974,7 +1950,7 @@ public class cgBase { return null; } - List<cgCache> cacheList = filterSearchResults(search, caches, Settings.isExcludeDisabledCaches(), false, null); + List<cgCache> cacheList = filterSearchResults(search, caches, Settings.isExcludeDisabledCaches(), false, cacheType); app.addSearch(cacheList, reason); return search; @@ -2091,7 +2067,7 @@ public class cgBase { // Is there any reason to exclude the cache from the list? final boolean excludeCache = (excludeDisabled && cache.isDisabled()) || (excludeMine && (cache.isOwn() || cache.isFound())) || - (cacheType != null && cacheType != cache.getCacheType()); + (cacheType != CacheType.ALL && cacheType != cache.getType()); if (!excludeCache) { search.addGeocode(cache.getGeocode()); cacheList.add(cache); diff --git a/main/src/cgeo/geocaching/cgCache.java b/main/src/cgeo/geocaching/cgCache.java index d41e725..2eeee6f 100644 --- a/main/src/cgeo/geocaching/cgCache.java +++ b/main/src/cgeo/geocaching/cgCache.java @@ -131,7 +131,7 @@ public class cgCache implements ICache { guid = other.getGuid(); } if (null == cacheType || CacheType.UNKNOWN == cacheType) { - cacheType = other.getCacheType(); + cacheType = other.getType(); } if (StringUtils.isBlank(name)) { name = other.getName(); @@ -906,18 +906,23 @@ public class cgCache implements ICache { this.nameForSorting = nameForSorting; } + /* + * (non-Javadoc) + * + * @see cgeo.geocaching.IBasicCache#getType() + * + * @returns Never null + */ @Override - public CacheType getCacheType() { + public CacheType getType() { return cacheType; } - public void setCacheType(CacheType cacheType) { - if (cacheType == null) { - this.cacheType = CacheType.UNKNOWN; - } - else { - this.cacheType = cacheType; + public void setType(CacheType cacheType) { + if (cacheType == null || CacheType.ALL == cacheType) { + throw new IllegalArgumentException("Illegal cache type"); } + this.cacheType = cacheType; } public boolean hasDifficulty() { diff --git a/main/src/cgeo/geocaching/cgCacheListAdapter.java b/main/src/cgeo/geocaching/cgCacheListAdapter.java index 1d2f1b8..11a3799 100644 --- a/main/src/cgeo/geocaching/cgCacheListAdapter.java +++ b/main/src/cgeo/geocaching/cgCacheListAdapter.java @@ -84,7 +84,7 @@ public class cgCacheListAdapter extends ArrayAdapter<cgCache> { activity.getWindowManager().getDefaultDisplay().getMetrics(metrics); pixelDensity = metrics.density; - for (final CacheType cacheType : cgBase.cacheTypesInv.keySet()) { + for (final CacheType cacheType : CacheType.values()) { gcIconDrawables.put(cacheType, activity.getResources().getDrawable(cgBase.getCacheIcon(cacheType))); } @@ -434,8 +434,8 @@ public class cgCacheListAdapter extends ArrayAdapter<cgCache> { } holder.text.setText(cache.getNameSp(), TextView.BufferType.SPANNABLE); - if (gcIconDrawables.containsKey(cache.getCacheType())) { // cache icon - holder.text.setCompoundDrawablesWithIntrinsicBounds(gcIconDrawables.get(cache.getCacheType()), null, null, null); + if (gcIconDrawables.containsKey(cache.getType())) { // cache icon + holder.text.setCompoundDrawablesWithIntrinsicBounds(gcIconDrawables.get(cache.getType()), null, null, null); } else { // unknown cache type, "mystery" icon holder.text.setCompoundDrawablesWithIntrinsicBounds(gcIconDrawables.get(CacheType.MYSTERY), null, null, null); } @@ -575,7 +575,7 @@ public class cgCacheListAdapter extends ArrayAdapter<cgCache> { if (cacheInfo.length() > 0) { cacheInfo.append(SEPARATOR); } - cacheInfo.append(res.getString(cache.getSize().stringId)); + cacheInfo.append(cache.getSize().getL10n()); } else if (cache.isEventCache() && cache.getHiddenDate() != null) { if (cacheInfo.length() > 0) { cacheInfo.append(SEPARATOR); diff --git a/main/src/cgeo/geocaching/cgCoord.java b/main/src/cgeo/geocaching/cgCoord.java index c7b6cfe..f6d7558 100644 --- a/main/src/cgeo/geocaching/cgCoord.java +++ b/main/src/cgeo/geocaching/cgCoord.java @@ -12,7 +12,7 @@ public class cgCoord implements IBasicCache, IWaypoint { private String guid = null; // only valid if constructed with a cache private CacheType cacheType = null; // only valid if constructed with a cache private String geocode = ""; - private String type = "cache"; // used values: { cache, waypoint } + private String coordType = "cache"; // used values: { cache, waypoint } private String typeSpec = CacheType.TRADITIONAL.id; private String name = ""; private boolean found = false; @@ -32,12 +32,12 @@ public class cgCoord implements IBasicCache, IWaypoint { geocode = cache.getGeocode(); coords = cache.getCoords(); name = cache.getName(); - type = "cache"; - typeSpec = cache.getCacheType().id; + coordType = "cache"; + typeSpec = cache.getType().id; difficulty = cache.getDifficulty(); terrain = cache.getTerrain(); size = cache.getSize(); - cacheType = cache.getCacheType(); + cacheType = cache.getType(); } public cgCoord(cgWaypoint waypoint) { @@ -47,7 +47,7 @@ public class cgCoord implements IBasicCache, IWaypoint { geocode = ""; coords = waypoint.getCoords(); name = waypoint.getName(); - type = "waypoint"; + coordType = "waypoint"; typeSpec = waypoint.getWaypointType() != null ? waypoint.getWaypointType().id : null; waypointType = waypoint.getWaypointType(); } @@ -69,12 +69,12 @@ public class cgCoord implements IBasicCache, IWaypoint { this.geocode = geocode; } - public String getType() { - return type; + public String getCoordType() { + return coordType; } - public void setType(String type) { - this.type = type; + public void setCoordType(String type) { + this.coordType = type; } public String getTypeSpec() { @@ -162,7 +162,7 @@ public class cgCoord implements IBasicCache, IWaypoint { } @Override - public CacheType getCacheType() { + public CacheType getType() { return cacheType; } } diff --git a/main/src/cgeo/geocaching/cgData.java b/main/src/cgeo/geocaching/cgData.java index bea910c..b95e42c 100644 --- a/main/src/cgeo/geocaching/cgData.java +++ b/main/src/cgeo/geocaching/cgData.java @@ -1233,7 +1233,7 @@ public class cgData { values.put("geocode", cache.getGeocode()); values.put("cacheid", cache.getCacheId()); values.put("guid", cache.getGuid()); - values.put("type", cache.getCacheType().id); + values.put("type", cache.getType().id); values.put("name", cache.getName()); values.put("own", cache.isOwn() ? 1 : 0); values.put("owner", cache.getOwner()); @@ -2090,14 +2090,14 @@ public class cgData { cache.setGeocode(cursor.getString(cacheColumnIndex[5])); cache.setCacheId(cursor.getString(cacheColumnIndex[6])); cache.setGuid(cursor.getString(cacheColumnIndex[7])); - cache.setCacheType(CacheType.getById(cursor.getString(cacheColumnIndex[8]))); + cache.setType(CacheType.getById(cursor.getString(cacheColumnIndex[8]))); cache.setName(cursor.getString(cacheColumnIndex[9])); cache.setOwn(cursor.getInt(cacheColumnIndex[10]) == 1); cache.setOwner(cursor.getString(cacheColumnIndex[11])); cache.setOwnerReal(cursor.getString(cacheColumnIndex[12])); cache.setHidden(new Date(cursor.getLong(cacheColumnIndex[13]))); cache.setHint(cursor.getString(cacheColumnIndex[14])); - cache.setSize(CacheSize.FIND_BY_ID.get(cursor.getString(cacheColumnIndex[15]))); + cache.setSize(CacheSize.getById(cursor.getString(cacheColumnIndex[15]))); cache.setDifficulty(cursor.getFloat(cacheColumnIndex[16])); index = cacheColumnIndex[17]; if (cursor.isNull(index)) { @@ -2560,13 +2560,13 @@ public class cgData { try { String sql = "select count(_id) from " + dbTableCaches; // this default is not used, but we like to have variables initialized if (!detailedOnly) { - if (cacheType == null) { + if (cacheType == CacheType.ALL) { sql = "select count(_id) from " + dbTableCaches + listSql; } else { sql = "select count(_id) from " + dbTableCaches + " where type = \"" + cacheType.id + "\"" + listSqlW; } } else { - if (cacheType == null) { + if (cacheType == CacheType.ALL) { sql = "select count(_id) from " + dbTableCaches + " where detailed = 1" + listSqlW; } else { sql = "select count(_id) from " + dbTableCaches + " where detailed = 1 and type = \"" + cacheType.id + "\"" + listSqlW; @@ -2612,7 +2612,7 @@ public class cgData { specifySql.append(" and detailed = 1 "); } - if (cacheType != null) { + if (cacheType != CacheType.ALL) { specifySql.append(" and type = \""); specifySql.append(cacheType.id); specifySql.append('"'); @@ -2653,7 +2653,7 @@ public class cgData { return geocodes; } - public List<String> loadBatchOfHistoricGeocodes(final boolean detailedOnly, final CacheType cachetype) { + public List<String> loadBatchOfHistoricGeocodes(final boolean detailedOnly, final CacheType cacheType) { init(); List<String> geocodes = new ArrayList<String>(); @@ -2664,9 +2664,9 @@ public class cgData { if (detailedOnly) { specifySql.append(" and detailed = 1"); } - if (cachetype != null) { + if (cacheType != CacheType.ALL) { specifySql.append(" and type = \""); - specifySql.append(cachetype.id); + specifySql.append(cacheType.id); specifySql.append('"'); } @@ -2703,15 +2703,15 @@ public class cgData { return geocodes; } - public List<String> getCachedInViewport(final Long centerLat, final Long centerLon, final Long spanLat, final Long spanLon, final CacheType cachetype) { - return getInViewport(false, centerLat, centerLon, spanLat, spanLon, cachetype); + public List<String> getCachedInViewport(final Long centerLat, final Long centerLon, final Long spanLat, final Long spanLon, final CacheType cacheType) { + return getInViewport(false, centerLat, centerLon, spanLat, spanLon, cacheType); } - public List<String> getStoredInViewport(final Long centerLat, final Long centerLon, final Long spanLat, final Long spanLon, final CacheType cachetype) { - return getInViewport(true, centerLat, centerLon, spanLat, spanLon, cachetype); + public List<String> getStoredInViewport(final Long centerLat, final Long centerLon, final Long spanLat, final Long spanLon, final CacheType cacheType) { + return getInViewport(true, centerLat, centerLon, spanLat, spanLon, cacheType); } - public List<String> getInViewport(final boolean stored, final Long centerLat, final Long centerLon, final Long spanLat, final Long spanLon, final CacheType cachetype) { + public List<String> getInViewport(final boolean stored, final Long centerLat, final Long centerLon, final Long spanLat, final Long spanLon, final CacheType cacheType) { if (centerLat == null || centerLon == null || spanLat == null || spanLon == null) { return null; } @@ -2748,10 +2748,10 @@ public class cgData { where.append(" and longitude <= "); where.append(String.format((Locale) null, "%.6f", lonMax)); - // cachetype limitation - if (cachetype != null) { + // cacheType limitation + if (cacheType != CacheType.ALL) { where.append(" and type = \""); - where.append(cachetype.id); + where.append(cacheType.id); where.append('"'); } @@ -2793,16 +2793,16 @@ public class cgData { return geocodes; } - public List<String> getOfflineAll(String cachetype) { + public List<String> getOfflineAll(CacheType cacheType) { init(); List<String> geocodes = new ArrayList<String>(); StringBuilder where = new StringBuilder(); - // cachetype limitation - if (cachetype != null) { - where.append(cachetype); + // cacheType limitation + if (cacheType != CacheType.ALL) { + where.append(cacheType); where.append('"'); } diff --git a/main/src/cgeo/geocaching/cgeo.java b/main/src/cgeo/geocaching/cgeo.java index 9e116a4..0c9dc90 100644 --- a/main/src/cgeo/geocaching/cgeo.java +++ b/main/src/cgeo/geocaching/cgeo.java @@ -35,11 +35,8 @@ import android.widget.TextView; import java.util.ArrayList; import java.util.Collections; -import java.util.HashMap; import java.util.List; import java.util.Locale; -import java.util.Map; -import java.util.Map.Entry; public class cgeo extends AbstractActivity { @@ -343,17 +340,22 @@ public class cgeo extends AbstractActivity { menu.setHeaderTitle(res.getString(R.string.menu_filter)); //first add the most used types - menu.add(1, 0, 0, res.getString(R.string.all_types)); - menu.add(1, 1, 0, res.getString(R.string.traditional)); - menu.add(1, 2, 0, res.getString(R.string.multi)); - menu.add(1, 3, 0, res.getString(R.string.mystery)); + menu.add(1, 0, 0, CacheType.ALL.getL10n()); + menu.add(1, 1, 0, CacheType.TRADITIONAL.getL10n()); + menu.add(1, 2, 0, CacheType.MULTI.getL10n()); + menu.add(1, 3, 0, CacheType.MYSTERY.getL10n()); // then add all other cache types sorted alphabetically - Map<CacheType, String> allTypes = new HashMap<CacheType, String>(cgBase.cacheTypesInv); - allTypes.remove(CacheType.TRADITIONAL); - allTypes.remove(CacheType.MULTI); - allTypes.remove(CacheType.MYSTERY); - List<String> sorted = new ArrayList<String>(allTypes.values()); + List<String> sorted = new ArrayList<String>(); + for (CacheType ct : CacheType.values()) { + if (ct == CacheType.ALL || + ct == CacheType.TRADITIONAL || + ct == CacheType.MULTI || + ct == CacheType.MYSTERY) { + continue; + } + sorted.add(ct.getL10n()); + } Collections.sort(sorted); for (String choice : sorted) { menu.add(1, menu.size(), 0, choice); @@ -363,16 +365,12 @@ public class cgeo extends AbstractActivity { menu.setGroupCheckable(1, true, true); boolean foundItem = false; int itemCount = menu.size(); - if (Settings.getCacheType() != null) { - final String typeTitle = cgBase.cacheTypesInv.get(Settings.getCacheType()); - if (typeTitle != null) { - for (int i = 0; i < itemCount; i++) { - if (menu.getItem(i).getTitle().equals(typeTitle)) { - menu.getItem(i).setChecked(true); - foundItem = true; - break; - } - } + String typeTitle = Settings.getCacheType().getL10n(); + for (int i = 0; i < itemCount; i++) { + if (menu.getItem(i).getTitle().equals(typeTitle)) { + menu.getItem(i).setChecked(true); + foundItem = true; + break; } } if (!foundItem) { @@ -385,7 +383,7 @@ public class cgeo extends AbstractActivity { final int id = item.getItemId(); if (id == 0) { - Settings.setCacheType(null); + Settings.setCacheType(CacheType.ALL); setFilterTitle(); return true; @@ -396,14 +394,14 @@ public class cgeo extends AbstractActivity { return true; } else if (id > 0) { final String itemTitle = item.getTitle().toString(); - CacheType choice = null; - for (Entry<CacheType, String> entry : cgBase.cacheTypesInv.entrySet()) { - if (entry.getValue().equalsIgnoreCase(itemTitle)) { - choice = entry.getKey(); + CacheType cacheType = CacheType.ALL; + for (CacheType ct : CacheType.values()) { + if (ct.getL10n().equalsIgnoreCase(itemTitle)) { + cacheType = ct; break; } } - Settings.setCacheType(choice); + Settings.setCacheType(cacheType); setFilterTitle(); return true; @@ -416,10 +414,11 @@ public class cgeo extends AbstractActivity { if (filterTitle == null) { filterTitle = (TextView) findViewById(R.id.filter_button_title); } - if (Settings.getCacheType() != null) { - filterTitle.setText(cgBase.cacheTypesInv.get(Settings.getCacheType())); - } else { + if (CacheType.ALL == Settings.getCacheType()) { + // The text for ALL is R.string.all_types filterTitle.setText(res.getString(R.string.all)); + } else { + filterTitle.setText(Settings.getCacheType().getL10n()); } } @@ -449,10 +448,6 @@ public class cgeo extends AbstractActivity { updateCacheCounter(); (new cleanDatabase()).start(); - if (Settings.getCacheType() != null && !cgBase.cacheTypesInv.containsKey(Settings.getCacheType())) { - Settings.setCacheType(null); - } - if (geo == null) { geo = app.startGeo(this, geoUpdate, 0, 0); } @@ -705,7 +700,7 @@ public class cgeo extends AbstractActivity { } } - countBubbleCnt = app.getAllStoredCachesCount(true, null, null); + countBubbleCnt = app.getAllStoredCachesCount(true, CacheType.ALL, null); countBubbleHandler.sendEmptyMessage(0); } diff --git a/main/src/cgeo/geocaching/cgeoadvsearch.java b/main/src/cgeo/geocaching/cgeoadvsearch.java index 0004000..e0b68f5 100644 --- a/main/src/cgeo/geocaching/cgeoadvsearch.java +++ b/main/src/cgeo/geocaching/cgeoadvsearch.java @@ -143,10 +143,6 @@ public class cgeoadvsearch extends AbstractActivity { private void init() { Settings.getLogin(); - if (Settings.getCacheType() != null && !cgBase.cacheTypesInv.containsKey(Settings.getCacheType())) { - Settings.setCacheType(null); - } - if (geo == null) { geo = app.startGeo(this, geoUpdate, 0, 0); } diff --git a/main/src/cgeo/geocaching/cgeoapplication.java b/main/src/cgeo/geocaching/cgeoapplication.java index bb73a13..52a0ca9 100644 --- a/main/src/cgeo/geocaching/cgeoapplication.java +++ b/main/src/cgeo/geocaching/cgeoapplication.java @@ -477,8 +477,8 @@ public class cgeoapplication extends Application { return cachesOut; } - public cgSearch getBatchOfStoredCaches(final boolean detailedOnly, final Geopoint coords, final CacheType cachetype, final int list) { - final List<String> geocodes = getStorage().loadBatchOfStoredGeocodes(detailedOnly, coords, cachetype, list); + public cgSearch getBatchOfStoredCaches(final boolean detailedOnly, final Geopoint coords, final CacheType cacheType, final int list) { + final List<String> geocodes = getStorage().loadBatchOfStoredGeocodes(detailedOnly, coords, cacheType, list); return new cgSearch(geocodes); } @@ -486,23 +486,18 @@ public class cgeoapplication extends Application { return getStorage().loadHistoryOfSearchedLocations(); } - public cgSearch getHistoryOfCaches(final boolean detailedOnly, final CacheType cachetype) { - final List<String> geocodes = getStorage().loadBatchOfHistoricGeocodes(detailedOnly, cachetype); + public cgSearch getHistoryOfCaches(final boolean detailedOnly, final CacheType cacheType) { + final List<String> geocodes = getStorage().loadBatchOfHistoricGeocodes(detailedOnly, cacheType); return new cgSearch(geocodes); } - public cgSearch getCachedInViewport(final Long centerLat, final Long centerLon, final Long spanLat, final Long spanLon, final CacheType cachetype) { - final List<String> geocodes = getStorage().getCachedInViewport(centerLat, centerLon, spanLat, spanLon, cachetype); + public cgSearch getCachedInViewport(final Long centerLat, final Long centerLon, final Long spanLat, final Long spanLon, final CacheType cacheType) { + final List<String> geocodes = getStorage().getCachedInViewport(centerLat, centerLon, spanLat, spanLon, cacheType); return new cgSearch(geocodes); } - public cgSearch getStoredInViewport(final Long centerLat, final Long centerLon, final Long spanLat, final Long spanLon, final CacheType cachetype) { - final List<String> geocodes = getStorage().getStoredInViewport(centerLat, centerLon, spanLat, spanLon, cachetype); - return new cgSearch(geocodes); - } - - public cgSearch getOfflineAll(String cachetype) { - final List<String> geocodes = getStorage().getOfflineAll(cachetype); + public cgSearch getStoredInViewport(final Long centerLat, final Long centerLon, final Long spanLat, final Long spanLon, final CacheType cacheType) { + final List<String> geocodes = getStorage().getStoredInViewport(centerLat, centerLon, spanLat, spanLon, cacheType); return new cgSearch(geocodes); } diff --git a/main/src/cgeo/geocaching/cgeocaches.java b/main/src/cgeo/geocaching/cgeocaches.java index cbc65d6..067c9c0 100644 --- a/main/src/cgeo/geocaching/cgeocaches.java +++ b/main/src/cgeo/geocaching/cgeocaches.java @@ -148,7 +148,7 @@ public class cgeocaches extends AbstractListActivity { private String action = null; private CacheListType type = null; private Geopoint coords = null; - private CacheType cachetype = null; + private CacheType cacheType = null; private String keyword = null; private String address = null; private String username = null; @@ -555,7 +555,7 @@ public class cgeocaches extends AbstractListActivity { Object typeObject = extras.get(EXTRAS_LIST_TYPE); type = (typeObject instanceof CacheListType) ? (CacheListType) typeObject : CacheListType.OFFLINE; coords = new Geopoint(extras.getDouble("latitude"), extras.getDouble("longitude")); - cachetype = Settings.getCacheType(); + cacheType = Settings.getCacheType(); keyword = extras.getString("keyword"); address = extras.getString("address"); username = extras.getString("username"); @@ -571,7 +571,7 @@ public class cgeocaches extends AbstractListActivity { listId = Settings.getLastList(); if (listId <= 0) { listId = cgList.STANDARD_LIST_ID; - title = res.getString(R.string.caches_stored); + title = res.getString(R.string.stored_caches_button); } else { final cgList list = app.getList(listId); title = list.title; @@ -605,7 +605,7 @@ public class cgeocaches extends AbstractListActivity { showProgress(true); setLoadingCaches(); - thread = new geocachesLoadByCoords(loadCachesHandler, coords, cachetype); + thread = new geocachesLoadByCoords(loadCachesHandler, coords); thread.setRecaptchaHandler(new cgSearchHandler(this, res, thread)); thread.start(); break; @@ -616,7 +616,7 @@ public class cgeocaches extends AbstractListActivity { showProgress(true); setLoadingCaches(); - thread = new geocachesLoadByCoords(loadCachesHandler, coords, cachetype); + thread = new geocachesLoadByCoords(loadCachesHandler, coords); thread.setRecaptchaHandler(new cgSearchHandler(this, res, thread)); thread.start(); break; @@ -626,7 +626,7 @@ public class cgeocaches extends AbstractListActivity { showProgress(true); setLoadingCaches(); - thread = new geocachesLoadByKeyword(loadCachesHandler, keyword, cachetype); + thread = new geocachesLoadByKeyword(loadCachesHandler, keyword); thread.setRecaptchaHandler(new cgSearchHandler(this, res, thread)); thread.start(); break; @@ -644,7 +644,7 @@ public class cgeocaches extends AbstractListActivity { setLoadingCaches(); } - thread = new geocachesLoadByCoords(loadCachesHandler, coords, cachetype); + thread = new geocachesLoadByCoords(loadCachesHandler, coords); thread.setRecaptchaHandler(new cgSearchHandler(this, res, thread)); thread.start(); break; @@ -654,7 +654,7 @@ public class cgeocaches extends AbstractListActivity { showProgress(true); setLoadingCaches(); - thread = new geocachesLoadByUserName(loadCachesHandler, username, cachetype); + thread = new geocachesLoadByUserName(loadCachesHandler, username); thread.setRecaptchaHandler(new cgSearchHandler(this, res, thread)); thread.start(); break; @@ -664,7 +664,7 @@ public class cgeocaches extends AbstractListActivity { showProgress(true); setLoadingCaches(); - thread = new geocachesLoadByOwner(loadCachesHandler, username, cachetype); + thread = new geocachesLoadByOwner(loadCachesHandler, username); thread.setRecaptchaHandler(new cgSearchHandler(this, res, thread)); thread.start(); break; @@ -715,7 +715,7 @@ public class cgeocaches extends AbstractListActivity { // refresh standard list if it has changed (new caches downloaded) if (type == CacheListType.OFFLINE && listId == cgList.STANDARD_LIST_ID && search != null) { - cgSearch newSearch = base.searchByOffline(coords, cachetype, listId); + cgSearch newSearch = base.searchByOffline(coords, cacheType, listId); if (newSearch != null && newSearch.totalCnt != search.totalCnt) { refreshCurrentList(); } @@ -766,7 +766,7 @@ public class cgeocaches extends AbstractListActivity { public boolean onCreateOptionsMenu(Menu menu) { SubMenu subMenuFilter = menu.addSubMenu(0, SUBMENU_FILTER, 0, res.getString(R.string.caches_filter)).setIcon(R.drawable.ic_menu_filter); subMenuFilter.setHeaderTitle(res.getString(R.string.caches_filter_title)); - if (Settings.getCacheType() == null) { + if (Settings.getCacheType() == CacheType.ALL) { subMenuFilter.add(0, SUBMENU_FILTER_TYPE, 0, res.getString(R.string.caches_filter_type)); } subMenuFilter.add(0, SUBMENU_FILTER_SIZE, 0, res.getString(R.string.caches_filter_size)); @@ -1102,30 +1102,22 @@ public class cgeocaches extends AbstractListActivity { if (selectedFilter.equals(res.getString(R.string.caches_filter_size))) { menu.setHeaderTitle(res.getString(R.string.caches_filter_size_title)); - menu.add(0, MENU_FILTER_SIZE_MICRO, 0, res.getString(CacheSize.MICRO.stringId)); - menu.add(0, MENU_FILTER_SIZE_SMALL, 0, res.getString(CacheSize.SMALL.stringId)); - menu.add(0, MENU_FILTER_SIZE_REGULAR, 0, res.getString(CacheSize.REGULAR.stringId)); - menu.add(0, MENU_FILTER_SIZE_LARGE, 0, res.getString(CacheSize.LARGE.stringId)); - menu.add(0, MENU_FILTER_SIZE_OTHER, 0, res.getString(CacheSize.OTHER.stringId)); - menu.add(0, MENU_FILTER_SIZE_VIRTUAL, 0, res.getString(CacheSize.VIRTUAL.stringId)); - menu.add(0, MENU_FILTER_SIZE_NOT_CHOSEN, 0, res.getString(CacheSize.NOT_CHOSEN.stringId)); + menu.add(0, MENU_FILTER_SIZE_MICRO, 0, CacheSize.MICRO.getL10n()); + menu.add(0, MENU_FILTER_SIZE_SMALL, 0, CacheSize.SMALL.getL10n()); + menu.add(0, MENU_FILTER_SIZE_REGULAR, 0, CacheSize.REGULAR.getL10n()); + menu.add(0, MENU_FILTER_SIZE_LARGE, 0, CacheSize.LARGE.getL10n()); + menu.add(0, MENU_FILTER_SIZE_OTHER, 0, CacheSize.OTHER.getL10n()); + menu.add(0, MENU_FILTER_SIZE_VIRTUAL, 0, CacheSize.VIRTUAL.getL10n()); + menu.add(0, MENU_FILTER_SIZE_NOT_CHOSEN, 0, CacheSize.NOT_CHOSEN.getL10n()); } else if (selectedFilter.equals(res.getString(R.string.caches_filter_type))) { menu.setHeaderTitle(res.getString(R.string.caches_filter_type_title)); - menu.add(0, MENU_FILTER_TYPE_TRADITIONAL, 0, res.getString(CacheType.TRADITIONAL.stringId)); - menu.add(0, MENU_FILTER_TYPE_MULTI, 0, res.getString(CacheType.MULTI.stringId)); - menu.add(0, MENU_FILTER_TYPE_MYSTERY, 0, res.getString(CacheType.MYSTERY.stringId)); - menu.add(0, MENU_FILTER_TYPE_LETTERBOX, 0, res.getString(CacheType.LETTERBOX.stringId)); - menu.add(0, MENU_FILTER_TYPE_EVENT, 0, res.getString(CacheType.EVENT.stringId)); - menu.add(0, MENU_FILTER_TYPE_MEGA, 0, res.getString(CacheType.MEGA_EVENT.stringId)); - menu.add(0, MENU_FILTER_TYPE_EARTH, 0, res.getString(CacheType.EARTH.stringId)); - menu.add(0, MENU_FILTER_TYPE_CITO, 0, res.getString(CacheType.CITO.stringId)); - menu.add(0, MENU_FILTER_TYPE_WEBCAM, 0, res.getString(CacheType.WEBCAM.stringId)); - menu.add(0, MENU_FILTER_TYPE_VIRTUAL, 0, res.getString(CacheType.VIRTUAL.stringId)); - menu.add(0, MENU_FILTER_TYPE_WHERIGO, 0, res.getString(CacheType.WHERIGO.stringId)); - menu.add(0, MENU_FILTER_TYPE_LOSTFOUND, 0, res.getString(CacheType.LOSTANDFOUND.stringId)); - menu.add(0, MENU_FILTER_TYPE_APE, 0, res.getString(CacheType.PROJECT_APE.stringId)); - menu.add(0, MENU_FILTER_TYPE_GCHQ, 0, res.getString(CacheType.GCHQ.stringId)); - menu.add(0, MENU_FILTER_TYPE_GPS, 0, res.getString(CacheType.GPS_EXHIBIT.stringId)); + menu.add(0, MENU_FILTER_SIZE_MICRO, 0, CacheSize.MICRO.getL10n()); + menu.add(0, MENU_FILTER_SIZE_SMALL, 0, CacheSize.SMALL.getL10n()); + menu.add(0, MENU_FILTER_SIZE_REGULAR, 0, CacheSize.REGULAR.getL10n()); + menu.add(0, MENU_FILTER_SIZE_LARGE, 0, CacheSize.LARGE.getL10n()); + menu.add(0, MENU_FILTER_SIZE_OTHER, 0, CacheSize.OTHER.getL10n()); + menu.add(0, MENU_FILTER_SIZE_VIRTUAL, 0, CacheSize.VIRTUAL.getL10n()); + menu.add(0, MENU_FILTER_SIZE_NOT_CHOSEN, 0, CacheSize.NOT_CHOSEN.getL10n()); } } else { // adapterInfo cannot be null here, but the compiler cannot guess it so this prevents warnings @@ -1774,7 +1766,7 @@ public class cgeocaches extends AbstractListActivity { if (coords != null) { search = base.searchByOffline(coords, Settings.getCacheType(), listId); } else { - search = base.searchByOffline(null, null, cgList.STANDARD_LIST_ID); + search = base.searchByOffline(null, Settings.getCacheType(), cgList.STANDARD_LIST_ID); } handler.sendMessage(new Message()); } @@ -1790,7 +1782,7 @@ public class cgeocaches extends AbstractListActivity { @Override public void run() { - search = base.searchByHistory(coords != null ? Settings.getCacheType() : null); + search = base.searchByHistory(coords != null ? Settings.getCacheType() : CacheType.ALL); handler.sendMessage(new Message()); } } @@ -1815,14 +1807,12 @@ public class cgeocaches extends AbstractListActivity { final private Handler handler; final private Geopoint coords; - final private CacheType cacheType; - public geocachesLoadByCoords(final Handler handler, final Geopoint coords, final CacheType cacheType) { + public geocachesLoadByCoords(final Handler handler, final Geopoint coords) { setPriority(Thread.MIN_PRIORITY); this.handler = handler; this.coords = coords; - this.cacheType = cacheType; if (coords == null) { showToast(res.getString(R.string.warn_no_coordinates)); @@ -1844,14 +1834,12 @@ public class cgeocaches extends AbstractListActivity { final private Handler handler; final private String keyword; - final private CacheType cacheType; - public geocachesLoadByKeyword(final Handler handler, final String keyword, final CacheType cacheType) { + public geocachesLoadByKeyword(final Handler handler, final String keyword) { setPriority(Thread.MIN_PRIORITY); this.handler = handler; this.keyword = keyword; - this.cacheType = cacheType; if (keyword == null) { showToast(res.getString(R.string.warn_no_keyword)); @@ -1872,14 +1860,12 @@ public class cgeocaches extends AbstractListActivity { final private Handler handler; final private String username; - final private CacheType cacheType; - public geocachesLoadByUserName(final Handler handler, final String username, final CacheType cacheType) { + public geocachesLoadByUserName(final Handler handler, final String username) { setPriority(Thread.MIN_PRIORITY); this.handler = handler; this.username = username; - this.cacheType = cacheType; if (StringUtils.isBlank(username)) { showToast(res.getString(R.string.warn_no_username)); @@ -1900,14 +1886,12 @@ public class cgeocaches extends AbstractListActivity { final private Handler handler; final private String username; - final private CacheType cacheType; - public geocachesLoadByOwner(final Handler handler, final String username, final CacheType cacheType) { + public geocachesLoadByOwner(final Handler handler, final String username) { setPriority(Thread.MIN_PRIORITY); this.handler = handler; this.username = username; - this.cacheType = cacheType; if (StringUtils.isBlank(username)) { showToast(res.getString(R.string.warn_no_username)); @@ -1921,8 +1905,8 @@ public class cgeocaches extends AbstractListActivity { public void run() { Map<String, String> params = new HashMap<String, String>(); params.put("username", username); - if (cachetype != null) { - params.put("cachetype", cachetype.id); + if (cacheType != null) { + params.put("cacheType", cacheType.id); } search = base.searchByOwner(this, username, cacheType, 0, Settings.isShowCaptcha()); @@ -2631,27 +2615,19 @@ public class cgeocaches extends AbstractListActivity { } private void prepareFilterBar() { - TextView filterTextView = (TextView) findViewById(R.id.filter_text); - View filterBar = findViewById(R.id.filter_bar); - String cacheType = "", filter = ""; + if (Settings.getCacheType() != CacheType.ALL || adapter.isFilter()) { + String filter = ""; + String cacheType = Settings.getCacheType().getL10n(); - if (Settings.getCacheType() != null || adapter.isFilter()) { - if (Settings.getCacheType() != null) { - cacheType = cgBase.cacheTypesInv.get(Settings.getCacheType()); - } if (adapter.isFilter()) { - filter = adapter.getFilterName(); - } - - if (Settings.getCacheType() != null && adapter.isFilter()) { - filter = ", " + filter; + filter = ", " + adapter.getFilterName(); } - filterTextView.setText(cacheType + filter); - filterBar.setVisibility(View.VISIBLE); + ((TextView) findViewById(R.id.filter_text)).setText(cacheType + filter); + findViewById(R.id.filter_bar).setVisibility(View.VISIBLE); } else { - filterBar.setVisibility(View.GONE); + findViewById(R.id.filter_bar).setVisibility(View.GONE); } } diff --git a/main/src/cgeo/geocaching/cgeodetail.java b/main/src/cgeo/geocaching/cgeodetail.java index f6b46cd..7dc5a2c 100644 --- a/main/src/cgeo/geocaching/cgeodetail.java +++ b/main/src/cgeo/geocaching/cgeodetail.java @@ -7,7 +7,6 @@ import cgeo.geocaching.apps.cache.navi.NavigationAppFactory; import cgeo.geocaching.compatibility.Compatibility; import cgeo.geocaching.connector.ConnectorFactory; import cgeo.geocaching.connector.IConnector; -import cgeo.geocaching.enumerations.CacheType; import cgeo.geocaching.geopoint.GeopointFormatter; import cgeo.geocaching.geopoint.GeopointFormatter.Format; import cgeo.geocaching.network.HtmlImage; @@ -728,7 +727,7 @@ public class cgeodetail extends AbstractActivity { detailsList.removeAllViews(); // actionbar icon, default mystery - ((TextView) findViewById(R.id.actionbar_title)).setCompoundDrawablesWithIntrinsicBounds(getResources().getDrawable(cgBase.getCacheIcon(cache.getCacheType())), null, null, null); + ((TextView) findViewById(R.id.actionbar_title)).setCompoundDrawablesWithIntrinsicBounds(getResources().getDrawable(cgBase.getCacheIcon(cache.getType())), null, null, null); // cache name (full name) Spannable span = (new Spannable.Factory()).newSpannable(Html.fromHtml(cache.getName()).toString()); @@ -737,18 +736,12 @@ public class cgeodetail extends AbstractActivity { } addCacheDetail(R.string.cache_name, span); - String cacheType; // cache type - if (cgBase.cacheTypesInv.containsKey(cache.getCacheType())) { // cache icon - cacheType = cgBase.cacheTypesInv.get(cache.getCacheType()); - } else { - cacheType = cgBase.cacheTypesInv.get(CacheType.MYSTERY); // TODO: or UNKNOWN? - } - addCacheDetail(R.string.cache_type, cacheType); + addCacheDetail(R.string.cache_type, cache.getType().getL10n()); // size if (null != cache.getSize() && cache.showSize()) { - addCacheDetail(R.string.cache_size, res.getString(cache.getSize().stringId)); + addCacheDetail(R.string.cache_size, cache.getSize().getL10n()); } // gc-code @@ -1398,7 +1391,7 @@ public class cgeodetail extends AbstractActivity { try { // cache coords = new cgCoord(); - coords.setType("cache"); + coords.setCoordType("cache"); if (StringUtils.isNotBlank(name)) { coords.setName(name); } else { @@ -1416,7 +1409,7 @@ public class cgeodetail extends AbstractActivity { for (cgWaypoint waypoint : cache.getWaypoints()) { if (null != waypoint.getCoords()) { coords = new cgCoord(); - coords.setType("waypoint"); + coords.setCoordType("waypoint"); coords.setName(waypoint.getName()); coords.setCoords(waypoint.getCoords()); coordinates.add(coords); diff --git a/main/src/cgeo/geocaching/cgeoinit.java b/main/src/cgeo/geocaching/cgeoinit.java index 2c5b74f..9f271ea 100644 --- a/main/src/cgeo/geocaching/cgeoinit.java +++ b/main/src/cgeo/geocaching/cgeoinit.java @@ -3,6 +3,7 @@ package cgeo.geocaching; import cgeo.geocaching.LogTemplateProvider.LogTemplate; import cgeo.geocaching.activity.AbstractActivity; import cgeo.geocaching.compatibility.Compatibility; +import cgeo.geocaching.enumerations.CacheType; import cgeo.geocaching.enumerations.StatusCode; import cgeo.geocaching.maps.MapProviderFactory; @@ -558,7 +559,7 @@ public class cgeoinit extends AbstractActivity { */ public void backup(View view) { // avoid overwriting an existing backup with an empty database (can happen directly after reinstalling the app) - if (app.getAllStoredCachesCount(true, null, null) == 0) { + if (app.getAllStoredCachesCount(true, CacheType.ALL, null) == 0) { helpDialog(res.getString(R.string.init_backup), res.getString(R.string.init_backup_unnecessary)); return; } diff --git a/main/src/cgeo/geocaching/cgeonavigate.java b/main/src/cgeo/geocaching/cgeonavigate.java index b3b7554..fa4e917 100644 --- a/main/src/cgeo/geocaching/cgeonavigate.java +++ b/main/src/cgeo/geocaching/cgeonavigate.java @@ -216,7 +216,7 @@ public class cgeonavigate extends AbstractActivity { int cnt = 4; for (cgCoord coordinate : coordinates) { - subMenu.add(0, cnt, 0, coordinate.getName() + " (" + coordinate.getType() + ")"); + subMenu.add(0, cnt, 0, coordinate.getName() + " (" + coordinate.getCoordType() + ")"); cnt++; } diff --git a/main/src/cgeo/geocaching/cgeopopup.java b/main/src/cgeo/geocaching/cgeopopup.java index a712202..50e92ee 100644 --- a/main/src/cgeo/geocaching/cgeopopup.java +++ b/main/src/cgeo/geocaching/cgeopopup.java @@ -230,7 +230,7 @@ public class cgeopopup extends AbstractActivity { detailsList.removeAllViews(); // actionbar icon - ((TextView) findViewById(R.id.actionbar_title)).setCompoundDrawablesWithIntrinsicBounds(getResources().getDrawable(cgBase.getCacheIcon(cache.getCacheType())), null, null, null); + ((TextView) findViewById(R.id.actionbar_title)).setCompoundDrawablesWithIntrinsicBounds(getResources().getDrawable(cgBase.getCacheIcon(cache.getType())), null, null, null); // cache type itemLayout = (RelativeLayout) inflater.inflate(R.layout.cache_item, null); @@ -238,20 +238,13 @@ public class cgeopopup extends AbstractActivity { itemValue = (TextView) itemLayout.findViewById(R.id.value); itemName.setText(res.getString(R.string.cache_type)); - if (cgBase.cacheTypesInv.containsKey(cache.getCacheType())) { // cache icon - if (cache.getSize() != null) { - itemValue.setText(cgBase.cacheTypesInv.get(cache.getCacheType()) - + " (" + res.getString(cache.getSize().stringId) + ")"); - } else { - itemValue.setText(cgBase.cacheTypesInv.get(cache.getCacheType())); - } + + String cacheType = cache.getType() != CacheType.UNKNOWN ? cache.getType().getL10n() : CacheType.MYSTERY.getL10n(); + if (cache.getSize() != null) { + itemValue.setText(cacheType + + " (" + cache.getSize().getL10n() + ")"); } else { - if (cache.getSize() != null) { - itemValue.setText(cgBase.cacheTypesInv.get(CacheType.MYSTERY) - + " (" + res.getString(cache.getSize().stringId) + ")"); - } else { - itemValue.setText(cgBase.cacheTypesInv.get(CacheType.MYSTERY)); - } + itemValue.setText(cacheType); } detailsList.addView(itemLayout); diff --git a/main/src/cgeo/geocaching/connector/GCConnector.java b/main/src/cgeo/geocaching/connector/GCConnector.java index 8419e56..9ba57c1 100644 --- a/main/src/cgeo/geocaching/connector/GCConnector.java +++ b/main/src/cgeo/geocaching/connector/GCConnector.java @@ -129,7 +129,7 @@ public class GCConnector extends AbstractConnector { return null; } - final List<cgCache> cacheList = cgBase.filterSearchResults(search, caches, false, false, null); + final List<cgCache> cacheList = cgBase.filterSearchResults(search, caches, false, false, Settings.getCacheType()); app.addSearch(cacheList, reason); return search; diff --git a/main/src/cgeo/geocaching/connector/opencaching/ApiOpenCachingConnector.java b/main/src/cgeo/geocaching/connector/opencaching/ApiOpenCachingConnector.java index f4c8c14..cbb11a2 100644 --- a/main/src/cgeo/geocaching/connector/opencaching/ApiOpenCachingConnector.java +++ b/main/src/cgeo/geocaching/connector/opencaching/ApiOpenCachingConnector.java @@ -1,6 +1,7 @@ package cgeo.geocaching.connector.opencaching; import cgeo.geocaching.Parameters; +import cgeo.geocaching.Settings; import cgeo.geocaching.cgBase; import cgeo.geocaching.cgCache; import cgeo.geocaching.cgCacheWrap; @@ -44,7 +45,7 @@ public class ApiOpenCachingConnector extends OpenCachingConnector { final cgCacheWrap caches = new cgCacheWrap(); caches.cacheList.add(cache); - final List<cgCache> cacheList = cgBase.filterSearchResults(search, caches, false, false, null); + final List<cgCache> cacheList = cgBase.filterSearchResults(search, caches, false, false, Settings.getCacheType()); app.addSearch(cacheList, reason); return search; diff --git a/main/src/cgeo/geocaching/connector/opencaching/OkapiClient.java b/main/src/cgeo/geocaching/connector/opencaching/OkapiClient.java index c1d4586..e12e78f 100644 --- a/main/src/cgeo/geocaching/connector/opencaching/OkapiClient.java +++ b/main/src/cgeo/geocaching/connector/opencaching/OkapiClient.java @@ -82,7 +82,7 @@ final public class OkapiClient { cache.setName(response.getString(CACHE_NAME)); // not used: names setLocation(cache, response.getString(CACHE_LOCATION)); - cache.setCacheType(getCacheType(response.getString(CACHE_TYPE))); + cache.setType(getCacheType(response.getString(CACHE_TYPE))); final String status = response.getString(CACHE_STATUS); cache.setDisabled(status.equalsIgnoreCase("Temporarily unavailable")); @@ -234,14 +234,14 @@ final public class OkapiClient { return CacheSize.NOT_CHOSEN; } - private static CacheType getCacheType(final String type) { - if (type.equalsIgnoreCase("Traditional")) { + private static CacheType getCacheType(final String cacheType) { + if (cacheType.equalsIgnoreCase("Traditional")) { return CacheType.TRADITIONAL; - } else if (type.equalsIgnoreCase("Multi")) { + } else if (cacheType.equalsIgnoreCase("Multi")) { return CacheType.MULTI; - } else if (type.equalsIgnoreCase("Quiz")) { + } else if (cacheType.equalsIgnoreCase("Quiz")) { return CacheType.MYSTERY; - } else if (type.equalsIgnoreCase("Virtual")) { + } else if (cacheType.equalsIgnoreCase("Virtual")) { return CacheType.VIRTUAL; } return CacheType.UNKNOWN; diff --git a/main/src/cgeo/geocaching/enumerations/CacheSize.java b/main/src/cgeo/geocaching/enumerations/CacheSize.java index b690b7c..c831dda 100644 --- a/main/src/cgeo/geocaching/enumerations/CacheSize.java +++ b/main/src/cgeo/geocaching/enumerations/CacheSize.java @@ -1,6 +1,7 @@ package cgeo.geocaching.enumerations; import cgeo.geocaching.R; +import cgeo.geocaching.cgeoapplication; import java.util.Collections; import java.util.HashMap; @@ -8,7 +9,7 @@ import java.util.Map; /** * Enum listing cache sizes - * + * * @author koem */ public enum CacheSize { @@ -18,19 +19,20 @@ public enum CacheSize { LARGE("large", 4, R.string.cache_size_large), VIRTUAL("virtual", 0, R.string.cache_size_virtual), NOT_CHOSEN("not chosen", 0, R.string.cache_size_notchosen), - OTHER("other", 0, R.string.cache_size_other); + OTHER("other", 0, R.string.cache_size_other), + UNKNOWN("unknown", 0, R.string.unknown); public final String id; public final int comparable; - public final int stringId; + private final String l10n; private CacheSize(String id, int comparable, int stringId) { this.id = id; this.comparable = comparable; - this.stringId = stringId; + this.l10n = cgeoapplication.getInstance().getBaseContext().getResources().getString(stringId); } - final public static Map<String, CacheSize> FIND_BY_ID; + final private static Map<String, CacheSize> FIND_BY_ID; static { final HashMap<String, CacheSize> mapping = new HashMap<String, CacheSize>(); for (CacheSize cs : values()) { @@ -39,4 +41,17 @@ public enum CacheSize { FIND_BY_ID = Collections.unmodifiableMap(mapping); } + public final static CacheSize getById(final String id) { + final CacheSize result = id != null ? CacheSize.FIND_BY_ID.get(id.toLowerCase().trim()) : null; + if (result == null) { + return UNKNOWN; + } + return result; + } + + public final String getL10n() { + return l10n; + } + } + diff --git a/main/src/cgeo/geocaching/enumerations/CacheType.java b/main/src/cgeo/geocaching/enumerations/CacheType.java index ccea7c8..455d03b 100644 --- a/main/src/cgeo/geocaching/enumerations/CacheType.java +++ b/main/src/cgeo/geocaching/enumerations/CacheType.java @@ -1,6 +1,7 @@ package cgeo.geocaching.enumerations; import cgeo.geocaching.R; +import cgeo.geocaching.cgeoapplication; import java.util.Collections; import java.util.HashMap; @@ -8,7 +9,7 @@ import java.util.Map; /** * Enum listing all cache types - * + * * @author koem */ public enum CacheType { @@ -27,18 +28,20 @@ public enum CacheType { PROJECT_APE("ape", "project ape cache", "2555690d-b2bc-4b55-b5ac-0cb704c0b768", R.string.ape), GCHQ("gchq", "groundspeak hq", "416f2494-dc17-4b6a-9bab-1a29dd292d8c", R.string.gchq), GPS_EXHIBIT("gps", "gps cache exhibit", "72e69af2-7986-4990-afd9-bc16cbbb4ce3", R.string.gps), - UNKNOWN("unknown", "unknown", "", R.string.unknown); + UNKNOWN("unknown", "unknown", "", R.string.unknown), + /** No real cache type -> filter */ + ALL("all", "display all caches", "9a79e6ce-3344-409c-bbe9-496530baf758", R.string.all_types); public final String id; public final String pattern; public final String guid; - public final int stringId; + private final String l10n; private CacheType(String id, String pattern, String guid, int stringId) { this.id = id; this.pattern = pattern; this.guid = guid; - this.stringId = stringId; + this.l10n = cgeoapplication.getInstance().getBaseContext().getResources().getString(stringId); } private final static Map<String, CacheType> FIND_BY_ID; @@ -55,10 +58,7 @@ public enum CacheType { } public final static CacheType getById(final String id) { - if (id == null) { - return UNKNOWN; - } - final CacheType result = CacheType.FIND_BY_ID.get(id.toLowerCase().trim()); + final CacheType result = id != null ? CacheType.FIND_BY_ID.get(id.toLowerCase().trim()) : null; if (result == null) { return UNKNOWN; } @@ -73,5 +73,8 @@ public enum CacheType { return result; } - final public static String ALL_GUID = "9a79e6ce-3344-409c-bbe9-496530baf758"; -} + public final String getL10n() { + return l10n; + } + +}
\ No newline at end of file diff --git a/main/src/cgeo/geocaching/files/GPXParser.java b/main/src/cgeo/geocaching/files/GPXParser.java index d08b2d3..ae6d093 100644 --- a/main/src/cgeo/geocaching/files/GPXParser.java +++ b/main/src/cgeo/geocaching/files/GPXParser.java @@ -483,7 +483,7 @@ public abstract class GPXParser extends FileParser { @Override public void end(String body) { - cache.setCacheType(CacheType.getByPattern(validate(body.toLowerCase()))); + cache.setType(CacheType.getByPattern(validate(body.toLowerCase()))); } }); @@ -492,7 +492,7 @@ public abstract class GPXParser extends FileParser { @Override public void end(String body) { - cache.setSize(CacheSize.FIND_BY_ID.get(validate(body.toLowerCase()))); + cache.setSize(CacheSize.getById(validate(body.toLowerCase()))); } }); diff --git a/main/src/cgeo/geocaching/files/LocParser.java b/main/src/cgeo/geocaching/files/LocParser.java index 90a6c50..14acbf6 100644 --- a/main/src/cgeo/geocaching/files/LocParser.java +++ b/main/src/cgeo/geocaching/files/LocParser.java @@ -160,7 +160,7 @@ public final class LocParser extends FileParser { caches.add(cache); fixCache(cache); - cache.setCacheType(CacheType.UNKNOWN); // type is not given in the LOC file + cache.setType(CacheType.UNKNOWN); // type is not given in the LOC file cache.setReason(listId); cache.setDetailed(true); } diff --git a/main/src/cgeo/geocaching/filter/cgFilterBySize.java b/main/src/cgeo/geocaching/filter/cgFilterBySize.java index dcb9875..eb754c6 100644 --- a/main/src/cgeo/geocaching/filter/cgFilterBySize.java +++ b/main/src/cgeo/geocaching/filter/cgFilterBySize.java @@ -1,24 +1,23 @@ package cgeo.geocaching.filter; -import cgeo.geocaching.cgBase; import cgeo.geocaching.cgCache; import cgeo.geocaching.enumerations.CacheSize; public class cgFilterBySize extends cgFilter { - private final CacheSize size; + private final CacheSize cacheSize; - public cgFilterBySize(CacheSize size) { - super(size.id); - this.size = size; + public cgFilterBySize(CacheSize cacheSize) { + super(cacheSize.id); + this.cacheSize = cacheSize; } @Override boolean applyFilter(cgCache cache) { - return this.size == cache.getSize(); + return this.cacheSize == cache.getSize(); } @Override public String getFilterName() { - return cgBase.cacheSizesInv.get(this.size); + return this.cacheSize.getL10n(); } } diff --git a/main/src/cgeo/geocaching/filter/cgFilterByType.java b/main/src/cgeo/geocaching/filter/cgFilterByType.java index 2a021d0..2200c0d 100644 --- a/main/src/cgeo/geocaching/filter/cgFilterByType.java +++ b/main/src/cgeo/geocaching/filter/cgFilterByType.java @@ -1,6 +1,5 @@ package cgeo.geocaching.filter; -import cgeo.geocaching.cgBase; import cgeo.geocaching.cgCache; import cgeo.geocaching.enumerations.CacheType; @@ -14,11 +13,11 @@ public class cgFilterByType extends cgFilter { @Override boolean applyFilter(final cgCache cache) { - return cacheType == cache.getCacheType(); + return cacheType == cache.getType(); } @Override public String getFilterName() { - return cgBase.cacheTypesInv.get(cacheType.id); + return this.cacheType.getL10n(); } } diff --git a/main/src/cgeo/geocaching/maps/CGeoMap.java b/main/src/cgeo/geocaching/maps/CGeoMap.java index ea6b19e..5aad403 100644 --- a/main/src/cgeo/geocaching/maps/CGeoMap.java +++ b/main/src/cgeo/geocaching/maps/CGeoMap.java @@ -399,11 +399,17 @@ public class CGeoMap extends AbstractMap implements OnDragListener, ViewFactory // removed startTimer since onResume is always called + prepareFilterBar(); + } + + private void prepareFilterBar() { // show the filter warning bar if the filter is set - if (Settings.getCacheType() != null) { - String cacheType = cgBase.cacheTypesInv.get(Settings.getCacheType()); + if (Settings.getCacheType() != CacheType.ALL) { + String cacheType = Settings.getCacheType().getL10n(); ((TextView) activity.findViewById(R.id.filter_text)).setText(cacheType); activity.findViewById(R.id.filter_bar).setVisibility(View.VISIBLE); + } else { + activity.findViewById(R.id.filter_bar).setVisibility(View.GONE); } } @@ -1344,7 +1350,7 @@ public class CGeoMap extends AbstractMap implements OnDragListener, ViewFactory items.add(getWaypointItem(new cgCoord(oneWaypoint), oneWaypoint.getWaypointType())); } } - items.add(getCacheItem(new cgCoord(cacheOne), cacheOne.getCacheType(), cacheOne.isOwn(), cacheOne.isFound(), cacheOne.isDisabled())); + items.add(getCacheItem(new cgCoord(cacheOne), cacheOne.getType(), cacheOne.isOwn(), cacheOne.isFound(), cacheOne.isDisabled())); } overlayCaches.updateItems(items); @@ -1544,7 +1550,7 @@ public class CGeoMap extends AbstractMap implements OnDragListener, ViewFactory if (coordsIntent != null) { final cgCoord coord = new cgCoord(); - coord.setType("waypoint"); + coord.setCoordType("waypoint"); coord.setCoords(coordsIntent); coord.setName("some place"); diff --git a/main/src/cgeo/geocaching/maps/CachesOverlay.java b/main/src/cgeo/geocaching/maps/CachesOverlay.java index 52800b9..240afa4 100644 --- a/main/src/cgeo/geocaching/maps/CachesOverlay.java +++ b/main/src/cgeo/geocaching/maps/CachesOverlay.java @@ -212,14 +212,14 @@ public class CachesOverlay extends AbstractItemizedOverlay { cgCoord coordinate = item.getCoord(); - if (StringUtils.isNotBlank(coordinate.getType()) && coordinate.getType().equalsIgnoreCase("cache") && StringUtils.isNotBlank(coordinate.getGeocode())) { + if (StringUtils.isNotBlank(coordinate.getCoordType()) && coordinate.getCoordType().equalsIgnoreCase("cache") && StringUtils.isNotBlank(coordinate.getGeocode())) { Intent popupIntent = new Intent(context, cgeopopup.class); popupIntent.putExtra("fromdetail", fromDetail); popupIntent.putExtra("geocode", coordinate.getGeocode()); context.startActivity(popupIntent); - } else if (coordinate.getType() != null && coordinate.getType().equalsIgnoreCase("waypoint") && coordinate.getId() != null && coordinate.getId() > 0) { + } else if (coordinate.getCoordType() != null && coordinate.getCoordType().equalsIgnoreCase("waypoint") && coordinate.getId() != null && coordinate.getId() > 0) { Intent popupIntent = new Intent(context, cgeowaypoint.class); popupIntent.putExtra("waypoint", coordinate.getId()); @@ -275,15 +275,11 @@ public class CachesOverlay extends AbstractItemizedOverlay { AlertDialog.Builder dialog = new AlertDialog.Builder(context); dialog.setCancelable(true); - if (coordinate.getType().equalsIgnoreCase("cache")) { + if (coordinate.getCoordType().equalsIgnoreCase("cache")) { dialog.setTitle("cache"); - String cacheType; - if (cgBase.cacheTypesInv.containsKey(coordinate.getTypeSpec())) { - cacheType = cgBase.cacheTypesInv.get(CacheType.getById(coordinate.getTypeSpec())); - } else { - cacheType = cgBase.cacheTypesInv.get(CacheType.MYSTERY); - } + CacheType ct = CacheType.getById(coordinate.getTypeSpec()); + String cacheType = CacheType.UNKNOWN != ct ? ct.getL10n() : CacheType.MYSTERY.getL10n(); dialog.setMessage(Html.fromHtml(item.getTitle()) + "\n\ngeocode: " + coordinate.getGeocode().toUpperCase() + "\ntype: " + cacheType); if (fromDetail) { |