Beispiel #1
0
  private static void parseCoreCache(final ObjectNode response, final Geocache cache) {
    cache.setGeocode(response.get(CACHE_CODE).asText());
    cache.setName(response.get(CACHE_NAME).asText());
    // not used: names
    setLocation(cache, response.get(CACHE_LOCATION).asText());
    cache.setType(getCacheType(response.get(CACHE_TYPE).asText()));

    final String status = response.get(CACHE_STATUS).asText();
    cache.setDisabled(status.equalsIgnoreCase(CACHE_STATUS_DISABLED));
    cache.setArchived(status.equalsIgnoreCase(CACHE_STATUS_ARCHIVED));

    cache.setSize(getCacheSize(response));
    cache.setDifficulty((float) response.get(CACHE_DIFFICULTY).asDouble());
    cache.setTerrain((float) response.get(CACHE_TERRAIN).asDouble());

    cache.setInventoryItems(response.get(CACHE_TRACKABLES_COUNT).asInt());

    if (response.has(CACHE_IS_FOUND)) {
      cache.setFound(response.get(CACHE_IS_FOUND).asBoolean());
    }
    cache.setHidden(parseDate(response.get(CACHE_HIDDEN).asText()));
  }
Beispiel #2
0
  private static Geocache parseCache(final JSONObject response) {
    final Geocache cache = new Geocache();
    cache.setReliableLatLon(true);
    try {

      parseCoreCache(response, cache);

      // not used: url
      final JSONObject owner = response.getJSONObject(CACHE_OWNER);
      cache.setOwnerDisplayName(parseUser(owner));

      cache.getLogCounts().put(LogType.FOUND_IT, response.getInt(CACHE_FOUNDS));
      cache.getLogCounts().put(LogType.DIDNT_FIND_IT, response.getInt(CACHE_NOTFOUNDS));

      if (!response.isNull(CACHE_RATING)) {
        cache.setRating((float) response.getDouble(CACHE_RATING));
      }
      cache.setVotes(response.getInt(CACHE_VOTES));

      cache.setFavoritePoints(response.getInt(CACHE_RECOMMENDATIONS));
      // not used: req_password
      // Prepend gc-link to description if available
      final StringBuilder description = new StringBuilder(500);
      if (!response.isNull("gc_code")) {
        final String gccode = response.getString("gc_code");
        description
            .append(
                cgeoapplication
                    .getInstance()
                    .getResources()
                    .getString(R.string.cache_listed_on, GCConnector.getInstance().getName()))
            .append(": <a href=\"http://coord.info/")
            .append(gccode)
            .append("\">")
            .append(gccode)
            .append("</a><br /><br />");
      }
      description.append(response.getString(CACHE_DESCRIPTION));
      cache.setDescription(description.toString());

      // currently the hint is delivered as HTML (contrary to OKAPI documentation), so we can store
      // it directly
      cache.setHint(response.getString(CACHE_HINT));
      // not used: hints

      final JSONArray images = response.getJSONArray(CACHE_IMAGES);
      if (images != null) {
        for (int i = 0; i < images.length(); i++) {
          final JSONObject imageResponse = images.getJSONObject(i);
          if (imageResponse.getBoolean(CACHE_IMAGE_IS_SPOILER)) {
            final String title = imageResponse.getString(CACHE_IMAGE_CAPTION);
            final String url =
                absoluteUrl(imageResponse.getString(CACHE_IMAGE_URL), cache.getGeocode());
            cache.addSpoiler(new Image(url, title));
          }
        }
      }

      cache.setAttributes(parseAttributes(response.getJSONArray(CACHE_ATTRNAMES)));
      cache.setLogs(parseLogs(response.getJSONArray(CACHE_LATEST_LOGS)));
      cache.setHidden(parseDate(response.getString(CACHE_HIDDEN)));
      // TODO: Store license per cache
      // cache.setLicense(response.getString("attribution_note"));
      cache.setWaypoints(parseWaypoints(response.getJSONArray(CACHE_WPTS)), false);
      if (!response.isNull(CACHE_IS_WATCHED)) {
        cache.setOnWatchlist(response.getBoolean(CACHE_IS_WATCHED));
      }
      if (!response.isNull(CACHE_MY_NOTES)) {
        cache.setPersonalNote(response.getString(CACHE_MY_NOTES));
      }
      cache.setLogPasswordRequired(response.getBoolean(CACHE_REQ_PASSWORD));

      cache.setDetailedUpdatedNow();
      // save full detailed caches
      cgData.saveCache(cache, EnumSet.of(SaveFlag.SAVE_DB));
    } catch (final JSONException e) {
      Log.e("OkapiClient.parseCache", e);
    }
    return cache;
  }