Beispiel #1
0
  private void syncTrips() throws JSONException {
    ArrayList<Trip> trips = (ArrayList<Trip>) TripControl.readAll();

    String tripURL = RESTResources.getInstance(this.context).getTripURL();
    for (Trip trip : trips) {
      // Changes up

      if (trip.isPendingDelete()) {
        String url = tripURL + "delete/" + trip.getId();
        RestMethod.delete(this.context, url, this.user, this.password);
        TripControl.delete(trip.getId());
      }
      if (trip.isPendingCreate()) {
        String url = tripURL + "";
        JSONObject obj = new JSONObject(trip.toJSON());
        RestMethod.post(this.context, url, obj, this.user, this.password);
        TripControl.setPendingCreate(trip.getId(), false);
      } else if (trip.isPendingUpdate()) {
        String url = tripURL + "";
        JSONObject obj = new JSONObject(trip.toJSON());
        RestMethod.put(this.context, url, obj, this.user, this.password);
        TripControl.setPendingUpdate(trip.getId(), false);
      }
      // Changes down
      // String url = RESTResources.getInstance(this.context).getPlaceURL();
      // String content = RestMethod.get(this.context, url, this.user, this.password);
    }
  }
Beispiel #2
0
  private void syncCityVisits() throws JSONException {
    ArrayList<CityVisit> visits = (ArrayList<CityVisit>) CityVisitDAO.read();

    String tripURL = RESTResources.getInstance(this.context).getTripURL();
    for (CityVisit visit : visits) {
      // Changes up

      if (visit.isPendingDelete()) {
        String url = tripURL + "delete/" + visit.getId();
        RestMethod.delete(this.context, url, this.user, this.password);
        TripControl.delete(visit.getId());
      }
      if (visit.isPendingCreate()) {
        String url = tripURL + "";
        JSONObject obj = new JSONObject(visit.toJSON());
        RestMethod.post(this.context, url, obj, this.user, this.password);
        TripControl.setPendingCreate(visit.getId(), false);
      } else if (visit.isPendingUpdate()) {
        String url = tripURL + "";
        JSONObject obj = new JSONObject(visit.toJSON());
        RestMethod.put(this.context, url, obj, this.user, this.password);
        TripControl.setPendingUpdate(visit.getId(), false);
      }
      // Changes down
      // String url = RESTResources.getInstance(this.context).getPlaceURL();
      // String content = RestMethod.get(this.context, url, this.user, this.password);
    }
  }
Beispiel #3
0
  private void syncFacebookUser() throws JSONException {
    SharedPreferences prefs =
        this.context.getSharedPreferences(
            this.context.getString(R.string.package_name), Context.MODE_PRIVATE);
    String accessToken = prefs.getString(ActionsFacade.EXTRA_ACCESS_TOKEN, "");

    if (accessToken != "") {
      String url = RESTResources.getInstance(this.context).getUserURL();
      JSONObject obj = new JSONObject();
      obj.put("access_token", accessToken);
      RestMethod.put(this.context, url, obj, this.user, this.password);
    }
  }
Beispiel #4
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);
  }