示例#1
0
  /**
   * Retrieve a collection of files that have changed since the provided {@code changeId}.
   *
   * @param changeId Change ID to retrieve changed files from.
   * @return Map of changed files key'ed by their file ID.
   */
  private Map<String, File> getChangedFiles(long changeId) {
    Map<String, File> result = new HashMap<String, File>();

    try {
      Changes.List request = mService.changes().list().setStartChangeId(changeId);
      do {
        ChangeList changes = request.execute();
        long largestChangeId = changes.getLargestChangeId().longValue();

        for (Change change : changes.getItems()) {
          if (change.getDeleted()) {
            result.put(change.getFileId(), null);
          } else if (TEXT_PLAIN.equals(change.getFile().getMimeType())) {
            result.put(change.getFileId(), change.getFile());
          }
        }

        if (largestChangeId > mLargestChangeId) {
          mLargestChangeId = largestChangeId;
        }
        request.setPageToken(changes.getNextPageToken());
      } while (request.getPageToken() != null && request.getPageToken().length() > 0);
    } catch (IOException e) {
      e.printStackTrace();
    }

    Log.d(TAG, "Got changed Drive files: " + result.size() + " - " + mLargestChangeId);
    return result;
  }
  /**
   * Returns a list of changes to a file
   *
   * @param service Drive API service instance.
   * @param params HashMap containing parameters for the request
   * @return <strong>List</strong> of changes
   */
  private ChangeList getChangeList(Drive service, HashMap<String, String> params)
      throws IOException {

    Changes.List request = service.changes().list();
    String temporaryResult = params.get(GoogleDriveUtils.StringConstants.INCLUDE_DELETED);

    if (!EMPTY_STRING.equals(temporaryResult)) {

      request.setIncludeDeleted(Boolean.valueOf(temporaryResult));
    }

    temporaryResult = EMPTY_STRING;
    temporaryResult = params.get(GoogleDriveUtils.StringConstants.INCLUDE_SUBSCRIBED);

    if (!EMPTY_STRING.equals(temporaryResult)) {

      request.setIncludeSubscribed(Boolean.valueOf(temporaryResult));
    }

    temporaryResult = EMPTY_STRING;
    temporaryResult = params.get(GoogleDriveUtils.StringConstants.MAX_RESULTS);

    if (!EMPTY_STRING.equals(temporaryResult)) {

      request.setMaxResults(Integer.valueOf(temporaryResult));
    }

    temporaryResult = EMPTY_STRING;
    temporaryResult = params.get(GoogleDriveUtils.StringConstants.PAGE_TOKEN);

    if (!EMPTY_STRING.equals(temporaryResult)) {

      request.setPageToken(temporaryResult);
    }

    temporaryResult = EMPTY_STRING;
    temporaryResult = params.get(GoogleDriveUtils.StringConstants.START_CHANGE_ID);

    if (!EMPTY_STRING.equals(temporaryResult)) {

      request.setStartChangeId(Long.valueOf(temporaryResult));
    }

    return request.execute();
  }