Пример #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
  public void GetAllEntries(Callback<List<GhostEntry>> callback) {
    final Callback<List<GhostEntry>> 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)
        .getAll(
            new Callback<List<GhostEntry>>() {
              @Override
              public void success(List<GhostEntry> entries, Response response) {
                if (cb != null) cb.success(entries, response);
                if (response == null) {
                  /*
                   Notify image was NOT uploaded successfully
                  */
                  notificationHelper.createFailedUploadNotification();
                  return;
                }
                /*
                Notify image was uploaded successfully
                */
                if (entries != null) {
                  notificationHelper.createNotification("found ghosts:" + entries.size(), "");
                }
              }

              @Override
              public void failure(RetrofitError error) {
                if (cb != null) cb.failure(error);
                notificationHelper.createNotification(
                    error.getKind().toString(), error.getCause().getLocalizedMessage());
                //                        notificationHelper.createFailedUploadNotification();
              }
            });
  }
Пример #3
0
  public void GetNear(double longitude, double latitude, Callback<List<DistanceEntry>> callback) {
    final Callback<List<DistanceEntry>> 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)
        .getNear(
            longitude,
            latitude,
            new Callback<List<DistanceEntry>>() {
              @Override
              public void success(List<DistanceEntry> serverEntryListResponse, Response response) {
                if (cb != null) cb.success(serverEntryListResponse, response);
                if (response == null) {
                  /*
                   Notify image was NOT uploaded successfully
                  */
                  notificationHelper.createFailedUploadNotification();
                  return;
                }
              }

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