Esempio n. 1
0
  /** Enables or disables buttons for a file being downloaded */
  private void setButtonsForTransferring() {
    if (!isEmpty()) {
      Button downloadButton = (Button) getView().findViewById(R.id.fdDownloadBtn);
      downloadButton.setText(R.string.common_cancel);
      // downloadButton.setEnabled(false);

      // let's protect the user from himself ;)
      ((Button) getView().findViewById(R.id.fdOpenBtn)).setEnabled(false);
      ((Button) getView().findViewById(R.id.fdRenameBtn)).setEnabled(false);
      ((Button) getView().findViewById(R.id.fdShareBtn)).setEnabled(false);
      ((Button) getView().findViewById(R.id.fdRemoveBtn)).setEnabled(false);
      getView().findViewById(R.id.fdKeepInSync).setEnabled(false);

      // show the progress bar for the transfer
      ProgressBar progressBar = (ProgressBar) getView().findViewById(R.id.fdProgressBar);
      progressBar.setVisibility(View.VISIBLE);
      TextView progressText = (TextView) getView().findViewById(R.id.fdProgressText);
      progressText.setVisibility(View.VISIBLE);
      FileDownloaderBinder downloaderBinder = mContainerActivity.getFileDownloaderBinder();
      FileUploaderBinder uploaderBinder = mContainerActivity.getFileUploaderBinder();
      if (downloaderBinder != null && downloaderBinder.isDownloading(mAccount, mFile)) {
        progressText.setText(R.string.downloader_download_in_progress_ticker);
      } else if (uploaderBinder != null && uploaderBinder.isUploading(mAccount, mFile)) {
        progressText.setText(R.string.uploader_upload_in_progress_ticker);
      }
    }
  }
Esempio n. 2
0
 public void leaveTransferProgress() {
   if (mProgressListener != null) {
     if (mContainerActivity.getFileDownloaderBinder() != null) {
       mContainerActivity
           .getFileDownloaderBinder()
           .removeDatatransferProgressListener(mProgressListener, mAccount, mFile);
     }
     if (mContainerActivity.getFileUploaderBinder() != null) {
       mContainerActivity
           .getFileUploaderBinder()
           .removeDatatransferProgressListener(mProgressListener, mAccount, mFile);
     }
   }
 }
Esempio n. 3
0
  private void onRenameFileOperationFinish(
      RenameFileOperation operation, RemoteOperationResult result) {
    boolean inDisplayActivity = getActivity() instanceof FileDisplayActivity;
    getActivity()
        .dismissDialog(
            (inDisplayActivity)
                ? FileDisplayActivity.DIALOG_SHORT_WAIT
                : FileDetailActivity.DIALOG_SHORT_WAIT);

    if (result.isSuccess()) {
      updateFileDetails(((RenameFileOperation) operation).getFile(), mAccount);
      mContainerActivity.onFileStateChanged();

    } else {
      if (result.getCode().equals(ResultCode.INVALID_LOCAL_FILE_NAME)) {
        Toast msg =
            Toast.makeText(getActivity(), R.string.rename_local_fail_msg, Toast.LENGTH_LONG);
        msg.show();
        // TODO throw again the new rename dialog
      } else {
        Toast msg =
            Toast.makeText(getActivity(), R.string.rename_server_fail_msg, Toast.LENGTH_LONG);
        msg.show();
        if (result.isSslRecoverableException()) {
          // TODO show the SSL warning dialog
        }
      }
    }
  }
Esempio n. 4
0
  /**
   * Updates the view with all relevant details about that file.
   *
   * <p>TODO Remove parameter when the transferring state of files is kept in database.
   *
   * <p>TODO REFACTORING! this method called 5 times before every time the fragment is shown!
   *
   * @param transferring Flag signaling if the file should be considered as downloading or
   *     uploading, although {@link FileDownloaderBinder#isDownloading(Account, OCFile)} and {@link
   *     FileUploaderBinder#isUploading(Account, OCFile)} return false.
   * @param refresh If 'true', try to refresh the hold file from the database
   */
  public void updateFileDetails(boolean transferring, boolean refresh) {

    if (readyToShow()) {

      if (refresh && mStorageManager != null) {
        mFile = mStorageManager.getFileByPath(mFile.getRemotePath());
      }

      // set file details
      setFilename(mFile.getFileName());
      setFiletype(mFile.getMimetype());
      setFilesize(mFile.getFileLength());
      if (ocVersionSupportsTimeCreated()) {
        setTimeCreated(mFile.getCreationTimestamp());
      }

      setTimeModified(mFile.getModificationTimestamp());

      CheckBox cb = (CheckBox) getView().findViewById(R.id.fdKeepInSync);
      cb.setChecked(mFile.keepInSync());

      // configure UI for depending upon local state of the file
      // if (FileDownloader.isDownloading(mAccount, mFile.getRemotePath()) ||
      // FileUploader.isUploading(mAccount, mFile.getRemotePath())) {
      FileDownloaderBinder downloaderBinder = mContainerActivity.getFileDownloaderBinder();
      FileUploaderBinder uploaderBinder = mContainerActivity.getFileUploaderBinder();
      if (transferring
          || (downloaderBinder != null && downloaderBinder.isDownloading(mAccount, mFile))
          || (uploaderBinder != null && uploaderBinder.isUploading(mAccount, mFile))) {
        setButtonsForTransferring();

      } else if (mFile.isDown()) {

        setButtonsForDown();

      } else {
        // TODO load default preview image; when the local file is removed, the preview remains
        // there
        setButtonsForRemote();
      }
    }
    getView().invalidate();
  }
Esempio n. 5
0
  private void onSynchronizeFileOperationFinish(
      SynchronizeFileOperation operation, RemoteOperationResult result) {
    boolean inDisplayActivity = getActivity() instanceof FileDisplayActivity;
    getActivity()
        .dismissDialog(
            (inDisplayActivity)
                ? FileDisplayActivity.DIALOG_SHORT_WAIT
                : FileDetailActivity.DIALOG_SHORT_WAIT);

    if (!result.isSuccess()) {
      if (result.getCode() == ResultCode.SYNC_CONFLICT) {
        Intent i = new Intent(getActivity(), ConflictsResolveActivity.class);
        i.putExtra(ConflictsResolveActivity.EXTRA_FILE, mFile);
        i.putExtra(ConflictsResolveActivity.EXTRA_ACCOUNT, mAccount);
        startActivity(i);

      } else {
        Toast msg = Toast.makeText(getActivity(), R.string.sync_file_fail_msg, Toast.LENGTH_LONG);
        msg.show();
      }

      if (mFile.isDown()) {
        setButtonsForDown();

      } else {
        setButtonsForRemote();
      }

    } else {
      if (operation.transferWasRequested()) {
        setButtonsForTransferring();
        mContainerActivity
            .onFileStateChanged(); // this is not working; FileDownloader won't do NOTHING at all
                                   // until this method finishes, so
        // checking the service to see if the file is downloading results in FALSE
      } else {
        Toast msg =
            Toast.makeText(getActivity(), R.string.sync_file_nothing_to_do_msg, Toast.LENGTH_LONG);
        msg.show();
        if (mFile.isDown()) {
          setButtonsForDown();

        } else {
          setButtonsForRemote();
        }
      }
    }
  }
Esempio n. 6
0
  private void onRemoveFileOperationFinish(
      RemoveFileOperation operation, RemoteOperationResult result) {
    boolean inDisplayActivity = getActivity() instanceof FileDisplayActivity;
    getActivity()
        .dismissDialog(
            (inDisplayActivity)
                ? FileDisplayActivity.DIALOG_SHORT_WAIT
                : FileDetailActivity.DIALOG_SHORT_WAIT);

    if (result.isSuccess()) {
      Toast msg =
          Toast.makeText(
              getActivity().getApplicationContext(),
              R.string.remove_success_msg,
              Toast.LENGTH_LONG);
      msg.show();
      if (inDisplayActivity) {
        // double pane
        FragmentTransaction transaction =
            getActivity().getSupportFragmentManager().beginTransaction();
        transaction.replace(
            R.id.file_details_container,
            new FileDetailFragment(null, null)); // empty FileDetailFragment
        transaction.commit();
        mContainerActivity.onFileStateChanged();
      } else {
        getActivity().finish();
      }

    } else {
      Toast msg = Toast.makeText(getActivity(), R.string.remove_fail_msg, Toast.LENGTH_LONG);
      msg.show();
      if (result.isSslRecoverableException()) {
        // TODO show the SSL warning dialog
      }
    }
  }
Esempio n. 7
0
  @Override
  public void onClick(View v) {
    switch (v.getId()) {
      case R.id.fdDownloadBtn:
        {
          FileDownloaderBinder downloaderBinder = mContainerActivity.getFileDownloaderBinder();
          FileUploaderBinder uploaderBinder = mContainerActivity.getFileUploaderBinder();
          if (downloaderBinder != null && downloaderBinder.isDownloading(mAccount, mFile)) {
            downloaderBinder.cancel(mAccount, mFile);
            if (mFile.isDown()) {
              setButtonsForDown();
            } else {
              setButtonsForRemote();
            }

          } else if (uploaderBinder != null && uploaderBinder.isUploading(mAccount, mFile)) {
            uploaderBinder.cancel(mAccount, mFile);
            if (!mFile.fileExists()) {
              // TODO make something better
              if (getActivity() instanceof FileDisplayActivity) {
                // double pane
                FragmentTransaction transaction =
                    getActivity().getSupportFragmentManager().beginTransaction();
                transaction.replace(
                    R.id.file_details_container,
                    new FileDetailFragment(null, null),
                    FTAG); // empty FileDetailFragment
                transaction.commit();
                mContainerActivity.onFileStateChanged();
              } else {
                getActivity().finish();
              }

            } else if (mFile.isDown()) {
              setButtonsForDown();
            } else {
              setButtonsForRemote();
            }

          } else {
            mLastRemoteOperation =
                new SynchronizeFileOperation(
                    mFile, null, mStorageManager, mAccount, true, false, getActivity());
            WebdavClient wc =
                OwnCloudClientUtils.createOwnCloudClient(
                    mAccount, getSherlockActivity().getApplicationContext());
            mLastRemoteOperation.execute(wc, this, mHandler);

            // update ui
            boolean inDisplayActivity = getActivity() instanceof FileDisplayActivity;
            getActivity()
                .showDialog(
                    (inDisplayActivity)
                        ? FileDisplayActivity.DIALOG_SHORT_WAIT
                        : FileDetailActivity.DIALOG_SHORT_WAIT);
          }
          break;
        }
      case R.id.fdKeepInSync:
        {
          CheckBox cb = (CheckBox) getView().findViewById(R.id.fdKeepInSync);
          mFile.setKeepInSync(cb.isChecked());
          mStorageManager.saveFile(mFile);

          /// register the OCFile instance in the observer service to monitor local updates;
          /// if necessary, the file is download
          Intent intent =
              new Intent(getActivity().getApplicationContext(), FileObserverService.class);
          intent.putExtra(
              FileObserverService.KEY_FILE_CMD,
              (cb.isChecked()
                  ? FileObserverService.CMD_ADD_OBSERVED_FILE
                  : FileObserverService.CMD_DEL_OBSERVED_FILE));
          intent.putExtra(FileObserverService.KEY_CMD_ARG_FILE, mFile);
          intent.putExtra(FileObserverService.KEY_CMD_ARG_ACCOUNT, mAccount);
          getActivity().startService(intent);

          if (mFile.keepInSync()) {
            onClick(
                getView().findViewById(R.id.fdDownloadBtn)); // force an immediate synchronization
          }
          break;
        }
      case R.id.fdRenameBtn:
        {
          EditNameDialog dialog =
              EditNameDialog.newInstance(
                  getString(R.string.rename_dialog_title), mFile.getFileName(), this);
          dialog.show(getFragmentManager(), "nameeditdialog");
          break;
        }
      case R.id.fdRemoveBtn:
        {
          ConfirmationDialogFragment confDialog =
              ConfirmationDialogFragment.newInstance(
                  R.string.confirmation_remove_alert,
                  new String[] {mFile.getFileName()},
                  mFile.isDown()
                      ? R.string.confirmation_remove_remote_and_local
                      : R.string.confirmation_remove_remote,
                  mFile.isDown() ? R.string.confirmation_remove_local : -1,
                  R.string.common_cancel);
          confDialog.setOnConfirmationListener(this);
          confDialog.show(getFragmentManager(), FTAG_CONFIRMATION);
          break;
        }
      case R.id.fdOpenBtn:
        {
          openFile();
          break;
        }
      case R.id.fdShareBtn:
        {;
          break;
        }
      default:
        Log.e(TAG, "Incorrect view clicked!");
    }

    /* else if (v.getId() == R.id.fdShareBtn) {
        Thread t = new Thread(new ShareRunnable(mFile.getRemotePath()));
        t.start();
    }*/
  }