Esempio n. 1
0
  private void syncPlaces(boolean recommendations) throws JSONException {
    String placesURL;
    ArrayList<City> cities = CityControl.getCities();
    ArrayList<Place> places = new ArrayList<Place>();

    for (City city : cities) {
      if (recommendations)
        placesURL = RESTResources.getInstance(this.context).getRecommendationURL(city);
      else placesURL = RESTResources.getInstance(this.context).getPlaceURL(city);

      // String content = RestMethod.get(this.context, placesURL, this.user, this.password);
      String content = RestMethod.get(this.context, placesURL);
      JSONArray json = new JSONArray(content);

      for (int i = 0; i < json.length(); i++) {
        Place place = new Place(json, this.context, i);
        place.setRecommended(recommendations);
        places.add(place);
      }
    }
    PlaceControl.createOrUpdate(places);
  }
Esempio n. 2
0
  @Override
  public void onPerformSync(
      Account account,
      Bundle extras,
      String authority,
      ContentProviderClient provider,
      SyncResult syncResult) {
    Log.i("SYNC", "Starting sync process. Last sync:" + this.lastUpdated);

    AccountManager am = AccountManager.get(this.context);
    this.user = account.name;
    this.password = am.getPassword(account);
    this.lastUpdated = new Date(System.currentTimeMillis());

    try {
      // We sync entity by entity

      // 2-way
      Log.i("SYNC", "Users sync");
      syncFacebookUser();

      // Log.i("SYNC", "Trips sync");
      // syncTrips();

      // Log.i("SYNC", "CityVisits sync");
      // syncCityVisits();

      // Log.i("SYNC", "PlaceVisits sync");
      // syncPlaceVisits();

      // Log.i("SYNC", "Transports sync");
      // syncTransports();

      // 1-way
      // Log.i("SYNC", "Countries sync");
      // syncCountry();

      // Log.i("SYNC", "Places sync");
      // syncPlaces(false);

      // Log.i("SYNC", "Recommendations sync");
      // syncPlaces(true);

      Place p = PlaceControl.read(118);
      p.setRecommended(true);
      PlaceDAO.update(p);

      p = PlaceControl.read(147);
      p.setRecommended(true);
      PlaceDAO.update(p);

      p = PlaceControl.read(141);
      p.setRecommended(true);
      PlaceDAO.update(p);

      p = PlaceControl.read(166);
      p.setRecommended(true);
      PlaceDAO.update(p);

      p = PlaceControl.read(163);
      p.setRecommended(true);
      PlaceDAO.update(p);

      p = PlaceControl.read(183);
      p.setRecommended(true);
      PlaceDAO.update(p);

      p = PlaceControl.read(185);
      p.setRecommended(true);
      PlaceDAO.update(p);

      p = PlaceControl.read(254);
      p.setRecommended(true);
      PlaceDAO.update(p);

      Log.i("SYNC", "Cities sync");
      // syncCities();

      Log.i("SYNC", "Sync finished");
    } catch (final ParseException e) {
      syncResult.stats.numParseExceptions++;
    } catch (final JSONException e) {
      syncResult.stats.numParseExceptions++;
    }
  }