Пример #1
0
  public void PostEntry(GhostEntry ghostEntry, Callback<ServerNewEntryResponse> callback) {
    final Callback<ServerNewEntryResponse> cb = callback;

    if (!NetworkUtils.isConnected(mContext.get())) {
      // Callback will be called, so we prevent a unnecessary notification
      cb.failure(null);
      return;
    }

    final NotificationHelper notificationHelper = new NotificationHelper(mContext.get());
    notificationHelper.createUploadingNotification();

    RestAdapter restAdapter = buildRestAdapter();

    restAdapter
        .create(ServerAPI.class)
        .postEntry(
            ghostEntry,
            new Callback<ServerNewEntryResponse>() {
              @Override
              public void success(ServerNewEntryResponse serverNewResponse, Response response) {
                if (cb != null) cb.success(serverNewResponse, response);
                if (response == null) {
                  /*
                   Notify image was NOT uploaded successfully
                  */
                  notificationHelper.createFailedUploadNotification();
                  return;
                }
                /*
                Notify image was uploaded successfully
                */
                if (serverNewResponse != null) {
                  notificationHelper.createNotification(
                      serverNewResponse.name, serverNewResponse.content);
                }
              }

              @Override
              public void failure(RetrofitError error) {
                if (cb != null) cb.failure(error);
                notificationHelper.createNotification(
                    error.getKind().toString(), error.getMessage());

                //                        notificationHelper.createFailedUploadNotification();
              }
            });
  }
Пример #2
0
 @Override
 public void getUsers(@Query("pagesize") int numItems, Callback<RespBean> callback) {
   RespBean obj = new Gson().fromJson(DATA, RespBean.class);
   Response response =
       new Response(
           Api.URL_ENDPOINT,
           200,
           "nothing",
           Collections.EMPTY_LIST,
           new TypedByteArray("application/json", DATA.getBytes()));
   callback.success(obj, response);
 }