private void startLoading(Request request, boolean skipRoundtripIfCached, long afterDelay) {
    this.skipRoundtripIfCached = skipRoundtripIfCached;
    appendResults = false;
    nextRequest = null;
    currentRequest = request;
    currentRequest.setCallback(
        new Request.Callback() {
          @Override
          public void onCompleted(Response response) {
            requestCompleted(response);
          }
        });

    // We are considered loading even if we have a delay.
    loading = true;

    final RequestBatch batch = putRequestIntoBatch(request, skipRoundtripIfCached);
    Runnable r =
        new Runnable() {
          @Override
          public void run() {
            Request.executeBatchAsync(batch);
          }
        };
    if (afterDelay == 0) {
      r.run();
    } else {
      Handler handler = new Handler();
      handler.postDelayed(r, afterDelay);
    }
  }
Example #2
0
 void runRequest(Request request) {
   OnActionListener<T> actionListener = getActionListener();
   request.setCallback(mCallback);
   RequestAsyncTask task = new RequestAsyncTask(request);
   task.execute();
   if (actionListener != null) {
     actionListener.onThinking();
   }
 }
Example #3
0
  /**
   * set next and prev pages requests
   *
   * @param response
   */
  private void updateCursor(Response response) {
    if (mOnActionListener == null) {
      return;
    }

    if (mCursor == null) {
      mCursor = new Cursor<T>(GetAction.this);
    }

    Request requestNextPage = response.getRequestForPagedResults(PagingDirection.NEXT);
    if (requestNextPage != null) {
      requestNextPage.setCallback(mCallback);
    }
    mCursor.setNextPage(requestNextPage);

    Request requestPrevPage = response.getRequestForPagedResults(PagingDirection.PREVIOUS);
    if (requestPrevPage != null) {
      requestPrevPage.setCallback(mCallback);
    }
    mCursor.setPrevPage(requestPrevPage);
    mOnActionListener.setCursor(mCursor);
  }
  public void followNextLink() {
    if (nextRequest != null) {
      appendResults = true;
      currentRequest = nextRequest;

      currentRequest.setCallback(
          new Request.Callback() {
            @Override
            public void onCompleted(Response response) {
              requestCompleted(response);
            }
          });

      loading = true;
      CacheableRequestBatch batch = putRequestIntoBatch(currentRequest, skipRoundtripIfCached);
      Request.executeBatchAsync(batch);
    }
  }