Ejemplo n.º 1
0
  public static boolean unlikeMemoryOnServer(Context context, Like like) {
    String url =
        Constants.URL_MEMORY_UPDATE
            + like.getJourneyId()
            + "/memories/"
            + like.getMemoryLocalId()
            + "/unlike";

    Map<String, String> params = new HashMap<>();
    params.put("api_key", TJPreferences.getApiKey(context));

    Log.d(TAG, "unliking memory with parameters " + params);
    Log.d(TAG, "unliking memory with url " + url);

    final RequestFuture<JSONObject> futureRequest = RequestFuture.newFuture();
    CustomJsonRequest jsonRequest =
        new CustomJsonRequest(
            com.android.volley.Request.Method.PUT, url, params, futureRequest, futureRequest);

    AppController.getInstance().getRequestQueue().add(jsonRequest);
    try {
      JSONObject response = futureRequest.get(30, TimeUnit.SECONDS);
      LikeDataSource.deleteLike(context, like.getId());
      Log.d(TAG, "memory unliked successfully on server with response " + response);
      return true;
    } catch (InterruptedException e) {
      Log.d(TAG, "couldnot unlike InterruptedException");
      e.printStackTrace();
    } catch (ExecutionException e) {
      Log.d(TAG, "couldnot unlike ExecutionException");
      e.printStackTrace();
    } catch (TimeoutException e) {
      Log.d(TAG, "couldnot unlike TimeoutException");
      e.printStackTrace();
    }
    return false;
  }