Ejemplo n.º 1
0
  @Override
  public List<Place> searchPlaces(Location location) {
    List<Place> results = new ArrayList<Place>();
    List<Place> places = Entity.query(Place.class).executeMulti();

    Iterator<Place> iterator = places.iterator();
    while (iterator.hasNext()) {
      Place place = iterator.next();
      if (Place.distance(place, location) < searchOptions.getRadius()) {
        results.add(place);
      }
      ;
    }
    return results;
  }
Ejemplo n.º 2
0
  @Override
  public void savePlaces(Collection<Place> places) {
    // just for debug
    //		String s="";
    //		int reallyStored = 0;
    // end debug
    for (Place place : places) {
      try {
        // insert only if not existant
        /*
        				String state;
        				Place placeExistant = Entity.query(Place.class).where( eql(Place.PLACENAME_COLUMN,place.getPlaceName()) ).execute();
        				if (placeExistant!=null && placeExistant.equals(place)) {
        					state = "_same";
        //					Ln.d(placeExistant.getPlaceName()+": save_state="+state);
        //					int oldId = placeExistant.getId();
        //					place.setId(oldId);
        //					state = ""+place.save();

        //					do nothing
        				} else {
        					state = ""+place.save();
        					Ln.d(place.getPlaceName()+": save_state="+state);

        					s+="|"+place.getPlaceName();
        					reallyStored++;
        				}*/

        // update if existant
        Place placeExistant =
            Entity.query(Place.class)
                .where(eql(Place.PLACENAME_COLUMN, place.getPlaceName()))
                .execute();
        if (placeExistant != null) {
          //					placeExistant.delete();
          //					place.save();
          placeExistant.updateValues(
              place.getPlaceName(),
              place.getPlaceId(),
              place.getLocation(),
              place.getIconUrlString(),
              place.getRating(),
              place.getTypes(),
              place.getVicinity(),
              place.getPhotosUrls(),
              place.isPermanentlyClosed(),
              place.getFormattedAddress(),
              place.getInternationalPhoneNumber(),
              place.getReviews(),
              place.getWebsite(),
              place.getDistance(),
              place.getPlusUrl());
          //					Ln.d("place:"+placeExistant+" existant, to update");
        } else {
          placeExistant = place;
          //					Ln.d("place:"+placeExistant+" new, to insert");
        }
        placeExistant.save();
      } catch (ORMDroidException e) {
        Ln.d("setPlaces exception: " + e.getMessage());
      }
    }
    // just for debug - used in "not existant IF"
    //		s.replaceFirst("|", "");
    //		String msg = "storing "+reallyStored+"/"+places.size()+" places";
    //		Ln.d(msg+": "+s);
  }