Exemplo n.º 1
0
  /**
   * @param excludeDisabled
   * @param excludeMine
   * @param cacheType
   * @return
   */
  public SearchResult filterSearchResults(
      final boolean excludeDisabled, final boolean excludeMine, final CacheType cacheType) {

    SearchResult result = new SearchResult(this);
    result.geocodes.clear();
    final ArrayList<Geocache> includedCaches = new ArrayList<Geocache>();
    final Set<Geocache> caches = DataStore.loadCaches(geocodes, LoadFlags.LOAD_CACHE_OR_DB);
    int excluded = 0;
    for (Geocache cache : caches) {
      // Is there any reason to exclude the cache from the list?
      final boolean excludeCache =
          (excludeDisabled && cache.isDisabled())
              || (excludeMine && (cache.isOwner() || cache.isFound()))
              || (!cacheType.contains(cache));
      if (excludeCache) {
        excluded++;
      } else {
        includedCaches.add(cache);
      }
    }
    result.addAndPutInCache(includedCaches);
    // decrease maximum number of caches by filtered ones
    result.setTotalCountGC(result.getTotalCountGC() - excluded);
    GCVote.loadRatings(includedCaches);
    return result;
  }
  public CacheListAdapter(
      final Activity activity, final List<cgCache> list, CacheListType cacheListType) {
    super(activity, 0, list);

    this.res = activity.getResources();
    this.list = list;
    this.cacheListType = cacheListType;
    if (cacheListType == CacheListType.HISTORY) {
      cacheComparator = new VisitComparator();
    }

    final DisplayMetrics metrics = new DisplayMetrics();
    activity.getWindowManager().getDefaultDisplay().getMetrics(metrics);
    pixelDensity = metrics.density;

    for (final CacheType cacheType : CacheType.values()) {
      gcIconDrawables.put(
          cacheType, activity.getResources().getDrawable(cgBase.getCacheIcon(cacheType)));
    }

    if (Settings.isLightSkin()) {
      ratingBcgs[0] = R.drawable.favourite_background_red_light;
      ratingBcgs[1] = R.drawable.favourite_background_orange_light;
      ratingBcgs[2] = R.drawable.favourite_background_green_light;
    } else {
      ratingBcgs[0] = R.drawable.favourite_background_red_dark;
      ratingBcgs[1] = R.drawable.favourite_background_orange_dark;
      ratingBcgs[2] = R.drawable.favourite_background_green_dark;
    }
  }
Exemplo n.º 3
0
  protected void selectGlobalTypeFilter() {
    final List<CacheType> cacheTypes = new ArrayList<CacheType>();

    // first add the most used types
    cacheTypes.add(CacheType.ALL);
    cacheTypes.add(CacheType.TRADITIONAL);
    cacheTypes.add(CacheType.MULTI);
    cacheTypes.add(CacheType.MYSTERY);

    // then add all other cache types sorted alphabetically
    final List<CacheType> sorted = new ArrayList<CacheType>();
    sorted.addAll(Arrays.asList(CacheType.values()));
    sorted.removeAll(cacheTypes);

    Collections.sort(
        sorted,
        new Comparator<CacheType>() {

          @Override
          public int compare(final CacheType left, final CacheType right) {
            return left.getL10n().compareToIgnoreCase(right.getL10n());
          }
        });

    cacheTypes.addAll(sorted);

    int checkedItem = cacheTypes.indexOf(Settings.getCacheType());
    if (checkedItem < 0) {
      checkedItem = 0;
    }

    final String[] items = new String[cacheTypes.size()];
    for (int i = 0; i < cacheTypes.size(); i++) {
      items[i] = cacheTypes.get(i).getL10n();
    }

    final Builder builder = new AlertDialog.Builder(this);
    builder.setTitle(R.string.menu_filter);
    builder.setSingleChoiceItems(
        items,
        checkedItem,
        new DialogInterface.OnClickListener() {

          @Override
          public void onClick(final DialogInterface dialog, final int position) {
            final CacheType cacheType = cacheTypes.get(position);
            Settings.setCacheType(cacheType);
            setFilterTitle();
            dialog.dismiss();
          }
        });
    builder.create().show();
  }
Exemplo n.º 4
0
 @Override
 @NonNull
 public List<IFilter> getFilters() {
   final CacheType[] types = CacheType.values();
   final List<IFilter> filters = new LinkedList<>();
   for (final CacheType cacheType : types) {
     if (cacheType != CacheType.ALL) {
       filters.add(new TypeFilter(cacheType));
     }
   }
   return filters;
 }
 public static void testGetById() {
   assertEquals(CacheType.UNKNOWN, CacheType.getById(""));
   assertEquals(CacheType.UNKNOWN, CacheType.getById(null));
   assertEquals(CacheType.UNKNOWN, CacheType.getById("random garbage"));
   assertEquals(CacheType.WHERIGO, CacheType.getById("wherigo"));
 }
 public static void testGetByPattern() {
   assertEquals(CacheType.UNKNOWN, CacheType.getByPattern(""));
   assertEquals(CacheType.UNKNOWN, CacheType.getByPattern(null));
   assertEquals(CacheType.UNKNOWN, CacheType.getByPattern("random garbage"));
   assertEquals(CacheType.CITO, CacheType.getByPattern("cache in trash out event"));
 }
Exemplo n.º 7
0
 @Override
 public void writeToParcel(final Parcel dest, final int flags) {
   super.writeToParcel(dest, flags);
   dest.writeInt(cacheType.ordinal());
 }
Exemplo n.º 8
0
 @Override
 @NonNull
 public String getName() {
   return cacheType.getL10n();
 }
Exemplo n.º 9
0
 protected TypeFilter(final Parcel in) {
   super(in);
   cacheType = CacheType.values()[in.readInt()];
 }
Exemplo n.º 10
0
  public static SearchResult searchByGeocodes(final Set<String> geocodes) {
    final SearchResult result = new SearchResult();

    final Set<String> filteredGeocodes = GCConnector.getInstance().handledGeocodes(geocodes);
    if (filteredGeocodes.isEmpty()) {
      return result;
    }
    final String geocodeList = StringUtils.join(filteredGeocodes.toArray(), "|");

    try {
      final Parameters params =
          new Parameters("i", geocodeList, "_", String.valueOf(System.currentTimeMillis()));
      params.add("app", "cgeo");
      final String referer = GCConstants.URL_LIVE_MAP_DETAILS;
      final String data = Tile.requestMapInfo(referer, params, referer).toBlocking().value();

      // Example JSON information
      // {"status":"success",
      //    "data":[{"name":"Mission:
      // Impossible","gc":"GC1234","g":"34c2e609-5246-4f91-9029-d6c02b0f2a82","available":true,"archived":false,"subrOnly":false,"li":false,"fp":"5","difficulty":{"text":3.5,"value":"3_5"},"terrain":{"text":1.0,"value":"1"},"hidden":"7/23/2001","container":{"text":"Regular","value":"regular.gif"},"type":{"text":"Unknown Cache","value":8},"owner":{"text":"Ca$h_Cacher","value":"2db18e69-6877-402a-848d-6362621424f6"}},
      //            {"name":"HP: Hannover -
      // Sahlkamp","gc":"GC2Q97X","g":"a09149ca-00e0-4aa2-b332-db2b4dfb18d2","available":true,"archived":false,"subrOnly":false,"li":false,"fp":"0","difficulty":{"text":1.0,"value":"1"},"terrain":{"text":1.5,"value":"1_5"},"hidden":"5/29/2011","container":{"text":"Small","value":"small.gif"},"type":{"text":"Traditional Cache","value":2},"owner":{"text":"GeoM@n","value":"1deaa69e-6bcc-421d-95a1-7d32b468cb82"}}]
      // }

      final ObjectNode json = (ObjectNode) JsonUtils.reader.readTree(data);
      final String status = json.path("status").asText();
      if (StringUtils.isBlank(status)) {
        throw new ParserException("No status inside JSON");
      }
      if ("success".compareTo(status) != 0) {
        throw new ParserException("Wrong status inside JSON");
      }
      final ArrayNode dataArray = (ArrayNode) json.get("data");
      if (dataArray == null) {
        throw new ParserException("No data inside JSON");
      }

      final List<Geocache> caches = new ArrayList<>();
      for (final JsonNode dataObject : dataArray) {
        final Geocache cache = new Geocache();
        cache.setName(dataObject.path("name").asText());
        cache.setGeocode(dataObject.path("gc").asText());
        cache.setGuid(dataObject.path("g").asText()); // 34c2e609-5246-4f91-9029-d6c02b0f2a82"
        cache.setDisabled(!dataObject.path("available").asBoolean());
        cache.setArchived(dataObject.path("archived").asBoolean());
        cache.setPremiumMembersOnly(dataObject.path("subrOnly").asBoolean());
        // "li" seems to be "false" always
        cache.setFavoritePoints(Integer.parseInt(dataObject.path("fp").asText()));
        cache.setDifficulty(
            Float.parseFloat(dataObject.path("difficulty").path("text").asText())); // 3.5
        cache.setTerrain(Float.parseFloat(dataObject.path("terrain").path("text").asText())); // 1.5
        cache.setHidden(
            GCLogin.parseGcCustomDate(
                dataObject.path("hidden").asText(), "MM/dd/yyyy")); // 7/23/2001
        cache.setSize(
            CacheSize.getById(dataObject.path("container").path("text").asText())); // Regular
        cache.setType(
            CacheType.getByPattern(
                dataObject.path("type").path("text").asText())); // Traditional Cache
        cache.setOwnerDisplayName(dataObject.path("owner").path("text").asText());

        caches.add(cache);
      }
      result.addAndPutInCache(caches);
    } catch (ParserException | ParseException | IOException | NumberFormatException ignored) {
      result.setError(StatusCode.UNKNOWN_ERROR);
    }
    return result;
  }