diff options
author | Bananeweizen <Bananeweizen@gmx.de> | 2012-08-19 08:14:37 +0200 |
---|---|---|
committer | Bananeweizen <Bananeweizen@gmx.de> | 2012-08-19 11:47:17 +0200 |
commit | 59a962c3c92bba382295b3b7df055d18bed3e827 (patch) | |
tree | 4798ac36fc48262e4aa6adf49ddad47a74e04a59 /main/src | |
parent | b95a66609cef2ae0e80514702385f9333d8be929 (diff) | |
download | cgeo-59a962c3c92bba382295b3b7df055d18bed3e827.zip cgeo-59a962c3c92bba382295b3b7df055d18bed3e827.tar.gz cgeo-59a962c3c92bba382295b3b7df055d18bed3e827.tar.bz2 |
fix #1963: Include "Cache Beacon" in apps
Diffstat (limited to 'main/src')
4 files changed, 49 insertions, 2 deletions
diff --git a/main/src/cgeo/geocaching/apps/cache/CacheBeaconApp.java b/main/src/cgeo/geocaching/apps/cache/CacheBeaconApp.java new file mode 100644 index 0000000..6e7cdca --- /dev/null +++ b/main/src/cgeo/geocaching/apps/cache/CacheBeaconApp.java @@ -0,0 +1,21 @@ +package cgeo.geocaching.apps.cache; + +import cgeo.geocaching.R; +import cgeo.geocaching.cgCache; +import cgeo.geocaching.enumerations.CacheAttribute; + +public class CacheBeaconApp extends AbstractGeneralApp { + + protected CacheBeaconApp() { + super(getString(R.string.cache_menu_cachebeacon), "de.fun2code.android.cachebeacon"); + } + + @Override + public boolean isEnabled(cgCache cache) { + if (cache == null) { + return false; + } + return cache.hasAttribute(CacheAttribute.WIRELESS_BEACON, true); + } + +} diff --git a/main/src/cgeo/geocaching/apps/cache/GeneralAppsFactory.java b/main/src/cgeo/geocaching/apps/cache/GeneralAppsFactory.java index 98e7db8..57eb957 100644 --- a/main/src/cgeo/geocaching/apps/cache/GeneralAppsFactory.java +++ b/main/src/cgeo/geocaching/apps/cache/GeneralAppsFactory.java @@ -15,8 +15,11 @@ public final class GeneralAppsFactory extends AbstractAppFactory { private static GeneralApp[] getGeneralApps() { if (ArrayUtils.isEmpty(apps)) { - apps = new GeneralApp[] { new GccApp(), - new WhereYouGoApp() }; + apps = new GeneralApp[] { + new CacheBeaconApp(), + new GccApp(), + new WhereYouGoApp() + }; } return apps; } diff --git a/main/src/cgeo/geocaching/cgCache.java b/main/src/cgeo/geocaching/cgCache.java index b8590e5..cd4e15c 100644 --- a/main/src/cgeo/geocaching/cgCache.java +++ b/main/src/cgeo/geocaching/cgCache.java @@ -10,9 +10,11 @@ import cgeo.geocaching.connector.capability.ISearchByGeocode; import cgeo.geocaching.connector.gc.GCConnector; import cgeo.geocaching.connector.gc.GCConstants; import cgeo.geocaching.connector.gc.Tile; +import cgeo.geocaching.enumerations.CacheAttribute; import cgeo.geocaching.enumerations.CacheSize; import cgeo.geocaching.enumerations.CacheType; import cgeo.geocaching.enumerations.LoadFlags; +import cgeo.geocaching.enumerations.LoadFlags.LoadFlag; import cgeo.geocaching.enumerations.LoadFlags.RemoveFlag; import cgeo.geocaching.enumerations.LoadFlags.SaveFlag; import cgeo.geocaching.enumerations.LogType; @@ -1591,4 +1593,21 @@ public class cgCache implements ICache, IWaypoint { } return null; } + + /** + * check whether the cache has a given attribute + * + * @param attribute + * @param yes + * true if we are looking for the attribute_yes version, false for the attribute_no version + * @return + */ + public boolean hasAttribute(CacheAttribute attribute, boolean yes) { + // lazy loading of attributes + cgCache fullCache = cgeoapplication.getInstance().loadCache(getGeocode(), EnumSet.of(LoadFlag.LOAD_ATTRIBUTES)); + if (fullCache == null) { + fullCache = this; + } + return fullCache.getAttributes().contains(attribute.getAttributeName(yes)); + } }
\ No newline at end of file diff --git a/main/src/cgeo/geocaching/enumerations/CacheAttribute.java b/main/src/cgeo/geocaching/enumerations/CacheAttribute.java index 6456f71..a31b0cc 100644 --- a/main/src/cgeo/geocaching/enumerations/CacheAttribute.java +++ b/main/src/cgeo/geocaching/enumerations/CacheAttribute.java @@ -137,4 +137,8 @@ public enum CacheAttribute { public static boolean isEnabled(final String attributeName) { return !StringUtils.endsWithIgnoreCase(attributeName, INTERNAL_NO); } + + public String getAttributeName(final boolean yes) { + return gcRawName + (yes ? INTERNAL_YES : INTERNAL_NO); + } } |