Exemplo n.º 1
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);
    }
  }
Exemplo n.º 2
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);
    }
  }