diff options
Diffstat (limited to 'main/src/cgeo/geocaching/connector/oc/OkapiClient.java')
| -rw-r--r-- | main/src/cgeo/geocaching/connector/oc/OkapiClient.java | 44 |
1 files changed, 26 insertions, 18 deletions
diff --git a/main/src/cgeo/geocaching/connector/oc/OkapiClient.java b/main/src/cgeo/geocaching/connector/oc/OkapiClient.java index 2175935..3ae4e97 100644 --- a/main/src/cgeo/geocaching/connector/oc/OkapiClient.java +++ b/main/src/cgeo/geocaching/connector/oc/OkapiClient.java @@ -34,7 +34,6 @@ import cgeo.geocaching.utils.SynchronizedDateFormat; import ch.boye.httpclientandroidlib.HttpResponse; import org.apache.commons.lang3.StringUtils; -import org.apache.commons.lang3.time.FastDateFormat; import org.apache.commons.lang3.tuple.ImmutablePair; import org.eclipse.jdt.annotation.NonNull; import org.eclipse.jdt.annotation.Nullable; @@ -61,7 +60,7 @@ final class OkapiClient { private static final char SEPARATOR = '|'; private static final String SEPARATOR_STRING = Character.toString(SEPARATOR); - private static final FastDateFormat LOG_DATE_FORMAT = FastDateFormat.getInstance("yyyy-MM-dd HH:mm:ss.SSSZ", TimeZone.getTimeZone("UTC"), Locale.US); + private static final SynchronizedDateFormat LOG_DATE_FORMAT = new SynchronizedDateFormat("yyyy-MM-dd HH:mm:ss.SSSZ", TimeZone.getTimeZone("UTC"), Locale.US); private static final SynchronizedDateFormat ISO8601DATEFORMAT = new SynchronizedDateFormat("yyyy-MM-dd'T'HH:mm:ssZ", Locale.getDefault()); private static final String CACHE_ATTRNAMES = "attrnames"; @@ -75,7 +74,8 @@ final class OkapiClient { private static final String CACHE_STATUS_ARCHIVED = "Archived"; private static final String CACHE_STATUS_DISABLED = "Temporarily unavailable"; private static final String CACHE_IS_FOUND = "is_found"; - private static final String CACHE_SIZE = "size"; + private static final String CACHE_SIZE_DEPRECATED = "size"; + private static final String CACHE_SIZE2 = "size2"; private static final String CACHE_VOTES = "rating_votes"; private static final String CACHE_NOTFOUNDS = "notfounds"; private static final String CACHE_FOUNDS = "founds"; @@ -112,7 +112,7 @@ final class OkapiClient { // the several realms of possible fields for cache retrieval: // Core: for livemap requests (L3 - only with level 3 auth) // Additional: additional fields for full cache (L3 - only for level 3 auth, current - only for connectors with current api) - private static final String SERVICE_CACHE_CORE_FIELDS = "code|name|location|type|status|difficulty|terrain|size|date_hidden"; + private static final String SERVICE_CACHE_CORE_FIELDS = "code|name|location|type|status|difficulty|terrain|size|size2|date_hidden"; private static final String SERVICE_CACHE_CORE_L3_FIELDS = "is_found"; private static final String SERVICE_CACHE_ADDITIONAL_FIELDS = "owner|founds|notfounds|rating|rating_votes|recommendations|description|hint|images|latest_logs|alt_wpts|attrnames|req_passwd"; private static final String SERVICE_CACHE_ADDITIONAL_CURRENT_FIELDS = "gc_code|attribution_note|attr_acodes"; @@ -152,19 +152,14 @@ final class OkapiClient { } public static List<Geocache> getCachesByOwner(final String username, final OCApiConnector connector) { - final Parameters params = new Parameters("search_method", METHOD_SEARCH_ALL); - final Map<String, String> valueMap = new LinkedHashMap<String, String>(); - final @Nullable - String uuid = getUserUUID(connector, username); - if (StringUtils.isEmpty(uuid)) { - return Collections.emptyList(); - } - valueMap.put("owner_uuid", uuid); - - return requestCaches(connector, params, valueMap); + return getCachesByUser(username, connector, "owner_uuid"); } public static List<Geocache> getCachesByFinder(final String username, final OCApiConnector connector) { + return getCachesByUser(username, connector, "found_by"); + } + + private static List<Geocache> getCachesByUser(final String username, final OCApiConnector connector, final String userRequestParam) { final Parameters params = new Parameters("search_method", METHOD_SEARCH_ALL); final Map<String, String> valueMap = new LinkedHashMap<String, String>(); final @Nullable @@ -172,7 +167,7 @@ final class OkapiClient { if (StringUtils.isEmpty(uuid)) { return Collections.emptyList(); } - valueMap.put("found_by", uuid); + valueMap.put(userRequestParam, uuid); return requestCaches(connector, params, valueMap); } @@ -567,12 +562,25 @@ final class OkapiClient { } private static CacheSize getCacheSize(final JSONObject response) { - if (response.isNull(CACHE_SIZE)) { + if (response.isNull(CACHE_SIZE2)) { + return getCacheSizeDeprecated(response); + } + try { + final String size = response.getString(CACHE_SIZE2); + return CacheSize.getById(size); + } catch (JSONException e) { + Log.e("OkapiClient.getCacheSize", e); + return getCacheSizeDeprecated(response); + } + } + + private static CacheSize getCacheSizeDeprecated(final JSONObject response) { + if (response.isNull(CACHE_SIZE_DEPRECATED)) { return CacheSize.NOT_CHOSEN; } double size = 0; try { - size = response.getDouble(CACHE_SIZE); + size = response.getDouble(CACHE_SIZE_DEPRECATED); } catch (final JSONException e) { Log.e("OkapiClient.getCacheSize", e); } @@ -586,7 +594,7 @@ final class OkapiClient { case 4: return CacheSize.LARGE; case 5: - return CacheSize.LARGE; + return CacheSize.VERY_LARGE; default: break; } |
