Ejemplo n.º 1
0
  /**
   * for fetching the data
   *
   * @throws RequestRepeatException if the request to download the image is already present in the
   *     queue or is downloading.
   * @return object -- returns string
   */
  public Object send() throws RequestRepeatException {

    if (Util.isInternetAvailable()) {
      isRepeatRequest = false;
      // checking again if this request is already duplicated for previous one is completed or not.
      // if not completed it will be "duplicated" request hence isRepeatRequest will be true.
      // else isRepeatRequest will become true.
      if (isRepeatRequest) {

        // checks for duplicate request completion
        setIsRepeatRequest();
      }

      if (!isRepeatRequest) {

        // get downloaded data
        Object obj = sendRequest();

        // removes this instance from the list to tell the future request that its been completed.
        Util.removeHttRequest(this);

        return obj;

      } else {
        throw new RequestRepeatException("Request already in queue");
      }
    } else {
      if (this.METHOD_TYPE != Constants.IMAGE_METHOD) {
        Util.showToast("Network not available");
      }
      return null;
    }
  }
Ejemplo n.º 2
0
  /** checks for duplicate request. */
  private boolean checkForRepeatRequest() {

    // getting all the active queues
    try {
      List<HttpRequest> list = Util.getHttpRequestList();

      if (list != null && list.size() > 0) {

        int count = list.size();

        for (int i = 0; i < count; i++) {

          HttpRequest r = list.get(i);

          // comparing the two request
          if (this.equals(r)) {
            list.clear();
            list = null;
            return true;
          }
        }
        list.clear();
      }
      list = null;
    } catch (Exception e) {
      return false;
    }

    return false;
  }
Ejemplo n.º 3
0
  /** checks for the repeat request and adds in the list if not repeated */
  private void setIsRepeatRequest() {

    // checking for duplicate request
    if (!checkForRepeatRequest()) {

      isRepeatRequest = false;

      // adding this object in the list
      Util.addHttRequest(this);
    } else {

      isRepeatRequest = true;
    }
  }