Esempio n. 1
0
  /**
   * Cancel the transference in downloads (files/folders) and file uploads
   *
   * @param file OCFile
   */
  public void cancelTransference(OCFile file) {
    Account account = mFileActivity.getAccount();
    if (file.isFolder()) {
      OperationsService.OperationsServiceBinder opsBinder =
          mFileActivity.getOperationsServiceBinder();
      if (opsBinder != null) {
        opsBinder.cancel(account, file);
      }
    }

    // for both files and folders
    FileDownloaderBinder downloaderBinder = mFileActivity.getFileDownloaderBinder();
    FileUploaderBinder uploaderBinder = mFileActivity.getFileUploaderBinder();
    if (downloaderBinder != null && downloaderBinder.isDownloading(account, file)) {
      downloaderBinder.cancel(account, file);

      // TODO - review why is this here, and solve in a better way
      // Remove etag for parent, if file is a favorite
      if (file.isFavorite()) {
        OCFile parent = mFileActivity.getStorageManager().getFileById(file.getParentId());
        parent.setEtag("");
        mFileActivity.getStorageManager().saveFile(parent);
      }

    } else if (uploaderBinder != null && uploaderBinder.isUploading(account, file)) {
      uploaderBinder.cancel(account, file);
    }
  }
Esempio n. 2
0
  public void toggleFavorite(OCFile file, boolean isFavorite) {
    file.setFavorite(isFavorite);
    mFileActivity.getStorageManager().saveFile(file);

    /// register the OCFile instance in the observer service to monitor local updates
    Intent observedFileIntent =
        FileObserverService.makeObservedFileIntent(
            mFileActivity, file, mFileActivity.getAccount(), isFavorite);
    mFileActivity.startService(observedFileIntent);

    /// immediate content synchronization
    if (file.isFavorite()) {
      syncFile(file);
    }
  }
  /**
   * Public factory method to create new RemoveFilesDialogFragment instances.
   *
   * @param files Files to remove.
   * @return Dialog ready to show.
   */
  public static RemoveFilesDialogFragment newInstance(ArrayList<OCFile> files) {
    RemoveFilesDialogFragment frag = new RemoveFilesDialogFragment();
    Bundle args = new Bundle();
    int messageStringId;

    boolean containsFolder = false;
    boolean containsDown = false;
    boolean containsFavorite = false;
    for (OCFile file : files) {
      if (file.isFolder()) containsFolder = true;
      if (file.isDown()) containsDown = true;
      if (file.isFavorite()) containsFavorite = true;
    }

    if (files.size() == 1) {
      // choose message for a single file
      OCFile file = files.get(0);

      messageStringId =
          (file.isFolder())
              ? R.string.confirmation_remove_folder_alert
              : R.string.confirmation_remove_file_alert;

    } else {
      // choose message for more than one file
      messageStringId =
          (containsFolder)
              ? R.string.confirmation_remove_folders_alert
              : R.string.confirmation_remove_files_alert;
    }

    int localRemoveButton =
        (!containsFavorite && (containsFolder || containsDown))
            ? R.string.confirmation_remove_local
            : -1;

    args.putInt(ARG_MESSAGE_RESOURCE_ID, messageStringId);
    if (files.size() == 1) {
      args.putStringArray(ARG_MESSAGE_ARGUMENTS, new String[] {files.get(0).getFileName()});
    }
    args.putInt(ARG_POSITIVE_BTN_RES, R.string.common_yes);
    args.putInt(ARG_NEUTRAL_BTN_RES, R.string.common_no);
    args.putInt(ARG_NEGATIVE_BTN_RES, localRemoveButton);
    args.putParcelableArrayList(ARG_TARGET_FILES, files);
    frag.setArguments(args);

    return frag;
  }