Example #1
0
  /**
   * Saves a OC File after a successful upload.
   *
   * <p>A PROPFIND is necessary to keep the props in the local database synchronized with the
   * server, specially the modification time and Etag (where available)
   *
   * <p>TODO refactor this ugly thing
   */
  private void saveUploadedFile() {
    OCFile file = mCurrentUpload.getFile();
    if (file.fileExists()) {
      file = mStorageManager.getFileById(file.getFileId());
    }
    long syncDate = System.currentTimeMillis();
    file.setLastSyncDateForData(syncDate);

    // new PROPFIND to keep data consistent with server
    // in theory, should return the same we already have
    ReadRemoteFileOperation operation = new ReadRemoteFileOperation(mCurrentUpload.getRemotePath());
    RemoteOperationResult result = operation.execute(mUploadClient);
    if (result.isSuccess()) {
      updateOCFile(file, (RemoteFile) result.getData().get(0));
      file.setLastSyncDateForProperties(syncDate);
    }

    // / maybe this would be better as part of UploadFileOperation... or
    // maybe all this method
    if (mCurrentUpload.wasRenamed()) {
      OCFile oldFile = mCurrentUpload.getOldFile();
      if (oldFile.fileExists()) {
        oldFile.setStoragePath(null);
        mStorageManager.saveFile(oldFile);
      } // else: it was just an automatic renaming due to a name
      // coincidence; nothing else is needed, the storagePath is right
      // in the instance returned by mCurrentUpload.getFile()
    }

    mStorageManager.saveFile(file);
  }
Example #2
0
 /**
  * Sends a broadcast in order to the interested activities can update their view
  *
  * @param upload Finished upload operation
  * @param uploadResult Result of the upload operation
  */
 private void sendFinalBroadcast(UploadFileOperation upload, RemoteOperationResult uploadResult) {
   Intent end = new Intent(getUploadFinishMessage());
   end.putExtra(EXTRA_REMOTE_PATH, upload.getRemotePath()); // real remote
   // path, after
   // possible
   // automatic
   // renaming
   if (upload.wasRenamed()) {
     end.putExtra(EXTRA_OLD_REMOTE_PATH, upload.getOldFile().getRemotePath());
   }
   end.putExtra(EXTRA_OLD_FILE_PATH, upload.getOriginalStoragePath());
   end.putExtra(ACCOUNT_NAME, upload.getAccount().name);
   end.putExtra(EXTRA_UPLOAD_RESULT, uploadResult.isSuccess());
   sendStickyBroadcast(end);
 }